Class: Pact::InteractionV2Parser

Inherits:
Object
  • Object
show all
Includes:
SymbolizeKeys
Defined in:
lib/pact/consumer_contract/interaction_v2_parser.rb

Class Method Summary collapse

Methods included from SymbolizeKeys

included, #symbolize_keys

Class Method Details

.call(hash, options) ⇒ Object



13
14
15
16
17
18
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 13

def self.call hash, options
  request = parse_request(hash['request'], options)
  response = parse_response(hash['response'], options)
  provider_states = parse_provider_states(hash['providerState'] || hash['provider_state'])
  Interaction.new(symbolize_keys(hash).merge(request: request, response: response, provider_states: provider_states))
end

.parse_provider_states(provider_state_name) ⇒ Object



30
31
32
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 30

def self.parse_provider_states provider_state_name
  provider_state_name ? [Pact::ProviderState.new(provider_state_name)] : []
end

.parse_request(request_hash, options) ⇒ Object



20
21
22
23
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 20

def self.parse_request request_hash, options
  request_hash = Pact::MatchingRules.merge(request_hash, request_hash['matchingRules'], options)
  Pact::Request::Expected.from_hash(request_hash)
end

.parse_response(response_hash, options) ⇒ Object



25
26
27
28
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 25

def self.parse_response response_hash, options
  response_hash = Pact::MatchingRules.merge(response_hash, response_hash['matchingRules'], options)
  Pact::Response.from_hash(response_hash)
end