Module: Syntropy::TestRequestExtensions

Included in:
Request
Defined in:
lib/syntropy/test.rb

Overview

Extensions to Syntropy::Request for testing.

Instance Method Summary collapse

Instance Method Details

#response_bodyString?

Returns the response body

Returns:

  • (String, nil)


202
203
204
# File 'lib/syntropy/test.rb', line 202

def response_body
  adapter.response_body
end

#response_content_typeString?

Returns the response content MIME type.

Returns:

  • (String, nil)


217
218
219
220
221
222
223
224
225
# File 'lib/syntropy/test.rb', line 217

def response_content_type
  ct = response_headers['Content-Type']
  return nil if !ct

  m = ct.match(/^([^;]+)/)
  return nil if !m

  m[1]
end

Returns the cookie value for the given cookie name from the response.

Parameters:

  • name (String, Symbol)

    cookie name

Returns:

  • (String, nil)

    cookie value



231
232
233
234
235
236
237
238
239
# File 'lib/syntropy/test.rb', line 231

def response_cookie(name)
  sc = response_headers['Set-Cookie']
  return nil if !sc

  m = sc.match(/#{name}=([^\s]+)$/)
  return nil if !m

  m[1]
end

#response_headersHash

Returns the response headers.

Returns:

  • (Hash)


188
189
190
# File 'lib/syntropy/test.rb', line 188

def response_headers
  adapter.response_headers
end

#response_jsonany

Parses the response body from JSON.

Returns:

  • (any)

    parsed JSON object



209
210
211
212
# File 'lib/syntropy/test.rb', line 209

def response_json
  raise if response_content_type != 'application/json'
  JSON.parse(response_body)
end

#response_statusInteger

Returns the response status

Returns:

  • (Integer)


195
196
197
# File 'lib/syntropy/test.rb', line 195

def response_status
  adapter.status
end