class Pact::ConsumerContract::Message
Attributes
contents[RW]
description[RW]
metadata[RW]
provider_state[RW]
provider_states[RW]
Public Class Methods
from_hash(hash, options = {})
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 26 def self.from_hash hash, options = {} opts = options.dup unless opts[:pact_specification_version] opts[:pact_specification_version] = Pact::SpecificationVersion::NIL_VERSION end contents_matching_rules = hash['matchingRules'] && hash['matchingRules']['body'] contents_hash = Pact::MatchingRules.merge(hash['contents'], contents_matching_rules, opts) contents = Pact::ConsumerContract::Message::Contents.from_hash(contents_hash) metadata = hash['metaData'] || hash['metadata'] provider_state = hash['providerStates'] && hash['providerStates'].first && hash['providerStates'].first['name'] provider_states = parse_provider_states(hash['providerStates']) new(symbolize_keys(hash).merge( contents: contents, provider_state: provider_state, provider_states: provider_states, metadata: metadata)) end
new(attributes = {})
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 18 def initialize attributes = {} @description = attributes[:description] @provider_state = attributes[:provider_state] || attributes[:providerState] @provider_states = attributes[:provider_states] || [] @contents = attributes[:contents] @metadata = attributes[:metadata] end
Private Class Methods
parse_provider_states(provider_states)
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 123 def self.parse_provider_states provider_states (provider_states || []).collect do | provider_state_hash | Pact::ProviderState.new(provider_state_hash['name'], provider_state_hash['params']) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 92 def == other other.is_a?(Message) && to_hash == other.to_hash end
description_with_provider_state_quoted()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 113 def description_with_provider_state_quoted provider_state ? "\"#{description}\" given \"#{provider_state}\"" : "\"#{description}\"" end
eq?(other)
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 109 def eq? other self == other end
http?()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 80 def http? false end
match_criterion(target, criterion)
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 105 def match_criterion target, criterion target == criterion || (criterion.is_a?(Regexp) && criterion.match(target)) end
matches_criteria?(criteria)
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 96 def matches_criteria? criteria criteria.each do | key, value | unless match_criterion self.send(key.to_s), value return false end end true end
message?()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 84 def message? true end
request()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 53 def request @request ||= Pact::Consumer::Request::Actual.from_hash( path: '/', method: 'POST', query: nil, headers: { 'Content-Type' => 'application/json' }, body: { description: description, providerStates: [{ name: provider_state, params: {} }] } ) end
response()
click to toggle source
custom media type?
# File lib/pact/consumer_contract/message.rb, line 70 def response @response ||= Pact::Response.new( status: 200, headers: {'Content-Type' => 'application/json'}, body: { contents: contents } ) end
to_hash()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 44 def to_hash { description: description, provider_states: [{ name: provider_state }], contents: contents.to_hash, metadata: metadata } end
to_s()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 117 def to_s to_hash.to_s end
validate!()
click to toggle source
# File lib/pact/consumer_contract/message.rb, line 88 def validate! raise Pact::InvalidMessageError.new(self) unless description && contents end