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, #match?

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
# 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)
  if verification.all_matched?
    logger.info "Verifying - interactions matched for example \"#{example_description(env)}\""
    [200, {'Content-Type' => 'text/plain'}, ['Interactions matched']]
  else
    error_message = FailureMessage.new(verification).to_s
    logger.warn "Verifying - actual interactions do not match expected interactions for example \"#{example_description(env)}\". \n#{error_message}"
    logger.warn error_message
    [500, {'Content-Type' => 'text/plain'}, ["Actual interactions do not match expected interactions for mock #{name}.\n\n#{error_message}See #{logger.description} for details."]]
  end
end