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.



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

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



167
168
169
# File 'lib/restclient/components.rb', line 167

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



167
168
169
# File 'lib/restclient/components.rb', line 167

def header
  @header
end

#statusObject (readonly) Also known as: code

Returns the value of attribute status.



167
168
169
# File 'lib/restclient/components.rb', line 167

def status
  @status
end

Instance Method Details

#to_hashObject



176
177
178
179
180
181
182
# File 'lib/restclient/components.rb', line 176

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