Sha256: 14a95336f06a4cb2b48e5d69de66b7f1a7d10dfdc59c2676ac1d7a8ef6cd925f

Contents?: true

Size: 788 Bytes

Versions: 4

Compression:

Stored size: 788 Bytes

Contents

require 'pact/consumer_contract/headers'
require 'pact/symbolize_keys'

module Pact

  class Response < Hash

    include SymbolizeKeys

    def initialize attributes
      merge!(attributes)
    end

    def status
      self[:status]
    end

    def headers
      self[:headers]
    end

    def body
      self[:body]
    end

    def body_allows_any_value?
      body_not_specified? || body_is_empty_hash?
    end

    def [] key
      super key.to_sym
    end

    def self.from_hash hash
      headers = Headers.new(hash[:headers] || hash['headers'] || {})
      new(symbolize_keys(hash).merge(headers: headers))
    end

    private

    def body_is_empty_hash?
      body.is_a?(Hash) && body.empty?
    end

    def body_not_specified?
      !self.key?(:body)
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact-support-0.0.4 lib/pact/consumer_contract/response.rb
pact-support-0.0.3 lib/pact/consumer_contract/response.rb
pact-support-0.0.2 lib/pact/consumer_contract/response.rb
pact-support-0.0.1 lib/pact/consumer_contract/response.rb