Class: Pact::MockService::RequestHandlers::VerificationGet

Inherits:
BaseAdministrationRequestHandler show all
Defined in:
lib/pact/mock_service/request_handlers/verification_get.rb

Defined Under Namespace

Classes: FailureMessage

Constant Summary

Constants inherited from BaseRequestHandler

BaseRequestHandler::NOT_FOUND_RESPONSE

Constants included from Consumer::RackRequestHelper

Consumer::RackRequestHelper::REQUEST_KEYS

Instance Attribute Summary

Attributes inherited from BaseAdministrationRequestHandler

#logger, #name

Instance Method Summary collapse

Methods inherited from BaseAdministrationRequestHandler

#has_mock_service_header?, #match?, #method_matches?, #path_matches?

Methods inherited from BaseRequestHandler

#call, #json_response, #match?, #text_response

Methods included from Consumer::RackRequestHelper

#params_hash, #request_as_hash_from

Constructor Details

#initialize(name, logger, session) ⇒ VerificationGet

Returns a new instance of VerificationGet.



8
9
10
11
12
# File 'lib/pact/mock_service/request_handlers/verification_get.rb', line 8

def initialize name, logger, session
  super name, logger
  @expected_interactions = session.expected_interactions
  @actual_interactions = session.actual_interactions
end

Instance Method Details

#request_methodObject



18
19
20
# File 'lib/pact/mock_service/request_handlers/verification_get.rb', line 18

def request_method
  'GET'
end

#request_pathObject



14
15
16
# File 'lib/pact/mock_service/request_handlers/verification_get.rb', line 14

def request_path
  '/interactions/verification'
end

#respond(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pact/mock_service/request_handlers/verification_get.rb', line 22

def respond env
  verification = Pact::MockService::Interactions::Verification.new(expected_interactions, actual_interactions)
  example_desc = example_description(env)
  example_desc = example_desc ? " for example #{example_desc.inspect}" : ''
  if verification.all_matched?
    logger.info "Verifying - interactions matched#{example_desc}"
    text_response('Interactions matched')
  else
    error_message = FailureMessage.new(verification).to_s
    logger.warn "Verifying - actual interactions do not match expected interactions#{example_desc}. \n#{error_message}"
    logger.warn error_message
    response_message = "Actual interactions do not match expected interactions for mock #{name}.\n\n#{error_message}See #{logger.description} for details."
    text_response(response_message, 500)
  end
end