@api private Provides an implementation for `have_http_status` matching against `ActionDispatch::TestResponse` http status category queries.
Not intended to be instantiated directly.
@example
expect(response).to have_http_status(:success) expect(response).to have_http_status(:error) expect(response).to have_http_status(:missing) expect(response).to have_http_status(:redirect)
@see RSpec::Rails::Matchers#have_http_status @see ActionDispatch::TestResponse
@return [String]
# File lib/rspec/rails/matchers/have_http_status.rb, line 270 def description "respond with #{type_message}" end
@return [String] explaining why the match failed
# File lib/rspec/rails/matchers/have_http_status.rb, line 275 def failure_message invalid_response_type_message || "expected the response to have #{type_message} but it was #{actual}" end
@return [String] explaining why the match failed
# File lib/rspec/rails/matchers/have_http_status.rb, line 281 def failure_message_when_negated invalid_response_type_message || "expected the response not to have #{type_message} but it was #{actual}" end
@return [Boolean] `true` if Rack’s associated numeric HTTP code matched
the `response` code
# File lib/rspec/rails/matchers/have_http_status.rb, line 260 def matches?(response) test_response = as_test_response(response) @actual = test_response.response_code test_response.send("#{expected}?") rescue TypeError => _ignored @invalid_response = response false end
# File lib/rspec/rails/matchers/have_http_status.rb, line 249 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
@return [Array<Symbol>] of status codes which represent a HTTP status
code "group"
@see github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
# File lib/rspec/rails/matchers/have_http_status.rb, line 245 def self.valid_statuses [:error, :success, :missing, :redirect] end