class Shoulda::Matchers::ActionController::RouteMatcher
@private
Attributes
Public Class Methods
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 133 def initialize(context, method, path, port: nil) @context = context @method = method @path = add_port_to_path(normalize_path(path), port) @params = {} end
Public Instance Methods
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 158 def description "route #{method.to_s.upcase} #{path} to/from #{params.inspect}" end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 162 def failure_message_when_negated "Didn't expect to #{description}" end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 147 def in_context(context) @context = context self end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 152 def matches?(controller) guess_controller_if_necessary(controller) route_recognized? end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 142 def to(*args) @params = RouteParams.new(args).normalize self end
Private Instance Methods
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 178 def add_port_to_path(path, port) if port "https://example.com:#{port}" + path else path end end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 186 def guess_controller_if_necessary(controller) params[:controller] ||= controller.controller_path end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 170 def normalize_path(path) if path.start_with?('/') path else "/#{path}" end end
Source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 190 def route_recognized? context.send( :assert_routing, { method: method, path: path }, params, ) true rescue ::ActionController::RoutingError => e @failure_message = e.message false rescue Shoulda::Matchers.assertion_exception_class => e @failure_message = e.message false end