Class: JsonWrapperResponse

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/wd_sinatra/test_helpers.rb

Overview

Wrapper around a rest response

Instance Attribute Summary collapse

Instance Method Summary collapse

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_responseObject (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

#uriObject (readonly)

Returns the value of attribute uri.



164
165
166
# File 'lib/wd_sinatra/test_helpers.rb', line 164

def uri
  @uri
end

#verbObject (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

#bodyObject



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

Returns:

  • (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

Returns:

  • (Boolean)


176
177
178
# File 'lib/wd_sinatra/test_helpers.rb', line 176

def success?
  @rest_response.status == 200
end