perl-Test-Spec icon indicating copy to clipboard operation
perl-Test-Spec copied to clipboard

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

Open PunchyRascal opened this issue 7 years ago • 4 comments

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.

PunchyRascal avatar Aug 24 '17 12:08 PunchyRascal

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

andyjones avatar Aug 24 '17 15:08 andyjones

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 avatar Aug 24 '17 17:08 PunchyRascal

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.

PunchyRascal avatar Aug 25 '17 12:08 PunchyRascal

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.

andyjones avatar Aug 25 '17 13:08 andyjones