class RSpec::Rails::Matchers::HaveHttpStatus::NumericCode
@api private Provides an implementation for `have_http_status` matching against numeric http status codes.
Not intended to be instantiated directly.
@example
expect(response).to have_http_status(404)
Public Class Methods
new(code)
click to toggle source
# File lib/rspec/rails/matchers/have_http_status.rb, line 79 def initialize(code) @expected = code.to_i @actual = nil @invalid_response = nil end
Public Instance Methods
description()
click to toggle source
@return [String]
# File lib/rspec/rails/matchers/have_http_status.rb, line 97 def description "respond with numeric status code #{expected}" end
failure_message()
click to toggle source
@return [String] explaining why the match failed
# File lib/rspec/rails/matchers/have_http_status.rb, line 102 def failure_message invalid_response_type_message || "expected the response to have status code #{expected.inspect}" \ " but it was #{actual.inspect}" end
failure_message_when_negated()
click to toggle source
@return [String] explaining why the match failed
# File lib/rspec/rails/matchers/have_http_status.rb, line 109 def failure_message_when_negated invalid_response_type_message || "expected the response not to have status code " \ "#{expected.inspect} but it did" end
matches?(response)
click to toggle source
@param [Object] response object providing an http code to match @return [Boolean] `true` if the numeric code matched the `response` code
# File lib/rspec/rails/matchers/have_http_status.rb, line 87 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