Module: RailsStuff::TestHelpers::Response
- Defined in:
- lib/rails_stuff/test_helpers/response.rb
Class Method Summary collapse
-
.prepare_json_object(object) ⇒ Object
Return ‘Hashie::Mash` for a given object.
Instance Method Summary collapse
-
#inspect ⇒ Object
Makes it easier to debug failed specs.
-
#json_body ⇒ Object
Easy access to json bodies.
Class Method Details
.prepare_json_object(object) ⇒ Object
Return ‘Hashie::Mash` for a given object. When `Array` is given it is mapped to mash recursievly.
9 10 11 12 13 14 15 |
# File 'lib/rails_stuff/test_helpers/response.rb', line 9 def prepare_json_object(object) case object when Hash then Hashie::Mash.new(object) when Array then object.map(&method(__callee__)) else object end end |
Instance Method Details
#inspect ⇒ Object
Makes it easier to debug failed specs.
37 38 39 |
# File 'lib/rails_stuff/test_helpers/response.rb', line 37 def inspect "<Response(#{status})>" end |
#json_body ⇒ Object
Easy access to json bodies. It parses and return ‘Hashie::Mash`’es, so properties can be accessed via method calls:
response.json_body.order.items.id
# note that hash methods are still present:
response.json_body.order[:key] # instead of order.key
32 33 34 |
# File 'lib/rails_stuff/test_helpers/response.rb', line 32 def json_body @json_body ||= Response.prepare_json_object(JSON.parse(body)) end |