Class: Pact::Request::Expected
- Defined in:
- lib/pact/consumer_contract/request.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{:allow_unexpected_keys => false}.freeze
Instance Attribute Summary collapse
-
#generators ⇒ Object
Returns the value of attribute generators.
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Base
#body, #headers, #method, #path, #query
Class Method Summary collapse
Instance Method Summary collapse
- #difference(actual_request) ⇒ Object
-
#initialize(method, path, headers, body, query, options = {}, generators = {}) ⇒ Expected
constructor
A new instance of Expected.
- #matches?(actual_request) ⇒ Boolean
- #matches_route?(actual_request) ⇒ Boolean
Methods inherited from Base
#content_type, #content_type?, #full_path, #method_and_path, #modifies_resource?, #specified?, #to_hash
Methods included from SymbolizeKeys
Constructor Details
#initialize(method, path, headers, body, query, options = {}, generators = {}) ⇒ Expected
Returns a new instance of Expected.
23 24 25 26 27 |
# File 'lib/pact/consumer_contract/request.rb', line 23 def initialize(method, path, headers, body, query, = {}, generators = {}) super(method, path, headers, body, query) @generators = generators @options = end |
Instance Attribute Details
#generators ⇒ Object
Returns the value of attribute generators.
9 10 11 |
# File 'lib/pact/consumer_contract/request.rb', line 9 def generators @generators end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/pact/consumer_contract/request.rb', line 9 def @options end |
Class Method Details
.from_hash(hash) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# 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) = sym_hash.fetch(:options, {}) generators = sym_hash.fetch(:generators, {}) new(method, path, headers, body, query, , generators) end |
Instance Method Details
#difference(actual_request) ⇒ Object
40 41 42 43 44 45 |
# 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) ⇒ Boolean
29 30 31 |
# File 'lib/pact/consumer_contract/request.rb', line 29 def matches?(actual_request) difference(actual_request).empty? end |
#matches_route?(actual_request) ⇒ Boolean
33 34 35 36 37 38 |
# 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 |