@private
# File lib/rspec/mocks/any_instance.rb, line 51 def __recorder @__recorder ||= AnyInstance::Recorder.new(self) end
Used to set stubs and message expectations on any instance of a given class. Returns a [Recorder](Recorder), which records messages like `stub` and `should_receive` for later playback on instances of the class.
@example
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 Account.any_instance.stub(:balance) { Money.new(:USD, 25) } Account.new.balance # => Money.new(:USD, 25))
@return [Recorder]
# 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
@private
# File lib/rspec/mocks/any_instance.rb, line 45 def rspec_reset restore_dup __mock_proxy.reset end
@private
# File lib/rspec/mocks/any_instance.rb, line 35 def rspec_verify __recorder.verify super ensure __recorder.stop_all_observation! restore_dup @__recorder = nil end