Skip to content

Commit

Permalink
feat: upgrade to pact-support 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Mar 23, 2018
1 parent e88c003 commit 20fea42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/pact/consumer_contract/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def initialize attributes = {}
@content = attributes[:content]
end

def self.from_hash hash
content_hash = Pact::MatchingRules.merge(hash['content'], hash['content']['matchingRules'])
def self.from_hash hash, options
content_hash = Pact::MatchingRules.merge(hash['content'], hash['content']['matchingRules'], options)
content = Pact::ConsumerContract::Message::Content.new(content_hash)
new(symbolize_keys(hash).merge(content: content))
end
Expand Down
12 changes: 11 additions & 1 deletion lib/pact/message/consumer_contract_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class ConsumerContractParser

def call(hash)
hash = symbolize_keys(hash)
interactions = hash[:messages].collect { |hash| Pact::ConsumerContract::Message.from_hash(hash)}
options = { pact_specification_version: pact_specification_version(hash) }
interactions = hash[:messages].collect { |hash| Pact::ConsumerContract::Message.from_hash(hash, options)}
ConsumerContract.new(
:consumer => ServiceConsumer.from_hash(hash[:consumer]),
:provider => ServiceProvider.from_hash(hash[:provider]),
Expand All @@ -20,6 +21,15 @@ def call(hash)
def can_parse?(hash)
hash.key?('messages') || hash.key?(:messages)
end

def pact_specification_version hash
# TODO handle all 3 ways of defining this...
# metadata.pactSpecificationVersion
maybe_pact_specification_version_1 = hash[:metadata] && hash[:metadata]['pactSpecification'] && hash[:metadata]['pactSpecification']['version']
maybe_pact_specification_version_2 = hash[:metadata] && hash[:metadata]['pactSpecificationVersion']
pact_specification_version = maybe_pact_specification_version_1 || maybe_pact_specification_version_2
pact_specification_version ? Pact::SpecificationVersion.new(pact_specification_version) : Pact::SpecificationVersion::NIL_VERSION
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion pact-message.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency "pact-support", "1.2.99.alpha.1"
spec.add_runtime_dependency "pact-support", "~> 1.5"
# pact-mock_service dependencies are Pact::ConsumerContractDecorator
# and Pact::ConsumerContractWriter. Potentially we should extract
# or duplicate these classes to remove the pact-mock_service dependency.
Expand Down

0 comments on commit 20fea42

Please sign in to comment.