Class: Pact::MockService::RequestHandlers::HandleMatchedInteraction

Inherits:
Object
  • Object
show all
Extended by:
PrettyGenerate
Defined in:
lib/pact/mock_service/request_handlers/interaction_replay.rb

Class Method Summary collapse

Methods included from PrettyGenerate

pretty_generate

Class Method Details

.call(interaction, verified_interactions, actual_interactions, logger) ⇒ Object



171
172
173
174
175
176
177
178
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 171

def self.call interaction, verified_interactions, actual_interactions, logger
  actual_interactions.register_matched interaction
  verified_interactions << interaction
  response = response_from(interaction.response)
  logger.info "Found matching response for #{interaction.request.method_and_path}"
  logger.debug pretty_generate(Pact::MockService::ResponseDecorator.new(interaction.response))
  response
end

.render_body(body) ⇒ Object



184
185
186
187
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 184

def self.render_body body
  return '' if body.nil?
  body.kind_of?(String) ? body.force_encoding('utf-8') : body.to_json
end

.response_from(response) ⇒ Object



180
181
182
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 180

def self.response_from response
  [response.status, (Pact::Reification.from_term(response.headers) || {}).to_hash, [render_body(Pact::Reification.from_term(response.body))]]
end