[rspec-devel] [ rspec-Feature Requests-8815 ] should_receive(:method).with('val') should report the arg it actually received instead of saying it received it 0 times.

noreply at rubyforge.org noreply at rubyforge.org
Thu Feb 22 15:58:12 EST 2007


Feature Requests item #8815, was opened at 2007-02-22 19:42
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=8815&group_id=797

Category: mock module
Group: None
>Status: Closed
Priority: 3
Submitted By: Martin Emde (zraii)
>Assigned to: David Chelimsky (dchelimsky)
Summary: should_receive(:method).with('val') should report the arg it actually received instead of saying it received it 0 times.

Initial Comment:
Right now, if you have a should_receive(:method).with(:any_arg_here) and the method receives the message but with a different arg, it just says:

Mock 'object' expected method with (:any_arg_here) once, but received it 0 times

This is not very useful when you're trying to figure out if it's not being called at all, or if it's being called with the wrong arg.

A spec that shows this would be something like this:

context "A Mock Object" do
  setup do
    @m = mock('object')
  end

  specify "should receive :method with 'value'" do
    @m.should_receive(:method).with('value')
    @m.method('other value')
  end
end

This spec will fail obviously, but the failure message will not tell you anything besides that the 'should receive' was not received, not that it *was* in fact received, just with the wrong arguments. Quite a bit of difference when you're trying to debug some code.

I appreciate everyone on rspec's hard work. Keep it up.

-Martin

----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-02-22 20:58

Message:
Actually, this is already fixed in 0.8.0-RC1. Here's the output from your example:

$ spec bug8815.rb 

F

1)
Spec::Mocks::MockExpectationError in 'A Mock Object should receive :method with 'value''
Mock 'object' expected :method with ("value") but received it with ("other value")
./bug8815.rb:8:

Finished in 0.001214 seconds

1 specification, 1 failure

Cheers,
David

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=8815&group_id=797


More information about the rspec-devel mailing list