[rspec-users] MockExpectationError actual args format for stubbed messages

Tom Stuart tom at experthuman.com
Wed Nov 18 05:53:55 EST 2009


Hi,

Is it realistic and desirable to tweak RSpec so that the MockExpectationError for a stubbed message works as specified in the attached spec patch?

In short, we wasted some time today on a wild goose chase because a failing expectation error was saying "unexpected arguments, expected: (#<Foo ...>, #<Bar ...>), got: ([#<Foo ...>, #<Bar ...>])" which made it look like we were accidentally building an array around our arguments somewhere in our implementation. Ultimately it turned out that it was a genuine problem with equality between the Foo instances but we were distracted by the array notation for the actual arguments.

Having looked at the RSpec specs I now see that this is intended behaviour because the error is reporting an array of argument arrays, one for each unexpected message. This is understandable but, I think, unnecessarily misleading; it would be much nicer if the most common case (only one unexpected message) looked like "got: (#<Foo ...>, #<Bar ...>)" and we found another syntax for showing multiple calls. In the spec patch I've suggested "got: (#<Foo ...>, #<Bar ...>), (#<Baz ...>, #<Qux ...>)" because that shows multiple messages while avoiding any confusion about whether actual arrays were involved.

I realise this would involve some changes to the plumbing around ErrorGenerator so that the semantics of #raise_unexpected_message_args_error become "here is a (usually single-element) array of argument arrays" rather than the current hack of "here is an argument array (except occasionally it won't quite be, but always display it as though it is)".

I'm happy to investigate, but before I do, does my suggestion meet with general approval?

Cheers,
-Tom

-------------- next part --------------
A non-text attachment was scrubbed...
Name: format_args_for_stubbed_message_expectations.diff
Type: application/octet-stream
Size: 2070 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091118/a2767234/attachment.obj>


More information about the rspec-users mailing list