class RSpec::Mocks::MessageExpectation

def with(*args, &block)

# => passes
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 args.empty?
    raise ArgumentError,
      "`with` must have at least one argument. Use `no_args` matcher to set the expectation of receiving no arguments."
  end
  self.inner_implementation_action = block
  @argument_list_matcher = ArgumentListMatcher.new(*args)
  self
end