class RSpec::Mocks::MessageExpectation
def with(*args, &block)
cart.add(Book.new(:isbn => 1934356379))
# => failed expectation
cart.add(Book.new(:isbn => 1234567890))
cart.should_receive(:add).with(Book.new(:isbn => 1934356379)) { :success }
# => :success
cart.add(Book.new(:isbn => 1934356379))
# => :failure
cart.add(Book.new(:isbn => 1234567890))
cart.stub(:add).with(Book.new(:isbn => 1934356379)) { :success }
cart.stub(:add) { :failure }
@example
arguments.
A message expectation will fail if the message is received with different
message using `with` to constrain to specific arguments.
you should stub a default value first, and then stub or mock the same
With a stub, if the message might be received with other args as well,
arguments.
Constrains a stub or message expectation to invocations with specific
def with(*args, &block) if block_given? if args.empty? RSpec.deprecate "Using the return value of a `with` block to validate passed arguments rather than as an implementation", :replacement => "the `satisfy` matcher, a custom matcher or validate the arguments in an implementation block" else self.inner_implementation_action = block end end @argument_list_matcher = ArgumentListMatcher.new(*args, &block) self end