Class: Pact::Response

Inherits:
Hash
  • Object
show all
Includes:
SymbolizeKeys
Defined in:
lib/pact/consumer_contract/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SymbolizeKeys

included, #symbolize_keys

Constructor Details

#initialize(attributes) ⇒ Response

Returns a new instance of Response.



13
14
15
# File 'lib/pact/consumer_contract/response.rb', line 13

def initialize attributes
  merge!(attributes.reject{|key, value| !ALLOWED_KEYS.include?(key)})
end

Class Method Details

.from_hash(hash) ⇒ Object



41
42
43
44
# File 'lib/pact/consumer_contract/response.rb', line 41

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

Instance Method Details

#[](key) ⇒ Object



37
38
39
# File 'lib/pact/consumer_contract/response.rb', line 37

def [] key
  super key.to_sym
end

#bodyObject



25
26
27
# File 'lib/pact/consumer_contract/response.rb', line 25

def body
  self[:body]
end

#body_allows_any_value?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/pact/consumer_contract/response.rb', line 33

def body_allows_any_value?
  body_not_specified? || body_is_empty_hash?
end

#headersObject



21
22
23
# File 'lib/pact/consumer_contract/response.rb', line 21

def headers
  self[:headers]
end

#specified?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/pact/consumer_contract/response.rb', line 29

def specified? key
  self.key?(key.to_sym)
end

#statusObject



17
18
19
# File 'lib/pact/consumer_contract/response.rb', line 17

def status
  self[:status]
end