Class: Contracts::InstantiatedContract

Inherits:
Object
  • Object
show all
Defined in:
lib/contracts/instantiated_contract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ InstantiatedContract

Returns a new instance of InstantiatedContract.



6
7
8
9
10
# File 'lib/contracts/instantiated_contract.rb', line 6

def initialize(request, response)
  @request = request
  @response = response
  @response_body = response.body
end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



3
4
5
# File 'lib/contracts/instantiated_contract.rb', line 3

def request
  @request
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



4
5
6
# File 'lib/contracts/instantiated_contract.rb', line 4

def response_body
  @response_body
end

Instance Method Details

#replace!(values) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/contracts/instantiated_contract.rb', line 20

def replace!(values)
  if @response_body.respond_to?(:normalize_keys)
    @response_body = @response_body.normalize_keys.deep_merge(values.normalize_keys)
  else
    @response_body = values
  end
end

#request_pathObject



12
13
14
# File 'lib/contracts/instantiated_contract.rb', line 12

def request_path
  @request.absolute_uri
end

#request_uriObject



16
17
18
# File 'lib/contracts/instantiated_contract.rb', line 16

def request_uri
  @request.full_uri
end

#stub!Object



28
29
30
31
32
33
34
35
36
# File 'lib/contracts/instantiated_contract.rb', line 28

def stub!
  WebMock.stub_request(@request.method, "#{@request.host}#{@request.path}").
    with(request_details).
    to_return({
      :status => @response.status,
      :headers => @response.headers,
      :body => format_body(@response_body)
    })
end