Module: RSpec::Mocks::AnyInstance

Defined in:
lib/rspec/mocks/any_instance.rb,
lib/rspec/mocks/any_instance/chain.rb,
lib/rspec/mocks/any_instance/recorder.rb,
lib/rspec/mocks/any_instance/stub_chain.rb,
lib/rspec/mocks/any_instance/message_chains.rb,
lib/rspec/mocks/any_instance/stub_chain_chain.rb,
lib/rspec/mocks/any_instance/expectation_chain.rb

Defined Under Namespace

Classes: Chain, ExpectationChain, NegativeExpectationChain, PositiveExpectationChain, Recorder

Instance Method Summary collapse

Instance Method Details

#any_instanceRecorder

Used to set stubs and message expectations on any instance of a given class. Returns a Recorder, which records messages like stub and should_receive for later playback on instances of the class.

Examples:


Car.any_instance.should_receive(:go)
race = Race.new
race.cars << Car.new
race.go # assuming this delegates to all of its cars
        # this example would pass

.any_instance.stub(:balance) { Money.new(:USD, 25) }
.new.balance # => Money.new(:USD, 25))

Returns:



28
29
30
31
32
# File 'lib/rspec/mocks/any_instance.rb', line 28

def any_instance
  RSpec::Mocks::space.add(self)
  modify_dup_to_remove_mock_proxy_when_invoked
  __recorder
end