Class: Pact::Request::Expected
- Defined in:
- lib/pact/consumer_contract/request.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{:allow_unexpected_keys => false}.freeze
Constants included from Matchers
Instance Attribute Summary collapse
-
#options ⇒ Object
Temporary hack.
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 = {}) ⇒ Expected
constructor
A new instance of Expected.
- #matches?(actual_request) ⇒ Boolean
- #matches_route?(actual_request) ⇒ Boolean
Methods inherited from Base
#as_json, #full_path, #method_and_path, #to_hash, #to_json
Methods included from Matchers
#actual_array_diff, #actual_hash_diff, #array_diff, #check_for_unexpected_keys, #class_diff, #classes_match?, #diff, #hash_diff, #object_diff, #regexp_diff, #structure_diff, #structure_diff_actual_display, #structure_diff_expected_display
Methods included from SymbolizeKeys
Constructor Details
#initialize(method, path, headers, body, query, options = {}) ⇒ Expected
Returns a new instance of Expected.
24 25 26 27 |
# File 'lib/pact/consumer_contract/request.rb', line 24 def initialize(method, path, headers, body, query, = {}) super(method, path, headers, body, query) @options = end |
Instance Attribute Details
#options ⇒ Object
Temporary hack
11 12 13 |
# File 'lib/pact/consumer_contract/request.rb', line 11 def @options end |
Class Method Details
.from_hash(hash) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pact/consumer_contract/request.rb', line 13 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, {}) new(method, path, headers, body, query, ) end |
Instance Method Details
#difference(actual_request) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/pact/consumer_contract/request.rb', line 37 def difference(actual_request) request_diff = diff(to_hash_without_body, actual_request.to_hash_without_body) unless body.is_a? NullExpectation request_diff.merge(body_difference(actual_request.body)) else request_diff end 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 |
# File 'lib/pact/consumer_contract/request.rb', line 33 def matches_route? actual_request diff({:method => method, :path => path}, {:method => actual_request.method, :path => actual_request.path}).empty? end |