Giter Site home page Giter Site logo

Comments (10)

bethesque avatar bethesque commented on June 16, 2024

Pact::Term should work in a header - I've just written spec to show this here:

https://github.com/realestate-com-au/pact/blob/master/spec/integration/consumer_with_pact_term_header.rb

There must be something else going wrong.

from pact-mock_service.

mboudreau avatar mboudreau commented on June 16, 2024

Okay, that's weird, it does seem to work, but it seems that it's the somethingLike that's failing in the body data. It was working before I changed the header...

Disregard.

from pact-mock_service.

mboudreau avatar mboudreau commented on June 16, 2024

@bethesque Okay, how about instead, there's better error handling/messaging when the somethingLike matcher doesn't work. It doesn't mention any particular line in the body (or whatever it's matching on) that's not matching, just an error stack being returned.

{
"message": "Error ocurred in mock service: TypeError - can't convert Pact::Term to String",
"backtrace": [
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/configuration.rb:93:in `=~'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/configuration.rb:93:in `block in body_differ_for_content_type'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/configuration.rb:93:in `each'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/configuration.rb:93:in `find'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/configuration.rb:93:in `body_differ_for_content_type'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/consumer_contract/request.rb:79:in `body_differ'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/consumer_contract/request.rb:72:in `body_diff'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/consumer_contract/request.rb:42:in `difference'",
"/var/lib/gems/1.9.1/gems/pact-support-0.3.0/lib/pact/consumer_contract/request.rb:30:in `matches?'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/interactions/candidate_interactions.rb:8:in `block in matching_interactions'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/interactions/candidate_interactions.rb:7:in `select'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/interactions/candidate_interactions.rb:7:in `matching_interactions'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/request_handlers/interaction_replay.rb:50:in `find_response'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/request_handlers/interaction_replay.rb:40:in `respond'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/request_handlers/base_request_handler.rb:17:in `call'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/cascade.rb:33:in `block in call'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/cascade.rb:24:in `each'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/cascade.rb:24:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/consumer/mock_service/cors_origin_header_middleware.rb:11:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/consumer/mock_service/error_handler.rb:13:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/mock_service/app.rb:32:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.4.0/lib/pact/consumer/mock_service/set_location.rb:14:in `call'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/handler/webrick.rb:89:in `service'",
"/var/lib/gems/1.9.1/gems/webrick-1.3.1/lib/webrick/httpserver.rb:138:in `service'",
"/var/lib/gems/1.9.1/gems/webrick-1.3.1/lib/webrick/httpserver.rb:94:in `run'",
"/var/lib/gems/1.9.1/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'"
]
}

This is not the first time it's happened. It's kind of hard to debug this issue without having a local debug version going.

from pact-mock_service.

bethesque avatar bethesque commented on June 16, 2024

That one might be a genuine bug. It uses the content type to work out which matching type to use (eg form, JSON, string). What it's currently doing is trying to use the Pact::Term to work out which content type it is, instead of the usual String that it gets from the Content-Type. I will look into it.

from pact-mock_service.

mboudreau avatar mboudreau commented on June 16, 2024

Okay, this is getting weirder. I have this interaction:

mockService
    .given('a form context id and an instance id')
    .uponReceiving('a PUT request with a form json')
    .withRequest(
        'put', 
        term('^/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', '/e0873a45-c1f7-4cf8-98b3-b6f93cadb0fc'), 
        {
            'Content-Type': 'application/json;charset=UTF-8',
            'Accept': 'application/vnd.formsbuilderapi-v1+json'
        }, 
        somethingLike(saveMock))
    .willRespondWith({
        status: 200
    });

Which works fine in Chrome because of the UTF automatic capitalization, so I need something to simply look for application/json in the content-type header, so I add the following to make it generic:

mockService
    .given('a form context id and an instance id')
    .uponReceiving('a PUT request with a form json')
    .withRequest(
        'put', 
        term('^/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', '/e0873a45-c1f7-4cf8-98b3-b6f93cadb0fc'), 
        {
            'Content-Type': term('application/json','application/json'),
            'Accept': 'application/vnd.formsbuilderapi-v1+json'
        }, 
        somethingLike(saveMock))
    .willRespondWith({
        status: 200
    });

Which will try to make anything with application/json in it match (as per the ruby regex validator that I found, this should work). However, when I change it to what's mentioned in the previous one, I get an error back:

{
"message": "Error ocurred in mock service: TypeError - can't convert Pact::Term to String",
"backtrace": [
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/configuration.rb:93:in `=~'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/configuration.rb:93:in `block in body_differ_for_content_type'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/configuration.rb:93:in `each'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/configuration.rb:93:in `find'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/configuration.rb:93:in `body_differ_for_content_type'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/consumer_contract/request.rb:79:in `body_differ'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/consumer_contract/request.rb:72:in `body_diff'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/consumer_contract/request.rb:42:in `difference'",
"/var/lib/gems/1.9.1/gems/pact-support-0.2.1/lib/pact/consumer_contract/request.rb:30:in `matches?'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/interactions/candidate_interactions.rb:8:in `block in matching_interactions'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/interactions/candidate_interactions.rb:7:in `select'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/interactions/candidate_interactions.rb:7:in `matching_interactions'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/request_handlers/interaction_replay.rb:50:in `find_response'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/request_handlers/interaction_replay.rb:40:in `respond'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/request_handlers/base_request_handler.rb:17:in `call'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/cascade.rb:33:in `block in call'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/cascade.rb:24:in `each'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/cascade.rb:24:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/consumer/mock_service/cors_origin_header_middleware.rb:11:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/consumer/mock_service/error_handler.rb:13:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/mock_service/app.rb:32:in `call'",
"/var/lib/gems/1.9.1/gems/pact-mock_service-0.3.0/lib/pact/consumer/mock_service/set_location.rb:14:in `call'",
"/var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/handler/webrick.rb:89:in `service'",
"/var/lib/gems/1.9.1/gems/webrick-1.3.1/lib/webrick/httpserver.rb:138:in `service'",
"/var/lib/gems/1.9.1/gems/webrick-1.3.1/lib/webrick/httpserver.rb:94:in `run'",
"/var/lib/gems/1.9.1/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'"
]
}

I'm not sure if it's because I'm trying to do too much (a term, another term and a somethingLike) in the request, or there's something fundamentally wrong with the comparison somewhere. Maybe it's just the regex that's wrong? I even tried with the a catchall regex term (.*) and still nothing. Can you please try to add this in the test to see if it's not just me going completely crazy?

from pact-mock_service.

mboudreau avatar mboudreau commented on June 16, 2024

@bethesque Yay! I'm not crazy!

from pact-mock_service.

bethesque avatar bethesque commented on June 16, 2024

Fixed. Please run bundle update pact-support. Or, given you don't like to use bundler, uninstall and reinstall the latest pact-mock_service gem.

from pact-mock_service.

mboudreau avatar mboudreau commented on June 16, 2024

Awesome, thanks!

On Tue Feb 24 2015 at 17:28:29 Beth Skurrie [email protected]
wrote:

Fixed. Please run bundle update pact-support. Or, given you don't like to
use bundler, uninstall and reinstall the latest pact-mock_service gem.


Reply to this email directly or view it on GitHub
#14 (comment)
.

from pact-mock_service.

bethesque avatar bethesque commented on June 16, 2024

No worries. I'll let you close this once you've verified it works.

from pact-mock_service.

mboudreau avatar mboudreau commented on June 16, 2024

Yep, tried the same code, worked like a charm. Cheers.

from pact-mock_service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.