pact-ruby: Some problems with pact specs

Hi

We are coding on ruby (https://github.com/umbrellio) and are looking for the system for testing our decoupled services. In particular we have a number of HTTP APIs. At some point we found Pact and decided to try it out. And we encountered some difficulties using it.

First of all, it’s somewhat weird that core ruby implementation doesn’t implement 3rd version of pact-specification.

Then we have found some bugs (or we just didn’t understand how it works).

For example, when we describe provider state at the provider side and we have an exception in set_up block, it doesn’t call the tear_down block. We are using transaction database cleaner strategy, and we can’t rollback the transaction because of this behaviour. We would like to use something like rspec around strategy, but it just doesn’t exist.

Secondly, we’d like to use an array of regexps in consumer pacts. We tried to use this code:

dates: each_like(Pact.term(generate: "2018-08-03", matcher: /\d{4}\-\d{2}\-\d{2}/)),

and on the consumer side it sucessfully generates the json with:

        "body": {
          "dates": [
            "2018-08-03"
          ]
        },
        "matchingRules": {
          "$.body.dates": {
            "min": 1
          },
          "$.body.dates[*].*": {
            "match": "type"
          },
          "$.body.dates[*]": {
            "match": "regex",
            "regex": "\\d{4}\\-\\d{2}\\-\\d{2}"
          }
        }

As we can see, there is a matching rules for $.body.dates[*] that is obviously saying that every item of the dates array must match a regexp. But pact:verify script doesn’t respect it saying that WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>"\\d{4}\\-\\d{2}\\-\\d{2}"} for path $['body']['dates'][*]

Then we tried to use a regexp in Pact.term with i modifier to make it case-insensitive, like Pact.term(generate: "AA", matcher: /a+/i) but we’ve got an error

  Value to generate "AA" does not match regular expression /a+\//

We like the ideas underlying Pact and it already does a lot. And we’d love to use it in our projects. But obviously, there is some room for improvements at least with specs integration and troubleshooting. We’d like to know if you are interested in collaboration, foreign pull requests to codebase and will you help us to investigate and solve the problems together.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 4
  • Comments: 27 (11 by maintainers)

Most upvoted comments

does CDC is intended to test the Syntax rather than going deeper to test the semantics as well.

@bheemreddy181 I’m not sure what you define semantics as here. My gut feel is that semantics are important but behaviour is not.

For example. Imagine you are testing a POST to create an object. The contract test cares that the response contains the location of the newly created object in the headers, the response code is a 201, and perhaps the body contains the resource itself. The contract test does not care whether or not the object was actually created and stored in the provider (that’s the job of the functional tests in the provider codebase). So, yes, you could stub out your database (or anything below the controller), if you also had “contract” tests to make sure that the layer you’re stubbing out behaves the way you think it should.