pact-foundation / pact-ruby

Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
2.16k stars 215 forks source link

Writing pact file results in non spec v3 compatible matching rules #157

Open Danny02 opened 6 years ago

Danny02 commented 6 years ago

I'm using Pact-JS (+pact-js-karma) to test my consumer tests and want to generate Pact files according to version 3 of the Pact spec. I think that I have set the spec option correctly, because the resulting pact file includes

"metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    }
  }

The generated matching rules are in v2 format:

"$.body._embedded.schuleList[*].*": {
            "match": "type"
 }

Our expectation regarding the generated output according to spec v3 was something like:

"body" : {
"$._embedded.schuleList[*].*": {
    "matchers": [
                {"match": "type" }
     ]       
 }
}
bethesque commented 6 years ago

Sorry, pact spec v3 is not supported in js yet. Which feature were you particularly interested in?

YOU54F commented 1 month ago

The pact specification is not passed in when pact_mock-service calls the MatchingRules.extract function in pact-support

https://github.com/pact-foundation/pact-support/blob/master/lib/pact/matching_rules.rb#L11

I've added a commit and pull request that will pass the spec version used.

https://github.com/pact-foundation/pact-mock_service/pull/159

however the matching rules are written incorrectly.

pact-message-ruby attempts to correct this here

https://github.com/pact-foundation/pact-message-ruby/blob/8c74b1357333b6c08e801064cc56e61d6ba2049d/lib/pact/message/consumer/interaction_decorator.rb#L50

whereby it would write

      "matchingRules": {
        "body": {
          "$.email": {
            "match": "type"
          },
          "$.first_name": {
            "match": "type"
          }
        }
      }

but it should write

      "matchingRules": {
        "body": {
          "$.email": {
            "matchers": [
              {
                "match": "type"
              }
            ]
          },
          "$.first_name": {
            "matchers": [
              {
                "match": "type"
              }
            ]
          }
        }
      }