Class: OpenapiRuby::Testing::Transport::RackTest

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_ruby/testing/transport.rb

Constant Summary collapse

UNPREFIXED_HEADERS =

Rack keeps these two out of the HTTP_ namespace.

{
  "content-type" => "CONTENT_TYPE",
  "content-length" => "CONTENT_LENGTH"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ RackTest

Returns a new instance of RackTest.



74
75
76
# File 'lib/openapi_ruby/testing/transport.rb', line 74

def initialize(context)
  @context = context
end

Instance Method Details

#dispatch(method, path, params: nil, headers: nil) ⇒ Object

rack-test treats a String params as the request body and a Hash as form/query data, which is the same split the adapters already make.



80
81
82
# File 'lib/openapi_ruby/testing/transport.rb', line 80

def dispatch(method, path, params: nil, headers: nil)
  @context.send(method.to_sym, path, params || {}, rack_env(headers || {}))
end

#responseObject



84
85
86
# File 'lib/openapi_ruby/testing/transport.rb', line 84

def response
  @context.last_response
end