| Class | Merb::Test::Rspec::RouteMatchers::RouteToMatcher |
| In: |
merb-core/lib/merb-core/test/matchers/route_matchers.rb
|
| Parent: | Object |
| 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 merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 9
9: def initialize(klass_or_name, action)
10: @expected_controller = Class === klass_or_name ? klass_or_name.name : klass_or_name
11: @expected_action = action.to_s
12: end
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 72
72: def actual_parameters_message
73: " with #{(@parameter_matcher.actual || {}).inspect}" if @parameter_matcher
74: end
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 68
68: def expected_parameters_message
69: " with #{@parameter_matcher.expected.inspect}" if @parameter_matcher
70: end
| String: | The failure message. |
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 58
58: def failure_message
59: "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}"
60: end
| target<Hash>: | The route parameters to match. |
| Boolean: | True if the parameter matcher created with with matches or if no parameter matcher exists. |
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 35
35: def match_parameters(target)
36: @parameter_matcher.nil? ? true : @parameter_matcher.matches?(target)
37: end
| target<Hash>: | The route parameters to match. |
| Boolean: | True if the controller action and parameters match. |
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 19
19: def matches?(target)
20: @target_env = target.dup
21: @target_controller, @target_action = @target_env.delete(:controller).to_s, @target_env.delete(:action).to_s
22:
23: @target_controller = "#{target.delete(:namespace)}::#{@target_controller}" if target.has_key?(:namespace)
24:
25: @expected_controller.snake_case == @target_controller.snake_case && @expected_action == @target_action && match_parameters(@target_env)
26: end
| String: | The failure message to be displayed in negative matches. |
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 64
64: def negative_failure_message
65: "expected the request not to route to #{@expected_controller.camel_case}##{@expected_action}#{expected_parameters_message}, but it did"
66: end
Creates a new paramter matcher.
| parameters<Hash, ~to_param>: | The parameters to match. |
| RouteToMatcher: | This matcher. |
If parameters is an object, then a new expected hash will be constructed with the key :id set to parameters.to_param.
# File merb-core/lib/merb-core/test/matchers/route_matchers.rb, line 50
50: def with(parameters)
51: @parameter_matcher = ParameterMatcher.new(parameters)
52:
53: self
54: end