Parent

Class Index [+]

Quicksearch

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
 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

Public Instance Methods

actual_parameters_message() click to toggle source
    # File 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
expected_parameters_message() click to toggle source
    # File 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
failure_message() click to toggle source

Returns

String

The failure message.

    # File 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
match_parameters(target) click to toggle source

Parameters

target

The route parameters to match.

Returns

Boolean

True if the parameter matcher created with # matches or if no parameter matcher exists.

    # File 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
matches?(target) click to toggle source

Parameters

target

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
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
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
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
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
50:     def with(parameters)
51:       @parameter_matcher = ParameterMatcher.new(parameters)
52: 
53:       self
54:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.