Sha256: 421e373b15c16044776573bdefb27689970709c5770e64c06f3573053f28ff70

Contents?: true

Size: 849 Bytes

Versions: 36

Compression:

Stored size: 849 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 specified? key
      self.key?(key.to_sym)
    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?
      !specified?(:body)
    end

  end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
pact-support-1.2.0 lib/pact/consumer_contract/response.rb
pact-support-1.1.8 lib/pact/consumer_contract/response.rb
pact-support-1.1.7 lib/pact/consumer_contract/response.rb
pact-support-1.1.6 lib/pact/consumer_contract/response.rb
pact-support-1.1.5 lib/pact/consumer_contract/response.rb
pact-support-1.1.4 lib/pact/consumer_contract/response.rb
pact-support-1.1.3 lib/pact/consumer_contract/response.rb
pact-support-1.1.2 lib/pact/consumer_contract/response.rb
pact-support-1.1.1 lib/pact/consumer_contract/response.rb
pact-support-1.1.0 lib/pact/consumer_contract/response.rb
pact-support-1.0.1 lib/pact/consumer_contract/response.rb
pact-support-1.0.0 lib/pact/consumer_contract/response.rb
pact-support-0.6.1 lib/pact/consumer_contract/response.rb
pact-support-0.6.0 lib/pact/consumer_contract/response.rb
pact-support-0.5.9 lib/pact/consumer_contract/response.rb
pact-support-0.5.8 lib/pact/consumer_contract/response.rb
pact-support-0.5.7 lib/pact/consumer_contract/response.rb
pact-support-0.5.5 lib/pact/consumer_contract/response.rb
pact-support-0.5.4 lib/pact/consumer_contract/response.rb
pact-support-0.5.3 lib/pact/consumer_contract/response.rb