Fix expected body when using generators #353
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since v1.66.0, with the introduction of generators, we started to see issues where instead of setting the JSON body of the expected request as a string, Pact started returning the same data but encoded as query parameters.
The consumer Pact is generated using v3 of the Pact spec with the JVM SDK, and specifically
stringType
fromPactDslJsonBody
. It produces a Pact file that contains something likeYou can find a reproduction case in a dedicated repository.
Just run
bundle exec rake pact:verify:foobar
to have a successful verification with v1.65.3.And run
FAIL=1 bundle exec rake pact:verify:foobar
to demonstrate the issue with v1.66.0.After investigating a bit, we narrowed it down to that commit.
In order to demonstrate the issue, I added this test.
My proposed fix is done in
Pact::Provider::Request::Replayable
because I'm not super familiar with the code base and I wasn't sure ifPact::Provider::Generators.apply_generators
should ever return anything else than a string or not. But if it's not the case, the fix could probably go inPact::Provider::Generators
as I suspect there is the same issue with the way path and maybe headers are generated as well.I'd be happy to fix it another way if you find it better and cover other cases if needed. Just let me know 😄