pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
73 stars 69 forks source link

Misleading "No interaction" summary message in some situations #77

Open TimothyJones opened 7 years ago

TimothyJones commented 7 years ago

When an interaction described in the test suite differs from the interaction sent by the client, the summary message is something like:

  1) SomeProvider service View can add a new view :
     No interaction found for PATCH /view/

It's easy to read this as implying that the problem is with the POST or the /view/ not matching in the request, when it might be because the request fails to match for other reasons (such as a different body content or headers).

Further up, the detailed output says:

Pact verification failed!
Actual interactions do not match expected interactions for mock MockService.

Incorrect requests:
    PATCH /view/0 (request body did not match)

See /Users/tjones/office/jobsearch-malcolm-ui/logs/pact.log for details.
        2) "after each" hook for ""

I think the incorrect requests line there: PATCH /view/0 (request body did not match) would be a better summary than the No interaction found message.

If there's no easy way to pull a good summary for all the cases that cause No interaction, then an easy improvement would be:

No interaction found for PATCH /view/ (see detailed output above)

Happy to contribute PRs if it would be helpful.

bethesque commented 7 years ago

I'm trying to find the code that provides that "No interaction found for" message, and this is what I found:

def self.response interaction_mismatch
          response = {
            message: "No interaction found for #{interaction_mismatch.actual_request.method_and_path}",
            interaction_diffs:  interaction_mismatch.to_hash
          }
          [500, {'Content-Type' => 'application/json'}, [response.to_json]]
        end

I'm not sure if something in the js is stripping out that extra info, or if it's a ruby thing. Can you post the full logs? Or better yet, fork the pact-js repo and create a running example.

TimothyJones commented 7 years ago

Here's an example of the test output, and here's the pact.log

Can create an example if that doesn't illustrate the problem well enough.

bethesque commented 7 years ago

You're right, that is not helpful output. I'm still not sure exactly where the "No interaction found for PATCH /view/0" is being printed from. Can you throw together an executable for me by forking pact-js and modifying one of these https://github.com/pact-foundation/pact-js/tree/master/examples

I'll have a play with it locally if I can find time, or maybe @mefellows can.

TimothyJones commented 7 years ago

Here's an example:

https://github.com/TimothyJones/pact-js/tree/issue-77/examples/issue-77

The output is slightly different, because I used the test runner from one of the other examples, but the error message is the same.

vashchukmaksim commented 5 years ago

@TimothyJones did you find a reason for the error?

TimothyJones commented 5 years ago

You can tell why the error is happening from the more detailed log file (presuming your log level is configured high enough).

This issue was about improving the error message to include the relevant details from the log - but I don’t think anyone had time to look into it yet.

TimothyJones commented 5 years ago

The error means that the actual request didn’t match the expected one for some reason- but the error suggests (sometimes incorrectly) that the http method and URL weren’t correct.