This repository was archived by the owner on Dec 5, 2019. It is now read-only.
Fix nil issue of example_uri_values(contract)#160
Open
ruanwz wants to merge 1 commit intothoughtworks:masterfrom
Open
Fix nil issue of example_uri_values(contract)#160ruanwz wants to merge 1 commit intothoughtworks:masterfrom
ruanwz wants to merge 1 commit intothoughtworks:masterfrom
Conversation
I got following error when simulate the contract with url like: http://abc.com?a=3&d=4 Failure/Error: result = contracts.simulate_consumers TypeError: no implicit conversion of nil into Hash # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/actors/from_examples.rb:35:in `merge!' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/actors/from_examples.rb:35:in `build_request' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/consumer.rb:70:in `build_request' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/consumer.rb:52:in `reenact' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/contract.rb:64:in `execute' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/contract.rb:40:in `simulate_request' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/contract_set.rb:9:in `map' # /home/david/.rvm/gems/ruby-2.1.1/gems/pacto-0.4.0.rc1/lib/pacto/contract_set.rb:9:in `simulate_consumers'
Collaborator
|
Thanks @ruanwz. Could you send a sample contract or create a test scenario? I think you found a bug, but maybe not quite the one you thought. That line obviously can return nil, but I don't think it should so setting a default value might not be the best fix. I suspect the actual problem is related to optional slashes in the path. The URI template is probably built with a slash, but then getting called with a URI that doesn't contain one: t = Addressable::Template.new('http://abc.com/{?othervars*}')
# works with a slash
uri = Addressable::URI.heuristic_parse('http://abc.com/?a=3&d=4')
t.extract uri
# => {"othervars"=>{"a"=>"3", "d"=>"4"}}
# fails without a slash
uri = Addressable::URI.heuristic_parse('http://abc.com?a=3&d=4')
t.extract uri
# => nilMany APIs don't care if the final slash is present or not, so Pacto should probably treat '/?a=3&d=4' and '?a=3&d=4' (or '/foo?a=3&d=4' vs '/foo/?a=3&d=4') as equivalent by default, but with an option to be more strict about slashes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I got following error when simulate the contract with url like: http://abc.com?a=3&d=4