Class: UmtsCustomMatchers::RedirectBack
- Inherits:
-
Object
- Object
- UmtsCustomMatchers::RedirectBack
- Defined in:
- lib/umts_custom_matchers/redirect_back.rb
Overview
Matcher for redirecting to “back”. Asserts that the HTTP response code is a redirect, and also that the ‘Location` matches the HTTP_REFERER of the request.
Constant Summary collapse
- MATCHER_MODULE =
RSpec::Rails::Matchers
- STATUS_CODE_MATCHER =
MATCHER_MODULE::HaveHttpStatus::GenericStatus
- REDIRECT_PATH_MATCHER =
MATCHER_MODULE::RedirectTo::RedirectTo
- ALLOWED_REQUEST_TYPES =
[ActionController::TestRequest].freeze
- ALLOWED_RESPONSE_TYPES =
[ActionDispatch::TestResponse].freeze
Instance Method Summary collapse
-
#failure_message ⇒ Object
:nodoc:.
-
#failure_message_when_negated ⇒ Object
:nodoc:.
-
#initialize(scope) ⇒ RedirectBack
constructor
A new instance of RedirectBack.
-
#matches?(code) ⇒ Boolean
Returns ‘true` if response is a `302`, and the location matches the `HTTP_REFERER` of the request.
-
#supports_block_expectations? ⇒ Boolean
:nodoc:.
Constructor Details
#initialize(scope) ⇒ RedirectBack
Returns a new instance of RedirectBack.
22 23 24 |
# File 'lib/umts_custom_matchers/redirect_back.rb', line 22 def initialize(scope) @scope = scope end |
Instance Method Details
#failure_message ⇒ Object
:nodoc:
56 57 58 |
# File 'lib/umts_custom_matchers/redirect_back.rb', line 56 def @message end |
#failure_message_when_negated ⇒ Object
:nodoc:
62 63 64 |
# File 'lib/umts_custom_matchers/redirect_back.rb', line 62 def 'expected response not to redirect back, but did' end |
#matches?(code) ⇒ Boolean
Returns ‘true` if response is a `302`, and the location matches the `HTTP_REFERER` of the request. `false` otherwise.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/umts_custom_matchers/redirect_back.rb', line 32 def matches?(code) path = 'http://test.host/redirect' status_matcher = STATUS_CODE_MATCHER.new :redirect path_matcher = REDIRECT_PATH_MATCHER.new @scope, path verify_spec_type or return false verify_request_type or return false verify_response_type or return false verify_input_type(code) or return false @scope.request.env['HTTP_REFERER'] ||= path code.call @response = @scope.response verify_status_code(status_matcher) or return false verify_redirect_path(path_matcher) or return false true end |
#supports_block_expectations? ⇒ Boolean
:nodoc:
68 69 70 |
# File 'lib/umts_custom_matchers/redirect_back.rb', line 68 def supports_block_expectations? true end |