[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 14:42:00 EST 2007


Feature Requests item #8815, was opened at 2007-02-22 12: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: Open
Priority: 3
Submitted By: Martin Emde (zraii)
Assigned to: Nobody (None)
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

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

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