Class: RSpec::Rails::Matchers::HaveHttpStatus::NumericCode Private
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Rails::Matchers::HaveHttpStatus::NumericCode
- 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
numeric http status codes.
Not intended to be instantiated directly.
Constant Summary
Constants inherited from BaseMatcher
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(code) ⇒ NumericCode
constructor
private
A new instance of NumericCode.
-
#matches?(response) ⇒ Boolean
private
true
if the numeric code matched theresponse
code.
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(code) ⇒ NumericCode
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 NumericCode.
80 81 82 83 84 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 80 def initialize(code) @expected = code.to_i @actual = nil @invalid_response = nil 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.
98 99 100 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 98 def description "respond with numeric status code #{expected}" 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.
103 104 105 106 107 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 103 def || "expected the response to have status code #{expected.inspect}" \ " but it was #{actual.inspect}" 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.
110 111 112 113 114 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 110 def || "expected the response not to have status code " \ "#{expected.inspect} but it did" 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 the numeric code matched the response
code.
88 89 90 91 92 93 94 95 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 88 def matches?(response) test_response = as_test_response(response) @actual = test_response.response_code.to_i expected == @actual rescue TypeError => _ignored @invalid_response = response false end |