lib/pact/shared/request.rb in pact-support-0.0.1 vs lib/pact/shared/request.rb in pact-support-0.0.2

- old
+ new

@@ -1,8 +1,9 @@ require 'pact/matchers' require 'pact/symbolize_keys' require 'pact/consumer_contract/headers' +require 'pact/consumer_contract/query_string' module Pact module Request @@ -16,11 +17,11 @@ def initialize(method, path, headers, body, query) @method = method.to_s @path = path.chomp('/') @headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant @body = body - @query = query + @query = is_unspecified?(query) ? query : Pact::QueryString.new(query) end def to_json(options = {}) as_json.to_json(options) end @@ -72,14 +73,18 @@ def body_specified? specified?(:body) end def specified? key - !(self.send(key).is_a? self.class.key_not_found.class) + !is_unspecified?(self.send(key)) end - def to_hash_without_body - keep_keys = [:method, :path, :headers, :query] + def is_unspecified? value + value.is_a? self.class.key_not_found.class + end + + def to_hash_without_body_or_query + keep_keys = [:method, :path, :headers] as_json.reject{ |key, value| !keep_keys.include? key }.tap do | hash | hash[:method] = method.upcase end end \ No newline at end of file