Class: RSpec::Rails::Matchers::HaveHttpStatus::GenericStatus Private
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Rails::Matchers::HaveHttpStatus::GenericStatus
- Includes:
- RSpec::Rails::Matchers::HaveHttpStatus
- Defined in:
- lib/rspec/rails/matchers/have_http_status.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides an implementation for have_http_status
matching against
ActionDispatch::TestResponse
http status category queries.
Not intended to be instantiated directly.
Constant Summary
Constants inherited from BaseMatcher
Class Method Summary collapse
-
.valid_statuses ⇒ Array<Symbol>
private
Of status codes which represent a HTTP status code "group".
Instance Method Summary collapse
- #description ⇒ String private
-
#failure_message ⇒ String
private
Explaining why the match failed.
-
#failure_message_when_negated ⇒ String
private
Explaining why the match failed.
-
#initialize(type) ⇒ GenericStatus
constructor
private
A new instance of GenericStatus.
-
#matches?(response) ⇒ Boolean
private
true
if Rack's associated numeric HTTP code matched theresponse
code or the named response status.
Methods included from RSpec::Rails::Matchers::HaveHttpStatus
as_test_response, #invalid_response_type_message, matcher_for_status
Methods inherited from BaseMatcher
#diffable?, #expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?
Constructor Details
#initialize(type) ⇒ GenericStatus
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 new instance of GenericStatus.
251 252 253 254 255 256 257 258 259 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 251 def initialize(type) unless self.class.valid_statuses.include?(type) raise ArgumentError, "Invalid generic HTTP status: #{type.inspect}" end @expected = type @actual = nil @invalid_response = nil end |
Class Method Details
.valid_statuses ⇒ Array<Symbol>
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 of status codes which represent a HTTP status code "group".
243 244 245 246 247 248 249 |
# File '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
#description ⇒ 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.
273 274 275 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 273 def description "respond with #{}" end |
#failure_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 explaining why the match failed.
278 279 280 281 |
# File '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
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 explaining why the match failed.
284 285 286 287 |
# File '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
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 true
if Rack's associated numeric HTTP code matched
the response
code or the named response status.
263 264 265 266 267 268 269 270 |
# File '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 |