Enhancements:
- Refactor internals so that the mock proxy methods and state are held
outside of the mocked object rather than inside it. This paves the way
for future syntax enhancements and removes the need for some hacky
work arounds for
any_instance
dup'ing andYAML
serialization, among other things. Note that the code now relies uponobject_id
returning a unique, consistent value for any object you want to mock or stub (Myron Marston). - Add support for test spies. This allows you to verify a message
was received afterwards using the
have_received
matcher. Note that you must first stub the method or use a null double. (Joe Ferris and Joël Quenneville) - Make
at_least
andat_most
style receive expectations print that they were expecting at least or at most some number of calls, rather than just the number of calls given in the expectation (Sam Phippen) - Make
with
style receive expectations print the args they were expecting, and the args that they got (Sam Phippen) - Fix some warnings seen under ruby 2.0.0p0 (Sam Phippen).
- Add a new
:expect
syntax for message expectations (Myron Marston and Sam Phippen).
Bug fixes
- Fix
any_instance
so that a frozen object can bedup
'd when methods have been stubbed on that type usingany_instance
(Jon Rowe). - Fix
and_call_original
so that it properly raises anArgumentError
when the wrong number of args are passed (Jon Rowe). - Fix
double
on 1.9.2 so you can wrap them in an Array usingArray(my_double)
(Jon Rowe). - Fix
stub_const
andhide_const
to handle constants that redefinesend
(Sam Phippen). - Fix
Marshal.dump
extension so that it correctly handles nil. (Luke Imhoff, Jon Rowe) - Fix isolation of
allow_message_expectations_on_nil
(Jon Rowe) - Use inspect to format actual arguments on expectations in failure messages (#280, Ben Langfeld)
Deprecations
- Deprecate
stub
andmock
as aliases fordouble
.double
is the best term for creating a test double, and it reduces confusion to have only one term (Michi Huber). - Deprecate
stub!
andunstub!
in favor ofstub
andunstub
(Jon Rowe). - Deprecate
at_least(0).times
andany_number_of_times
(Michi Huber).
Bug fixes
- Fix bug that caused weird behavior when a method that had
previously been stubbed with multiple return values (e.g.
obj.stub(:foo).and_return(1, 2)
) was later mocked with a single return value (e.g.obj.should_receive(:foo).once.and_return(1)
). (Myron Marston) - Fix bug related to a mock expectation for a method that already had
multiple stubs with different
with
constraints. Previously, the first stub was used, even though it may not have matched the passed args. The fix defers this decision until the message is received so that the proper stub response can be chosen based on the passed arguments (Myron Marston). - Do not call
nil?
extra times on a mocked object, in casenil?
itself is expected a set number of times (Myron Marston). - Fix
missing_default_stub_error
message so array args are handled properly (Myron Marston). - Explicitly disallow
any_instance.unstub!
(Ryan Jones). - Fix
any_instance
stubbing so that it works withDelegator
subclasses (Myron Marston). - Fix
and_call_original
so that it works withDelegator
subclasses (Myron Marston). - Fix
any_instance.should_not_receive
whenany_instance.should_receive
is used on the same class in the same example. Previously it would wrongly report a failure even when the message was not received (Myron Marston).
Bug fixes
- Fix
and_call_original
to work properly for methods defined on a module extended onto an object instance (Myron Marston). - Fix
stub_const
with an undefined constnat name to work properly with constant strings that are prefixed with::
-- and edge case I missed in the bug fix in the 2.12.1 release (Myron Marston). - Ensure method visibility on a partial mock is restored after reseting
method stubs, even on a singleton module (created via
extend self
) when the method visibility differs between the instance and singleton versions (Andy Lindeman).
Bug fixes
- Fix
any_instance
to supportand_call_original
. (Myron Marston) - Properly restore stubbed aliased methods on rubies that report the incorrect owner (Myron Marston and Andy Lindeman).
- Fix
hide_const
andstub_const
with a defined constnat name to work properly with constant strings that are prefixed with::
(Myron Marston).
Enhancements
and_raise
can accept an exception class and message, more closely matchingKernel#raise
(e.g.,foo.stub(:bar).and_raise(RuntimeError, "message")
) (Bas Vodde)- Add
and_call_original
, which will delegate the message to the original method (Myron Marston).
Deprecations:
- Add deprecation warning when using
and_return
withshould_not_receive
(Neha Kumari)
Bug fixes
- Fix
:transfer_nested_constants
option ofstub_const
so that it doesn't blow up when there are inherited constants. (Myron Marston) any_instance
stubs can be used on classes that overrideObject#method
. (Andy Lindeman)- Methods stubbed with
any_instance
are unstubbed after the test finishes. (Andy Lindeman) - Fix confusing error message when calling a mocked class method an extra time with the wrong arguments (Myron Marston).
Bug fixes
- Don't modify
dup
on classes that don't supportdup
(David Chelimsky) - Fix
any_instance
so that it works properly with methods defined on a superclass. (Daniel Eguzkiza) - Fix
stub_const
so that it works properly for nested constants that share a name with a top-level constant (e.g. "MyGem::Hash"). (Myron Marston)
Bug fixes
- Fix
should_receive
so that when it is called on anas_null_object
double with no implementation, and there is a previous explicit stub for the same method, the explicit stub remains (rather than being overriden with the null object implementation--return self
). (Myron Marston)
Enhancements
- Expose ArgumentListMatcher as a formal API
- supports use by 3rd party mock frameworks like Surrogate
- Add
stub_const
API to stub constants for the duration of an example (Myron Marston).
Bug fixes
- Fix regression of edge case behavior.
double.should_receive(:foo) { a }
was causing a NoMethodError whendouble.stub(:foo).and_return(a, b)
had been setup before (Myron Marston). - Infinite loop generated by using
any_instance
anddup
. (Sidu Ponnappa @kaiwren) double.should_receive(:foo).at_least(:once).and_return(a)
always returns a even if:foo
is already stubbed.- Prevent infinite loop when interpolating a null double into a string
as an integer (
"%i" % double.as_null_object
). (Myron Marston) - Fix
should_receive
so that null object behavior (e.g. returning self) is preserved if no implementation is given (Myron Marston). - Fix
and_raise
so that it raisesRuntimeError
rather thanException
by default, just like ruby does. (Andrew Marshall)
Bug fixes
- fix regression of edge case behavior
(rspec#132)
- fixed failure of
object.should_receive(:message).at_least(0).times.and_return value
- fixed failure of
object.should_not_receive(:message).and_return value
- fixed failure of
Bug fixes
- fail fast when an
exactly
orat_most
expectation is exceeded
Enhancements
- Support order constraints across objects (preethiramdev)
Bug fixes
- Allow a
as_null_object
to be passed towith
- Pass proc to block passed to stub (Aubrey Rhodes)
- Initialize child message expectation args to match any args (#109 - preethiramdev)
No changes for this release. Just releasing with the other rspec gems.
No changes for this release. Just releasing with the other rspec gems.
Enhancements
- Eliminate Ruby warnings (Matijs van Zuijlen)
Enhancements
- Use
__send__
rather thansend
(alextk) - Add support for
any_instance.stub_chain
(Sidu Ponnappa) - Add support for
any_instance
argument matching based onwith
(Sidu Ponnappa and Andy Lindeman)
Changes
- Check for
failure_message_for_should
orfailure_message
instead ofdescription
to detect a matcher (Tibor Claassen)
Bug fixes
- pass a hash to
any_instance.stub
. (Justin Ko) - allow
to_ary
to be called without raisingNoMethodError
(Mikhail Dieterle) any_instance
properly restores private methods (Sidu Ponnappa)
Enhancements
- Add support for
any_instance.stub
andany_instance.should_receive
(Sidu Ponnappa and Andy Lindeman)
Bug fixes
- fix bug in which multiple chains with shared messages ending in hashes failed to return the correct value
Bug fixes
- message expectation counts now work in combination with a stub (Damian Nurzynski)
- fix failure message when message received with incorrect args (Josep M. Bach)
No functional changes in this release, which was made to align with the rspec-core-2.4.0 release.
Bug fixes
- Fix our Marshal extension so that it does not interfere with objects that
have their own
@mock_proxy
instance variable. (Myron Marston)
Enhancements
- Added "rspec/mocks/standalone" for exploring the rspec-mocks in irb.
Bug fix
- Eliminate warning on splat args without parens (Gioele Barabucci)
- Fix bug where
obj.should_receive(:foo).with(stub.as_null_object)
would pass with a false positive.
Bug fixes
- Fix serialization of stubbed object (Josep M Bach)
Enhancements
- support passing a block to an expectation block (Nicolas Braem)
obj.should_receive(:msg) {|&block| ... }
Bug fixes
- Fix YAML serialization of stub (Myron Marston)
- Fix rdoc rake task (Hans de Graaff)
Bug fixes
- fixed regression that broke
obj.stub_chain(:a, :b => :c)
- fixed regression that broke
obj.stub_chain(:a, :b) { :c }
respond_to?
always returns true when usingas_null_object