pact-foundation / pact-support

Shared code for Pact gems
MIT License
7 stars 47 forks source link

Error ocurred in mock service: NoMethodError - undefined method `split' for ... #68

Closed a-iasevoli closed 5 years ago

a-iasevoli commented 5 years ago

I'll start by saying that I'm not a Ruby developer and I'm not that familiar with this project.

I have this scenario: 1 pact file with 2 interactions. One interaction has "content-type": "multipart/form-data;boundary=BOUNDARY" in the header The other has "application/json;charset=utf-8" in the header

For some reason, as soon as there is a multipart/form-data between the interactions, pact-support (or mock-service) uses MultipartFormDiffer to get the difference between expected and actual from all the interactions!

If I remove the multipart interaction, MultipartFormDiffer is not used anymore.

Because the body of a application/json;charset=utf-8 request is a json object, split is not defined and it fails.

This is the entire log

E, [2019-05-31T19:45:21.050556 #60814] ERROR -- : Error ocurred in mock service: NoMethodError - undefined method `split' for #<Hash:0x00007fabab279f08> E, [2019-05-31T19:45:21.050717 #60814] ERROR -- : /usr/local/lib/ruby/gems/2.5.0/gems/pact-support-1.10.2/lib/pact/shared/multipart_form_differ.rb:11:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/pact-support-1.10.2/lib/pact/consumer_contract/request.rb:72:in `body_diff' /usr/local/lib/ruby/gems/2.5.0/gems/pact-support-1.10.2/lib/pact/consumer_contract/request.rb:42:in `difference' /usr/local/lib/ruby/gems/2.5.0/gems/pact-support-1.10.2/lib/pact/consumer_contract/request.rb:28:in `matches?' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/interactions/candidate_interactions.rb:8:in `block in matching_interactions' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/interactions/candidate_interactions.rb:7:in `select' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/interactions/candidate_interactions.rb:7:in `matching_interactions' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/request_handlers/interaction_replay.rb:55:in `find_response' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/request_handlers/interaction_replay.rb:45:in `respond' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/request_handlers/base_request_handler.rb:17:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/cascade.rb:33:in `block in call' /usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/cascade.rb:24:in `each' /usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/cascade.rb:24:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/consumer/mock_service/cors_origin_header_middleware.rb:11:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/consumer/mock_service/error_handler.rb:13:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/app.rb:33:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/pact-mock_service-3.1.1/lib/pact/consumer/mock_service/set_location.rb:14:in `call' /usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.7/lib/rack/handler/webrick.rb:86:in `service' /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:140:in `service' /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:96:in `run' /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/webrick/server.rb:307:in `block in start_thread'

bethesque commented 5 years ago

Can you fork https://github.com/pact-foundation/pact-ruby-standalone-e2e-example and modify it to recreate the issue please? You don't need to know Ruby.

a-iasevoli commented 5 years ago

Sorry it took a bit. Here is the fork https://github.com/ai-dev/pact-ruby-standalone-e2e-example

bethesque commented 5 years ago

Thank you. When it's quick for me to recreate it, it's quick for me to fix it! I've released the fix to the pact-support gem. Are you using one of the wrapper libraries that also needs to be released? (pact-js, python, pact-net?)

a-iasevoli commented 5 years ago

Thanks to you! Yes, I'm using pact-node to create the stub server

bethesque commented 5 years ago

@mboudreau could you release pact-node with 1.67.0 of the standalone when you have a moment please?

mefellows commented 5 years ago

v.8.5.0 on its way out shortly.

akbhartiya commented 5 years ago

Hi Team,

We are getting same issue with pact-net 2.4.6. Is this version of pact-net include this fix. I am trying to create contract file with multipart/form-data Content-Type. Getting Below error from mock service Response Status: 500, Response Body: {"message":"Error ocurred in mock service: NoMethodError - undefined method `split' for #<Array:0x2e2fe28

Is there any example available for creating contract file where we tries to submit form data to Mock service and generates Contract file.

Thanks

bethesque commented 5 years ago

@akbhartiya you'll need to supply an executable example so we can recreate the issue. I've submitted a PR to update to the latest ruby standalone here - hopefully that fixes it.

neilcampbell commented 5 years ago

@akbhartiya @bethesque The latest ruby standalone core (1.70.0) will be packaged in Pact-Net 2.4.7, which is building right now.

bethesque commented 5 years ago

Thanks Neil. @akbhartiya let us know if you're still having the issue after upgrading.