Class: Merb::Test::Rspec::ControllerMatchers::RedirectTo
- Defined in:
- lib/merb-core/test/matchers/controller_matchers.rb
Instance Method Summary collapse
-
#failure_message ⇒ Object
Returns String:: The failure message.
-
#initialize(expected) ⇒ RedirectTo
constructor
Parameters String:: The expected location.
-
#inspect_target ⇒ Object
Returns String:: The controller and action name.
-
#matches?(target) ⇒ Boolean
Parameters target<Merb::Controller>:: The controller to match.
-
#negative_failure_message ⇒ Object
Returns String:: The failure message to be displayed in negative matches.
-
#target_location ⇒ Object
Returns String:: Either the target’s location header or the target itself.
Constructor Details
#initialize(expected) ⇒ RedirectTo
Parameters
- String
-
The expected location
39 40 41 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 39 def initialize(expected) @expected = expected end |
Instance Method Details
#failure_message ⇒ Object
Returns
- String
-
The failure message.
57 58 59 60 61 62 63 64 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 57 def msg = "expected #{inspect_target} to redirect to <#{@expected}>, but " if @redirected msg << "was <#{target_location}>" else msg << "there was no redirection" end end |
#inspect_target ⇒ Object
Returns
- String
-
The controller and action name.
74 75 76 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 74 def inspect_target "#{@target.controller_name}##{@target.action_name}" end |
#matches?(target) ⇒ Boolean
Parameters
- target<Merb::Controller>
-
The controller to match
Returns
- Boolean
-
True if the controller status is redirect and the locations match.
49 50 51 52 53 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 49 def matches?(target) @target, @location = target, target.headers['Location'] @redirected = BeRedirect.new.matches?(target.status) @location == @expected && @redirected end |
#negative_failure_message ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
68 69 70 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 68 def "expected #{inspect_target} not to redirect to <#{@expected}>, but did anyway" end |
#target_location ⇒ Object
Returns
- String
-
Either the target’s location header or the target itself.
80 81 82 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 80 def target_location @target.respond_to?(:headers) ? @target.headers['Location'] : @target end |