Module: RSpec::Rails::Matchers::HaveHttpStatus Private
- Included in:
- GenericStatus, NumericCode, SymbolicStatus
- Defined in:
- lib/rspec/rails/matchers/have_http_status.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Namespace for various implementations of have_http_status
.
Defined Under Namespace
Classes: GenericStatus, NumericCode, SymbolicStatus
Class Method Summary collapse
-
.as_test_response(obj) ⇒ ActionDispatch::TestResponse
private
Conversion function to coerce the provided object into an
ActionDispatch::TestResponse
. -
.matcher_for_status(target) ⇒ Object
private
Instantiates an instance of the proper matcher based on the provided
target
.
Instance Method Summary collapse
-
#invalid_response_type_message ⇒ String?
private
A formatted failure message if
@invalid_response
is present,nil
otherwise.
Class Method Details
.as_test_response(obj) ⇒ ActionDispatch::TestResponse
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Conversion function to coerce the provided object into an
ActionDispatch::TestResponse
.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File '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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiates an instance of the proper matcher based on the provided
target
.
19 20 21 22 23 24 25 26 27 |
# File '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?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a formatted failure message if
@invalid_response
is present, nil
otherwise.
60 61 62 63 64 |
# File '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 |