module SharkOnLambda::RSpec::RequestHelpers

Constants

SUPPORTED_HTTP_METHODS

Attributes

app[W]

Public Instance Methods

app() click to toggle source
# File lib/shark_on_lambda/rspec/request_helpers.rb, line 18
def app
  @app ||= SharkOnLambda.application
end
response() click to toggle source
# File lib/shark_on_lambda/rspec/request_helpers.rb, line 22
def response
  if @response.nil?
    raise 'You must make a request before you can request a response.'
  end

  @response
end

Private Instance Methods

build_env(method, action, **options) click to toggle source
# File lib/shark_on_lambda/rspec/request_helpers.rb, line 32
def build_env(method, action, **options)
  headers = options.fetch(:headers, {})
  env_builder = EnvBuilder.new(
    method: method,
    controller: described_class,
    action: action,
    headers: normalized_headers(headers),
    params: options.fetch(:params, {})
  )
  env_builder.build
end
default_content_type() click to toggle source
# File lib/shark_on_lambda/rspec/request_helpers.rb, line 44
def default_content_type
  'application/vnd.api+json'
end
make_request(method, action, **options) click to toggle source
# File lib/shark_on_lambda/rspec/request_helpers.rb, line 48
def make_request(method, action, **options)
  env = build_env(method, action, **options)

  status, headers, body = app.call(env)
  errors = env['rack.errors']
  @response = Rack::MockResponse.new(status, headers, body, errors)
end
normalized_headers(headers) click to toggle source
# File lib/shark_on_lambda/rspec/request_helpers.rb, line 56
def normalized_headers(headers)
  headers.transform_keys! { |key| key.to_s.downcase }
  headers['content-type'] ||= default_content_type
  headers
end