Class: Pact::MockService::RequestHandlers::HandleMultipleInteractionsFoundForStub

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



115
116
117
118
119
120
121
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 115

def self.call actual_request, matching_interactions, verified_interactions, actual_interactions, logger
  logger.warn "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, verified_interactions, actual_interactions, logger
end

.first_most_successful_interaction(matching_interactions) ⇒ Object



129
130
131
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 129

def self.first_most_successful_interaction matching_interactions
  matching_interactions.sort{ |i1, i2| Pact::Reification.from_term(i1.response.status) <=> Pact::Reification.from_term(i2.response.status) }.first
end

.response(actual_request, matching_interactions, verified_interactions, actual_interactions, logger) ⇒ Object



123
124
125
126
127
# File 'lib/pact/mock_service/request_handlers/interaction_replay.rb', line 123

def self.response actual_request, matching_interactions, verified_interactions, actual_interactions, logger
  logger.warn "Sorting responses by response status and returning first."
  interaction = first_most_successful_interaction(matching_interactions)
  HandleMatchedInteraction.call(interaction, verified_interactions, actual_interactions, logger)
end