class Merb::Test::Rspec::RouteMatchers::RouteToMatcher
Public Class Methods
new(klass_or_name, action)
click to toggle source
Parameters¶ ↑
- klass_or_name<Class, String>
-
The controller class or class name to match routes for.
- action<~to_s>
-
The name of the action to match routes for.
# File lib/merb-core/test/matchers/route_matchers.rb, line 9 def initialize(klass_or_name, action) @expected_controller = Class === klass_or_name ? klass_or_name.name : klass_or_name @expected_action = action.to_s end
Public Instance Methods
actual_parameters_message()
click to toggle source
# File lib/merb-core/test/matchers/route_matchers.rb, line 72 def actual_parameters_message " with #{(@parameter_matcher.actual || {}).inspect}" if @parameter_matcher end
expected_parameters_message()
click to toggle source
# File lib/merb-core/test/matchers/route_matchers.rb, line 68 def expected_parameters_message " with #{@parameter_matcher.expected.inspect}" if @parameter_matcher end
failure_message()
click to toggle source
Returns¶ ↑
- String
-
The failure message.
# File lib/merb-core/test/matchers/route_matchers.rb, line 58 def failure_message "expected the request to route to #{@expected_controller.to_const_string}##{@expected_action}#{expected_parameters_message}, but was #{@target_controller.to_const_string}##{@target_action}#{actual_parameters_message}" end
match_parameters(target)
click to toggle source
Parameters¶ ↑
- target<Hash>
-
The route parameters to match.
Returns¶ ↑
- Boolean
-
True if the parameter matcher created with with matches or if no parameter matcher exists.
# File lib/merb-core/test/matchers/route_matchers.rb, line 35 def match_parameters(target) @parameter_matcher.nil? ? true : @parameter_matcher.matches?(target) end
matches?(target)
click to toggle source
Parameters¶ ↑
- target<Hash>
-
The route parameters to match.
Returns¶ ↑
- Boolean
-
True if the controller action and parameters match.
# File lib/merb-core/test/matchers/route_matchers.rb, line 19 def matches?(target) @target_env = target.dup @target_controller, @target_action = @target_env.delete(:controller).to_s, @target_env.delete(:action).to_s @target_controller = "#{target.delete(:namespace)}::#{@target_controller}" if target.has_key?(:namespace) @expected_controller.snake_case == @target_controller.snake_case && @expected_action == @target_action && match_parameters(@target_env) end
negative_failure_message()
click to toggle source
Returns¶ ↑
- String
-
The failure message to be displayed in negative matches.
# File lib/merb-core/test/matchers/route_matchers.rb, line 64 def negative_failure_message "expected the request not to route to #{@expected_controller.camel_case}##{@expected_action}#{expected_parameters_message}, but it did" end
with(parameters)
click to toggle source
Creates a new paramter matcher.
Parameters¶ ↑
- parameters<Hash, ~to_param>
-
The parameters to match.
Returns¶ ↑
- RouteToMatcher
-
This matcher.
Alternatives¶ ↑
If parameters is an object, then a new expected hash will be constructed with the key :id set to parameters.to_param.
# File lib/merb-core/test/matchers/route_matchers.rb, line 50 def with(parameters) @parameter_matcher = ParameterMatcher.new(parameters) self end