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]
21 22 23 24 25 26 27 |
# File 'lib/tina4/test_client.rb', line 21 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.
18 19 20 |
# File 'lib/tina4/test_client.rb', line 18 def body @body end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
18 19 20 |
# File 'lib/tina4/test_client.rb', line 18 def content_type @content_type end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
18 19 20 |
# File 'lib/tina4/test_client.rb', line 18 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
18 19 20 |
# File 'lib/tina4/test_client.rb', line 18 def status @status end |
Instance Method Details
#inspect ⇒ Object
42 43 44 |
# File 'lib/tina4/test_client.rb', line 42 def inspect "<TestResponse status=#{@status} content_type=#{@content_type.inspect}>" end |
#json ⇒ Object
Parse body as JSON.
30 31 32 33 34 35 |
# File 'lib/tina4/test_client.rb', line 30 def json return nil if @body.nil? || @body.empty? JSON.parse(@body) rescue JSON::ParserError nil end |
#text ⇒ Object
Return body as a string.
38 39 40 |
# File 'lib/tina4/test_client.rb', line 38 def text @body.to_s end |