class RSpec::Rails::Matchers::HaveHttpStatus::SymbolicStatus

@api private Provides an implementation for `have_http_status` matching against Rack symbol http status codes.

Not intended to be instantiated directly.

@example

expect(response).to have_http_status(:created)

@see RSpec::Rails::Matchers#have_http_status @see github.com/rack/rack/blob/master/lib/rack/utils.rb `Rack::Utils::SYMBOL_TO_STATUS_CODE`

Public Class Methods

new(status) click to toggle source
# File lib/rspec/rails/matchers/have_http_status.rb, line 130
def initialize(status)
  @expected_status = status
  @actual = nil
  @invalid_response = nil
  set_expected_code!
end

Public Instance Methods

description() click to toggle source

@return [String]

# File lib/rspec/rails/matchers/have_http_status.rb, line 150
def description
  "respond with status code #{pp_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 155
def failure_message
  invalid_response_type_message ||
  "expected the response to have status code #{pp_expected} but it"                " was #{pp_actual}"
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 162
def failure_message_when_negated
  invalid_response_type_message ||
  "expected the response not to have status code #{pp_expected} "                "but it did"
end
matches?(response) click to toggle source

@param [Object] response object providing an http code to match @return [Boolean] `true` if Rack’s associated numeric HTTP code matched

the `response` code
# File lib/rspec/rails/matchers/have_http_status.rb, line 140
def matches?(response)
  test_response = as_test_response(response)
  @actual = test_response.response_code
  expected == @actual
rescue TypeError => _ignored
  @invalid_response = response
  false
end