123456789_123456789_123456789_123456789_123456789_

Module: RSpec::Rails::Matchers::HaveHttpStatus Private

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: rspec-rails/lib/rspec/rails/matchers/have_http_status.rb

Overview

Namespace for various implementations of ‘have_http_status`.

Class Method Summary

Instance Method Summary

Class Method Details

.as_test_response(obj) ⇒ ActionDispatch::TestResponse (mod_func)

Conversion function to coerce the provided object into an ‘ActionDispatch::TestResponse`.

Parameters:

  • obj (Object)

    object to convert to a response

[ GitHub ]

  
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 35

def as_test_response(obj)
  if ::ActionDispatch::Response === obj
    ::ActionDispatch::TestResponse.from_response(obj)
  elsif ::ActionDispatch::TestResponse === obj
    obj
  elsif obj.respond_to?(:status_code) && obj.respond_to?(:response_headers)
    # Acts As Capybara Session
    # Hack to support `Capybara::Session` without having to load
    # Capybara or catch `NameError`s for the undefined constants
    obj = ActionDispatch::Response.new.tap do |resp|
      resp.status  = obj.status_code
      resp.headers.clear
      resp.headers.merge!(obj.response_headers)
      resp.body    = obj.body
      resp.request = ActionDispatch::Request.new({})
    end
    ::ActionDispatch::TestResponse.from_response(obj)
  else
    raise TypeError, "Invalid response type: #{obj}"
  end
end

.matcher_for_status(target) ⇒ Object

Instantiates an instance of the proper matcher based on the provided ‘target`.

Parameters:

  • target (Object)

    expected http status or code

Returns:

  • response matcher instance

[ GitHub ]

  
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 19

def self.matcher_for_status(target)
  if GenericStatus.valid_statuses.include?(target)
    GenericStatus.new(target)
  elsif Symbol === target
    SymbolicStatus.new(target)
  else
    NumericCode.new(target)
  end
end

Instance Method Details

#invalid_response_type_messageString?

Returns:

  • (String, nil)

    a formatted failure message if ‘@invalid_response` is present, nil otherwise

[ GitHub ]

  
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 60

def invalid_response_type_message
  return unless @invalid_response

  "expected a response object, but an instance of " \
  "#{@invalid_response.class} was received"
end