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, options = {}) ⇒ RedirectTo
constructor
Parameters String:: The expected location Hash:: Optional hash of options (currently only :message).
-
#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, options = {}) ⇒ RedirectTo
Parameters
- String
-
The expected location
- Hash
-
Optional hash of options (currently only :message)
39 40 41 42 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 39 def initialize(expected, = {}) @expected = expected @options = end |
Instance Method Details
#failure_message ⇒ Object
Returns
- String
-
The failure message.
64 65 66 67 68 69 70 71 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 64 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.
81 82 83 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 81 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.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 50 def matches?(target) @target, @location = target, target.headers['Location'] @redirected = BeRedirect.new.matches?(target.status) if @options[:message] msg = Merb::Request.escape([Marshal.dump(@options[:message])].pack("m")) @expected << "?_message=#{msg}" end @location == @expected && @redirected end |
#negative_failure_message ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
75 76 77 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 75 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.
87 88 89 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 87 def target_location @target.respond_to?(:headers) ? @target.headers['Location'] : @target end |