Class: MockServer::MockServerClient

Inherits:
AbstractClient show all
Includes:
Model, UtilityMethods
Defined in:
lib/mockserver/mock_server_client.rb

Overview

The client used to interact with the mock server.

Constant Summary

Constants included from Model

MockServer::Model::DEFAULT_MISSING_INDEX

Instance Attribute Summary

Attributes inherited from AbstractClient

#logger

Instance Method Summary collapse

Methods included from UtilityMethods

#camelize, #camelized_hash, #parse_string_to_json, #symbolize_keys

Methods inherited from AbstractClient

#clear, #dump_log, #initialize, #reset, #retrieve, #verify

Methods included from MockServer::Model::DSL

#at_least, #body, #cookie, #decode, #delay_by, #exact, #exactly, #expectation, #expectation_from_json, #forward, #header, #once, #parameter, #parameterized, #regex, #request, #request_from_json, #response, #times, #unlimited, #xpath

Constructor Details

This class inherits a constructor from MockServer::AbstractClient

Instance Method Details

#register(expectation) ⇒ Object

Registers an expectation with the mockserver

Parameters:

  • expectation (Expectation)

    the expectation to create the request from

Returns:

  • (Object)

    the response from the register action



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mockserver/mock_server_client.rb', line 21

def register(expectation)
  fail 'Expectation passed in is not valid type' unless expectation.is_a?(Expectation)
  request = create_expectation_request(expectation)

  logger.debug('Registering new expectation')
  logger.debug("URL: #{EXPECTATION_ENDPOINT} Payload: #{request.to_hash}")

  response = @base[EXPECTATION_ENDPOINT].put(request.to_json, content_type: :json)
  logger.debug("Got register response: #{response.code}")
  parse_string_to_json(response)
end