Class: RSpec::Rails::Matchers::HaveHttpStatus::GenericStatus Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Rails::Matchers::BaseMatcher
|
Defined in: | rspec-rails/lib/rspec/rails/matchers/have_http_status.rb |
Overview
Provides an implementation for RSpec::Rails::Matchers#have_http_status matching against ActionDispatch::TestResponse
http status category queries.
Not intended to be instantiated directly.
Constant Summary
-
RESPONSE_METHODS =
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 291{ success: 'successful', error: 'server_error', missing: 'not_found' }.freeze
::RSpec::Rails::Matchers::BaseMatcher
- Inherited
Class Method Summary
- .new(type) ⇒ GenericStatus constructor Internal use only
- .valid_statuses ⇒ Array<Symbol> Internal use only
::RSpec::Rails::Matchers::BaseMatcher
- Inherited
.matcher_name, .new, | |
.underscore | Borrowed from ActiveSupport. |
Instance Attribute Summary
::RSpec::Rails::Matchers::BaseMatcher
- Inherited
#actual, | |
#diffable? |
|
#expected, #expects_call_stack_jump?, #matcher_name, #matcher_name=, #rescued_exception, | |
#supports_block_expectations? | Most matchers are value matchers (i.e. meant to work with ‘expect(value)`) rather than block matchers (i.e. meant to work with `expect { }`), so this defaults to false. |
Instance Method Summary
- #description ⇒ String Internal use only
- #failure_message ⇒ String Internal use only
- #failure_message_when_negated ⇒ String Internal use only
- #matches?(response) ⇒ Boolean Internal use only
- #check_expected_status(test_response, expected) protected Internal use only
- #type_codes ⇒ String private Internal use only
- #type_message ⇒ String private Internal use only
::RSpec::Rails::Matchers::HaveHttpStatus
- Included
#invalid_response_type_message, | |
#as_test_response | Conversion function to coerce the provided object into an |
::RSpec::Rails::Matchers::BaseMatcher
- Inherited
#actual_formatted, | |
#description | Generates a description using |
#expected_formatted, | |
#match_unless_raises | Used to wrap a block of code that will indicate failure by raising one of the named exceptions. |
#matches? | Indicates if the match is successful. |
#assert_ivars, #present_ivars |
::RSpec::Rails::Matchers::BaseMatcher::DefaultFailureMessages
- Included
#failure_message | Provides a good generic failure message. |
#failure_message_when_negated | Provides a good generic negative failure message. |
::RSpec::Rails::Matchers::BaseMatcher::HashFormatting
- Included
#improve_hash_formatting | ‘{ |
::RSpec::Matchers::Composable
- Included
#& | Alias for Matchers::Composable#and. |
#=== | Delegates to #matches?. |
#and | Creates a compound |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound |
#values_match? | This provides a generic way to fuzzy-match an expected value against an actual value. |
#| | Alias for Matchers::Composable#or. |
#should_enumerate? | We should enumerate arrays as long as they are not recursive. |
#surface_descriptions_in | Transforms the given data structure (typically a hash or array) into a new data structure that, when |
#unreadable_io?, | |
#with_matchers_cloned | Historically, a single matcher instance was only checked against a single value. |
Class Method Details
.valid_statuses ⇒ Array
<Symbol
>
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 243
def self.valid_statuses [ :error, :success, :missing, :server_error, :successful, :not_found, :redirect ] end
Instance Method Details
#check_expected_status(test_response, expected) (protected)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 297
def check_expected_status(test_response, expected) test_response.send( "#{RESPONSE_METHODS.fetch(expected, expected)}?") end
#description ⇒ String
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 273
def description "respond with #{}" end
#failure_message ⇒ String
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 278
def || "expected the response to have #{} but it was #{actual}" end
#failure_message_when_negated ⇒ String
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 284
def || "expected the response not to have #{} but it was #{actual}" end
#matches?(response) ⇒ Boolean
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 263
def matches?(response) test_response = as_test_response(response) @actual = test_response.response_code check_expected_status(test_response, expected) rescue TypeError => _ignored @invalid_response = response false end
#type_codes ⇒ String
(private)
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 314
def type_codes # At the time of this commit the most recent version of # `ActionDispatch::TestResponse` defines the following aliases: # # alias_method :success?, :successful? # alias_method :missing?, :not_found? # alias_method :redirect?, :redirection? # alias_method :error?, :server_error? # # It's parent `ActionDispatch::Response` includes # `Rack::Response::Helpers` which defines the aliased methods as: # # def successful?; status >= 200 && status < 300; end # def redirection?; status >= 300 && status < 400; end # def server_error?; status >= 500 && status < 600; end # def not_found?; status == 404; end # # @see https://github.com/rails/rails/blob/ca200378/actionpack/lib/action_dispatch/testing/test_response.rb#L17-L27 # @see https://github.com/rails/rails/blob/ca200378/actionpack/lib/action_dispatch/http/response.rb#L74 # @see https://github.com/rack/rack/blob/ce4a3959/lib/rack/response.rb#L119-L122 @type_codes ||= case expected when :error, :server_error "5xx" when :success, :successful "2xx" when :missing, :not_found "404" when :redirect "3xx" end end
#type_message ⇒ String
(private)
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 305
def @type_message ||= (expected == :error ? "an error" : "a #{expected}") + " status code (#{type_codes})" end