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

David Chelimsky dchelimsky at gmail.com
Wed Nov 18 14:54:40 EST 2009


On Wed, Nov 18, 2009 at 2:53 AM, Tom Stuart <tom at experthuman.com> wrote:

> 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?
>

Approved!

Please submit a lighthouse ticket and reference a patch from there.

Thanks!

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091118/fd9d9c87/attachment-0001.html>


More information about the rspec-users mailing list