Class: Merb::Test::Rspec::RouteMatchers::RouteToMatcher
- Defined in:
- lib/merb-core/test/matchers/route_matchers.rb
Instance Method Summary collapse
- #actual_parameters_message ⇒ Object
- #expected_parameters_message ⇒ Object
-
#failure_message ⇒ Object
Returns String:: The failure message.
-
#initialize(klass_or_name, action) ⇒ RouteToMatcher
constructor
Parameters klass_or_name<Class, String>:: The controller class or class name to match routes for.
-
#match_parameters(target) ⇒ Object
Parameters target<Hash>:: The route parameters to match.
-
#matches?(target) ⇒ Boolean
Parameters target<Hash>:: The route parameters to match.
-
#negative_failure_message ⇒ Object
Returns String:: The failure message to be displayed in negative matches.
-
#with(parameters) ⇒ Object
Creates a new paramter matcher.
Constructor Details
#initialize(klass_or_name, action) ⇒ RouteToMatcher
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.
9 10 11 12 |
# 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 |
Instance Method Details
#actual_parameters_message ⇒ Object
72 73 74 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 72 def " with #{(@parameter_matcher.actual || {}).inspect}" if @parameter_matcher end |
#expected_parameters_message ⇒ Object
68 69 70 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 68 def " with #{@parameter_matcher.expected.inspect}" if @parameter_matcher end |
#failure_message ⇒ Object
Returns
- String
-
The failure message.
58 59 60 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 58 def "expected the request to route to #{@expected_controller.camel_case}##{@expected_action}#{}, but was #{@target_controller.camel_case}##{@target_action}#{}" end |
#match_parameters(target) ⇒ Object
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.
35 36 37 |
# 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) ⇒ Boolean
Parameters
- target<Hash>
-
The route parameters to match.
Returns
- Boolean
-
True if the controller action and parameters match.
19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
64 65 66 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 64 def "expected the request not to route to #{@expected_controller.camel_case}##{@expected_action}#{}, but it did" end |
#with(parameters) ⇒ Object
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.
50 51 52 53 54 |
# File 'lib/merb-core/test/matchers/route_matchers.rb', line 50 def with(parameters) @parameter_matcher = ParameterMatcher.new(parameters) self end |