0

I have a ruby pact mock service provider that captures my request. I would like to extract the exact value provided in the request (which was matched by a Pact.term / Pact.like), to do further processing with that value once the request has been answered by the pact service provider.

An example: a password reset functionality. Code makes an API call to a mailing service, providing the password reset link as parameter. Pact captures the request and mocks it successfully, validating the data. I pass the reset_link as one of the parameters (a Json body). This gets match in a Pact.term. All good. But I also want to recover the exact value that was used in the request (say reset_link: 'http://sample.com/reset-password?key=12345'), so I can make a subsequent request and check that exact link does indeed allow a successful password reset.

Now, if I was sending email directly, it is easy to do, I can just parse Mail::TestMailer.deliveries.last

How can I do this?

I've gone through the code, even creating a Pact::SomethingLike subclass wouldn't work, as the comparison method is a lovely functional programming module, not a method in the class.

Is there a before / after hook, or a way to grab the whole web request?

PS: I'm aware this is typically tested by the underlying library I use. The library sanctioned way of adjusting functionality is to override certain methods, I need to re-test the whole functionality.

PPS: this is not rails but roda.

Thanks André

André
  • 1

1 Answers1

1

I'm not sure if Pact Ruby supports this exact requirement, however digging into why you're doing this, I'd suggest it's a bad idea.

This is a functional test, something that Pact consciously makes difficult to support. See https://docs.pact.io/best_practices/contract_tests_not_functional_tests.html for more details as to why. There are better tools for the job for these sorts of tests, and they don't belong in the consumer code base (they absolutely do belong in the Providers' test suite).

Pact is a contract testing tool, and as such is only interested in isolated request/response contracts, not chained ones as per functional tests.

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18