class Pact::Request::Expected
Constants
- DEFAULT_OPTIONS
Attributes
generators[RW]
options[RW]
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 11 def self.from_hash(hash) sym_hash = symbolize_keys hash method = sym_hash.fetch(:method) path = sym_hash.fetch(:path) query = sym_hash.fetch(:query, key_not_found) headers = sym_hash.fetch(:headers, key_not_found) body = sym_hash.fetch(:body, key_not_found) options = sym_hash.fetch(:options, {}) generators = sym_hash.fetch(:generators, {}) new(method, path, headers, body, query, options, generators) end
key_not_found()
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 58 def self.key_not_found Pact::NullExpectation.new end
new(method, path, headers, body, query, options = {}, generators = {})
click to toggle source
Calls superclass method
Pact::Request::Base::new
# File lib/pact/consumer_contract/request.rb, line 23 def initialize(method, path, headers, body, query, options = {}, generators = {}) super(method, path, headers, body, query) @generators = generators @options = options end
Public Instance Methods
difference(actual_request)
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 40 def difference(actual_request) require 'pact/matchers' # avoid recusive loop between pact/reification, pact/matchers and this file request_diff = Pact::Matchers.diff(to_hash_without_body_or_query, actual_request.to_hash_without_body_or_query) request_diff.merge!(query_diff(actual_request.query)) request_diff.merge!(body_diff(actual_request.body)) end
matches?(actual_request)
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 29 def matches?(actual_request) difference(actual_request).empty? end
matches_route?(actual_request)
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 33 def matches_route? actual_request require 'pact/matchers' # avoid recusive loop between pact/reification, pact/matchers and this file route = {:method => method.upcase, :path => path} other_route = {:method => actual_request.method.upcase, :path => actual_request.path} Pact::Matchers.diff(route, other_route).empty? end
Protected Instance Methods
query_diff(actual_query)
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 49 def query_diff actual_query if specified?(:query) query_diff = query.difference(actual_query) query_diff.any? ? {query: query_diff} : {} else {} end end
Private Instance Methods
body_diff(actual_body)
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 72 def body_diff(actual_body) if specified?(:body) body_difference = body_differ.call(body, actual_body, allow_unexpected_keys: runtime_options[:allow_unexpected_keys_in_body]) return { body: body_difference } if body_difference.any? end {} end
body_differ()
click to toggle source
# File lib/pact/consumer_contract/request.rb, line 80 def body_differ Pact.configuration.body_differ_for_content_type content_type end
runtime_options()
click to toggle source
Options is a dirty hack to allow Condor to send extra keys in the request, as it’s too much work to set up an exactly matching expectation. Need to implement a proper matching strategy and remove this. Do not rely on it!
# File lib/pact/consumer_contract/request.rb, line 68 def runtime_options DEFAULT_OPTIONS.merge(symbolize_keys(options)) end