Class: RSpec::Rails::Matchers::HaveHttpStatus::NumericCode Private
- Inherits:
-
Matchers::BuiltIn::BaseMatcher
- Object
- Matchers::BuiltIn::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.
Instance Method Summary (collapse)
- - (String) description private
-
- (String) failure_message
private
Explaining why the match failed.
-
- (String) failure_message_when_negated
private
Explaining why the match failed.
-
- (NumericCode) initialize(code)
constructor
private
A new instance of NumericCode.
-
- (Boolean) matches?(response)
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
Constructor Details
- (NumericCode) initialize(code)
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
76 77 78 79 80 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 76 def initialize(code) @expected = code.to_i @actual = nil @invalid_response = nil end |
Instance Method Details
- (String) description
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.
94 95 96 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 94 def description "respond with numeric status code #{expected}" end |
- (String) failure_message
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
99 100 101 102 103 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 99 def || "expected the response to have status code #{expected.inspect}" \ " but it was #{actual.inspect}" end |
- (String) failure_message_when_negated
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
106 107 108 109 110 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 106 def || "expected the response not to have status code " \ "#{expected.inspect} but it did" end |
- (Boolean) matches?(response)
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
84 85 86 87 88 89 90 91 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 84 def matches?(response) test_response = as_test_response(response) @actual = test_response.response_code expected == @actual rescue TypeError => _ignored @invalid_response = response false end |