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.



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

#uriObject (readonly)

Returns the value of attribute uri.



147
148
149
# File 'lib/wd_sinatra/test_helpers.rb', line 147

def uri
  @uri
end

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

#bodyObject



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

Returns:

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

Returns:

  • (Boolean)


159
160
161
# File 'lib/wd_sinatra/test_helpers.rb', line 159

def success?
  @rest_response.status == 200
end