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.
166 167 168 169 170 |
# File 'lib/wd_sinatra/test_helpers.rb', line 166 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
192 193 194 |
# File 'lib/wd_sinatra/test_helpers.rb', line 192 def method_missing(meth, *args) body.send(meth, args) end |
Instance Attribute Details
#rest_response ⇒ Object (readonly)
Returns the value of attribute rest_response.
162 163 164 |
# File 'lib/wd_sinatra/test_helpers.rb', line 162 def rest_response @rest_response end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
164 165 166 |
# File 'lib/wd_sinatra/test_helpers.rb', line 164 def uri @uri end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
163 164 165 |
# File 'lib/wd_sinatra/test_helpers.rb', line 163 def verb @verb end |
Instance Method Details
#[](val) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/wd_sinatra/test_helpers.rb', line 184 def [](val) if body body[val.to_s] else nil end end |
#body ⇒ Object
172 173 174 |
# File 'lib/wd_sinatra/test_helpers.rb', line 172 def body @body ||= JSON.load(rest_response.body) rescue rest_response.body end |
#redirected? ⇒ Boolean
180 181 182 |
# File 'lib/wd_sinatra/test_helpers.rb', line 180 def redirected? @rest_response.status.to_s =~ /30\d/ end |
#success? ⇒ Boolean
176 177 178 |
# File 'lib/wd_sinatra/test_helpers.rb', line 176 def success? @rest_response.status == 200 end |