Class: Crspec::Rails::RequestHelpers::ResponseStruct
- Inherits:
-
Struct
- Object
- Struct
- Crspec::Rails::RequestHelpers::ResponseStruct
- Defined in:
- lib/crspec/rails/request_helpers.rb
Overview
Lightweight response wrapper that mimics the small subset of the Rails test response API that the specs rely on (status, body, headers, media_type, parsed_body, etc.).
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
24 25 26 |
# File 'lib/crspec/rails/request_helpers.rb', line 24 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
24 25 26 |
# File 'lib/crspec/rails/request_helpers.rb', line 24 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status
24 25 26 |
# File 'lib/crspec/rails/request_helpers.rb', line 24 def status @status end |
Instance Method Details
#media_type ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/crspec/rails/request_helpers.rb', line 25 def media_type content_type_header = headers["Content-Type"] || headers["content-type"] return nil unless content_type_header # Strip any charset or parameters, e.g. "application/json; charset=utf-8" content_type_header.split(";").first&.strip end |
#parsed_body ⇒ Object
33 34 35 36 37 38 |
# File 'lib/crspec/rails/request_helpers.rb', line 33 def parsed_body return nil unless body JSON.parse(body) rescue JSON::ParserError nil end |