lib/pact/shared/request.rb in pact-support-0.2.0 vs lib/pact/shared/request.rb in pact-support-0.2.1

- old
+ new

@@ -14,25 +14,24 @@ attr_reader :method, :path, :headers, :body, :query, :options def initialize(method, path, headers, body, query) @method = method.to_s - @path = path.chomp('/') + @path = path.respond_to?(:chomp) ? path.chomp('/') : path #TODO get rid of the chomp in v2 @headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant @body = body @query = is_unspecified?(query) ? query : Pact::Query.create(query) end def to_hash hash = { method: method, path: path, } - - hash.merge!(query: query) if specified?(:query) - hash.merge!(headers: headers) if specified?(:headers) - hash.merge!(body: body) if specified?(:body) + hash[:query] = query if specified?(:query) + hash[:headers] = headers if specified?(:headers) + hash[:body] = body if specified?(:body) hash end def method_and_path "#{method.upcase} #{full_path}" @@ -77,17 +76,20 @@ 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] - to_hash.reject{ |key, value| !keep_keys.include? key }.tap do | hash | - hash[:method] = method.upcase - end + hash = { + method: method.upcase, + path: path + } + hash[:headers] = headers if specified?(:headers) + hash end def display_path - path.empty? ? "/" : path + reified_path = Pact::Reification.from_term(path) + reified_path.empty? ? "/" : reified_path end def display_query (query.nil? || query.empty?) ? '' : "?#{Pact::Reification.from_term(query)}" end \ No newline at end of file