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

@see github.com/rack/rack/blob/master/lib/rack/utils.rb ‘Rack::Utils::SYMBOL_TO_STATUS_CODE`
@see RSpec::Rails::Matchers#have_http_status
expect(response).to have_http_status(:created)
@example
Not intended to be instantiated directly.
Rack symbol http status codes.
Provides an implementation for `have_http_status` matching against
@api private

def actual_status

Returns:
  • (Symbol) - representing the actual http numeric code
def actual_status
  return unless actual
  @actual_status ||= compute_status_from(actual)
end

def compute_status_from(code)

Returns:
  • (Symbol) - representing the http numeric code

Parameters:
  • code (Fixnum) -- http status code to look up
def compute_status_from(code)
  status, _ = Rack::Utils::SYMBOL_TO_STATUS_CODE.find do |_, c|
    c == code
  end
  status
end

def description

Returns:
  • (String) -
def description
  "respond with status code #{pp_expected}"
end

def failure_message

Returns:
  • (String) - explaining why the match failed
def failure_message
  invalid_response_type_message ||
  "expected the response to have status code #{pp_expected} but it" \
    " was #{pp_actual}"
end

def failure_message_when_negated

Returns:
  • (String) - explaining why the match failed
def failure_message_when_negated
  invalid_response_type_message ||
  "expected the response not to have status code #{pp_expected} " \
    "but it did"
end

def initialize(status)

def initialize(status)
  @expected_status = status
  @actual = nil
  @invalid_response = nil
  set_expected_code!
end

def matches?(response)

Returns:
  • (Boolean) - `true` if Rack's associated numeric HTTP code matched

Parameters:
  • response (Object) -- object providing an http code to match
def matches?(response)
  test_response = as_test_response(response)
  @actual = test_response.response_code
  expected == @actual
rescue TypeError => _ignored
  @invalid_response = response
  false
end

def pp_actual

Returns:
  • (String) - pretty format the actual response status
def pp_actual
  pp_status(actual_status, actual)
end

def pp_expected

Returns:
  • (String) - pretty format the expected status and associated code
def pp_expected
  pp_status(expected_status, expected)
end

def pp_status(status, code)

Returns:
  • (String) - pretty format the actual response status
def pp_status(status, code)
  if status
    "#{status.inspect} (#{code})"
  else
    code.to_s
  end
end

def set_expected_code!

Raises:
  • (ArgumentError) - if an associated code could not be found

Other tags:
    See: Rack::Utils::SYMBOL_TO_STATUS_CODE -
def set_expected_code!
  @expected ||=
    Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(expected_status) do
      raise ArgumentError,
            "Invalid HTTP status: #{expected_status.inspect}"
    end
end