Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/syntax.rb

Overview

The legacy :should syntax adds the any_instance to Class. We generally recommend you use the newer :expect syntax instead, which allows you to stub any instance of a class using allow_any_instance_of(klass) or mock any instance using expect_any_instance_of(klass).

See Also:

Instance Method Summary collapse

Instance Method Details

#any_instanceRecorder

Note:

This is only available when you have enabled the should syntax.

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

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

Returns:

  • (Recorder)

See Also:



# File 'lib/rspec/mocks/syntax.rb', line 304