kingpong / perl-Test-Spec

rSpec-like test system for Perl
http://search.cpan.org/dist/Test-Spec/lib/Test/Spec.pm
30 stars 17 forks source link

Request: Improve ->with(...) and ->with_deep(...) error reporting #43

Open PunchyRascal opened 7 years ago

PunchyRascal commented 7 years ago

Methods with and with_deep are very useful for efficient mocking, however when the expectation is not met, they provide little information as to what is actually wrong.

It would be very nice, if the parameters could be for example compared using Test::Differences's eq_or_diff or similar debug method.

Thanks.

andyjones commented 7 years ago

Do you have any error messages that you can share so I can see what you mean?

PunchyRascal commented 7 years ago

Not ATM (can provide them tomorrow) but basically, the with method reports only something along the lines of: "Expected parameters do no match" (or number of parameters) and with_deep reports for example that "array with 3 elements was expected, but got 6 elements".

But you have no idea what those extra or missing parameters are or how the values differ when they do.

PunchyRascal commented 7 years ago

Here are the error messages with and with_deep produce now:

with

Number of arguments don't match expectation

or

 Expected argument in position 0 to be 'http://example.com', but it was 'moo'

with_deep

   got : array with 5 element(s)
expect : array with 6 element(s)

or

 Compared $data->[0][4]
   got : 'foo-downloaded-content'
expect : 'foo-downloaded-contenta'

So actually it's already halfway there - in case the number of arguments matches, the differences are shown, but not otherwise.

andyjones commented 7 years ago

Thanks.

I'll look at improving the with error messages over the weekend as that is built by Test::Spec.

Test::Deep builds the error message for with_deep so it is probably best to raise that example with them.