Class: JsonWrapperResponse
- Inherits:
-
Object
- Object
- JsonWrapperResponse
- Extended by:
- Forwardable
- Defined in:
- lib/wd_sinatra/test_helpers.rb
Overview
Wrapper around a rest response
Instance Attribute Summary collapse
-
#rest_response ⇒ Object
readonly
Returns the value of attribute rest_response.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #[](val) ⇒ Object
- #body ⇒ Object
-
#initialize(response, opts = {}) ⇒ JsonWrapperResponse
constructor
A new instance of JsonWrapperResponse.
- #method_missing(meth, *args) ⇒ Object
- #redirected? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(response, opts = {}) ⇒ JsonWrapperResponse
Returns a new instance of JsonWrapperResponse.
149 150 151 152 153 |
# File 'lib/wd_sinatra/test_helpers.rb', line 149 def initialize(response, opts={}) @rest_response = response @verb = opts[:verb] @uri = opts[:uri] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
175 176 177 |
# File 'lib/wd_sinatra/test_helpers.rb', line 175 def method_missing(meth, *args) body.send(meth, args) end |
Instance Attribute Details
#rest_response ⇒ Object (readonly)
Returns the value of attribute rest_response.
145 146 147 |
# File 'lib/wd_sinatra/test_helpers.rb', line 145 def rest_response @rest_response end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
147 148 149 |
# File 'lib/wd_sinatra/test_helpers.rb', line 147 def uri @uri end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
146 147 148 |
# File 'lib/wd_sinatra/test_helpers.rb', line 146 def verb @verb end |
Instance Method Details
#[](val) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/wd_sinatra/test_helpers.rb', line 167 def [](val) if body body[val.to_s] else nil end end |
#body ⇒ Object
155 156 157 |
# File 'lib/wd_sinatra/test_helpers.rb', line 155 def body @body ||= JSON.load(rest_response.body) rescue rest_response.body end |
#redirected? ⇒ Boolean
163 164 165 |
# File 'lib/wd_sinatra/test_helpers.rb', line 163 def redirected? @rest_response.status.to_s =~ /30\d/ end |
#success? ⇒ Boolean
159 160 161 |
# File 'lib/wd_sinatra/test_helpers.rb', line 159 def success? @rest_response.status == 200 end |