Comments (10)
Pact::Term should work in a header - I've just written spec to show this here:
There must be something else going wrong.
from pact-mock_service.
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.
@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.
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.
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.
@bethesque Yay! I'm not crazy!
from pact-mock_service.
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.
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.
No worries. I'll let you close this once you've verified it works.
from pact-mock_service.
Yep, tried the same code, worked like a charm. Cheers.
from pact-mock_service.
Related Issues (20)
- Feature Request - Log level CLI Option on pact-stub-service HOT 1
- Can't start mock service wrong number of arguments (given 4, expected 2..3) (ArgumentError) HOT 1
- Internal server error when request payload cannot be encoded to UTF-8 HOT 9
- Count the number requests matching an interaction HOT 1
- Request to '/pact' endpoint without body is failing making python-pact verification unusable HOT 1
- Feature Request - support dynamic responses based on ID in request HOT 5
- given pacts dir not used HOT 2
- pactfile_write_mode - "usage" text is missing the option to 'update' HOT 2
- Ruby 2.7 cannot load such file -- thwait HOT 9
- Allow Access-Control-Allow-Credentials to be set for --cors mode HOT 13
- Feature request: json response from /interactions/verification
- Chore: migrate away from TravisCI HOT 1
- iam not able to generate pact files ,just the this infoi iam getting "INFO WEBrick::HTTPServer#start: pid=15660 port=1234" HOT 2
- Return more informative response codes HOT 2
- Feature request - Response based on provider state HOT 1
- Return most specific match when multiple matches are found HOT 4
- Can you please provide me the response model for POST /pact endpoint. HOT 2
- Pact stub service throws error for query values with matching rules HOT 5
- GH repo notifications on release HOT 1
- Update to rack 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pact-mock_service.