Class: RSpec::Rails::Matchers::HaveHttpStatus::SymbolicStatus Private

Inherits:
BaseMatcher
  • Object
show all
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 Rack symbol http status codes.

Not intended to be instantiated directly.

Examples:

expect(response).to have_http_status(:created)

See Also:

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

Instance Method Summary collapse

Methods included from RSpec::Rails::Matchers::HaveHttpStatus

as_test_response, #invalid_response_type_message, matcher_for_status

Methods inherited from BaseMatcher

#diffable?, #expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?

Constructor Details

#initialize(status) ⇒ SymbolicStatus

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 SymbolicStatus.

131
132
133
134
135
136
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 131
def initialize(status)
  @expected_status = status
  @actual = nil
  @invalid_response = nil
  set_expected_code!
end

Instance Method Details

#descriptionString

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:

  • (String)
151
152
153
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 151
def description
  "respond with status code #{pp_expected}"
end

#failure_messageString

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.

Returns:

  • (String)

    explaining why the match failed

156
157
158
159
160
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 156
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_negatedString

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.

Returns:

  • (String)

    explaining why the match failed

163
164
165
166
167
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 163
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) ⇒ Boolean

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 Rack's associated numeric HTTP code matched the response code.

Parameters:

  • response (Object)

    object providing an http code to match

Returns:

  • (Boolean)

    true if Rack's associated numeric HTTP code matched the response code

141
142
143
144
145
146
147
148
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 141
def matches?(response)
  test_response = as_test_response(response)
  @actual = test_response.response_code
  expected == @actual
rescue TypeError => _ignored
  @invalid_response = response
  false
end