Class: Pact::MockService::RequestHandlers::HandleMultipleInteractionsFound

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(actual_request, matching_interactions, verified_interactions, actual_interactions, logger) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 87

def self.call actual_request, matching_interactions, verified_interactions, actual_interactions, logger
  logger.error "Multiple interactions found for #{actual_request.method_and_path}:"
  matching_interactions.each do | interaction |
    logger.debug pretty_generate(Pact::MockService::InteractionDecorator.new(interaction))
  end
  response actual_request, matching_interactions
end

.request_summary_for(interaction) ⇒ Object



103
104
105
106
107
108
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 103

def self.request_summary_for interaction
  summary = {:description => interaction.description}
  summary[:provider_state] if interaction.provider_state
  summary[:request] = Pact::MockService::RequestDecorator.new(interaction.request)
  summary
end

.response(actual_request, matching_interactions) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 95

def self.response actual_request, matching_interactions
  response = {
    message: "Multiple interaction found for #{actual_request.method_and_path}",
    matching_interactions:  matching_interactions.collect{ | interaction | request_summary_for(interaction) }
  }
  [500, {'Content-Type' => 'application/json'}, [response.to_json + "\n"]]
end