Class: Crspec::Matchers::HaveHttpStatusMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Crspec::Matchers::HaveHttpStatusMatcher
- Defined in:
- lib/crspec/matchers.rb
Constant Summary collapse
- STATUS_GROUPS =
{ success: 200..299, successful: 200..299, redirect: 300..399, error: 500..599, server_error: 500..599, client_error: 400..499, missing: [404] }.freeze
- FALLBACK_CODES =
{ ok: 200, created: 201, accepted: 202, no_content: 204, moved_permanently: 301, found: 302, see_other: 303, not_modified: 304, bad_request: 400, unauthorized: 401, forbidden: 403, not_found: 404, method_not_allowed: 405, not_acceptable: 406, conflict: 409, gone: 410, unprocessable_entity: 422, unprocessable_content: 422, too_many_requests: 429, internal_server_error: 500, not_implemented: 501, bad_gateway: 502, service_unavailable: 503 }.freeze
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected) ⇒ HaveHttpStatusMatcher
constructor
A new instance of HaveHttpStatusMatcher.
- #matches?(actual) ⇒ Boolean
Methods inherited from BaseMatcher
Constructor Details
#initialize(expected) ⇒ HaveHttpStatusMatcher
Returns a new instance of HaveHttpStatusMatcher.
360 361 362 |
# File 'lib/crspec/matchers.rb', line 360 def initialize(expected) super(expected) end |
Instance Method Details
#failure_message ⇒ Object
370 371 372 |
# File 'lib/crspec/matchers.rb', line 370 def "Expected response to have HTTP status #{@expected.inspect}, got #{@actual_status.inspect}" end |
#failure_message_when_negated ⇒ Object
374 375 376 |
# File 'lib/crspec/matchers.rb', line 374 def "Expected response not to have HTTP status #{@expected.inspect}, but it did (#{@actual_status.inspect})" end |
#matches?(actual) ⇒ Boolean
364 365 366 367 368 |
# File 'lib/crspec/matchers.rb', line 364 def matches?(actual) @actual = actual @actual_status = actual.respond_to?(:status) ? actual.status : actual expected_codes.include?(@actual_status) end |