Class: RestClient::MockNetHTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/restclient/components.rb

Overview

A class that mocks the behaviour of a Net::HTTPResponse class. It is required since RestClient::Response must be initialized with a class that responds to :code and :to_hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, status, header) ⇒ MockNetHTTPResponse

Returns a new instance of MockNetHTTPResponse.



173
174
175
176
177
# File 'lib/restclient/components.rb', line 173

def initialize(body, status, header)
  @body = body
  @status = status
  @header = header
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



170
171
172
# File 'lib/restclient/components.rb', line 170

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



170
171
172
# File 'lib/restclient/components.rb', line 170

def header
  @header
end

#statusObject (readonly) Also known as: code

Returns the value of attribute status.



170
171
172
# File 'lib/restclient/components.rb', line 170

def status
  @status
end

Instance Method Details

#to_hashObject



179
180
181
182
183
184
185
# File 'lib/restclient/components.rb', line 179

def to_hash
  @header.inject({}) {|out, (key, value)|
    # In Net::HTTP, header values are arrays
    out[key] = [value]
    out
  }
end