Class: Tina4::TestResponse
- Inherits:
-
Object
- Object
- Tina4::TestResponse
- Defined in:
- lib/tina4/test_client.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(rack_response) ⇒ TestResponse
constructor
Build from a Rack response tuple [status, headers, body_array].
- #inspect ⇒ Object
-
#json ⇒ Object
Parse body as JSON.
-
#text ⇒ Object
Return body as a string.
Constructor Details
#initialize(rack_response) ⇒ TestResponse
Build from a Rack response tuple [status, headers, body_array]
23 24 25 26 27 28 29 |
# File 'lib/tina4/test_client.rb', line 23 def initialize(rack_response) @status = rack_response[0] @headers = rack_response[1] || {} @content_type = @headers["content-type"] || "" raw_body = rack_response[2] @body = raw_body.is_a?(Array) ? raw_body.join : raw_body.to_s end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
20 21 22 |
# File 'lib/tina4/test_client.rb', line 20 def body @body end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
20 21 22 |
# File 'lib/tina4/test_client.rb', line 20 def content_type @content_type end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
20 21 22 |
# File 'lib/tina4/test_client.rb', line 20 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
20 21 22 |
# File 'lib/tina4/test_client.rb', line 20 def status @status end |
Instance Method Details
#inspect ⇒ Object
44 45 46 |
# File 'lib/tina4/test_client.rb', line 44 def inspect "<TestResponse status=#{@status} content_type=#{@content_type.inspect}>" end |
#json ⇒ Object
Parse body as JSON.
32 33 34 35 36 37 |
# File 'lib/tina4/test_client.rb', line 32 def json return nil if @body.nil? || @body.empty? JSON.parse(@body) rescue JSON::ParserError nil end |
#text ⇒ Object
Return body as a string.
40 41 42 |
# File 'lib/tina4/test_client.rb', line 40 def text @body.to_s end |