Class: BasicObject

Defined in:

lib/rspec/mocks/syntax.rb

Overview

The legacy :should syntax adds the following methods directly to
BasicObject so that they are available off of any object. Note, however,
that this syntax does not always play nice with delegate/proxy objects.
We recommend you use the non-monkeypatching :expect syntax instead.

Warning:

Chains can be arbitrarily long, which makes it quite painless to
violate the Law of Demeter in violent ways, so you should consider any
use of stub_chain a code smell. Even though not all code smells
indicate real problems (think fluent interfaces), stub_chain still
results in brittle examples. For example, if you write
foo.stub_chain(:bar, :baz => 37) in a spec and then the
implementation calls foo.baz.bar, the stub will not work.

Examples:

double.stub_chain("foo.bar"){:baz}double.stub_chain(:foo,:bar=>:baz)double.stub_chain(:foo,:bar){:baz}# Given any of ^^ these three forms ^^:
double.foo.bar# => :baz
# Common use in Rails/ActiveRecord:
Article.stub_chain("recent.published"){[Article.new]}