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
-
.matcher_for_status(target) ⇒ Object
Internal use only
Instantiates an instance of the proper matcher based on the provided
target
. -
.as_test_response(obj) ⇒ ActionDispatch::TestResponse
Internal use only
mod_func
Conversion function to coerce the provided object into an
ActionDispatch::TestResponse
.
Instance Method Summary
- #invalid_response_type_message ⇒ String? Internal use only
Class Method Details
.as_test_response(obj) ⇒ ActionDispatch::TestResponse
(mod_func)
Conversion function to coerce the provided object into an ActionDispatch::TestResponse
.
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 35
def as_test_response(obj) if ::ActionDispatch::Response === obj || ::Rack::MockResponse === 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
.
# 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_message ⇒ String
?
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 60
def return unless @invalid_response "expected a response object, but an instance of " \ "#{@invalid_response.class} was received" end