class Shoulda::Matchers::ActionController::RouteMatcher

@private

Attributes

failure_message[R]
failure_message_for_should[R]
failure_message_for_should_not[R]
failure_message_when_negated[R]

Public Class Methods

new(method, path, context) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 60
def initialize(method, path, context)
  @method  = method
  @path    = path
  @context = context
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 86
def description
  "route #{@method.to_s.upcase} #{@path} to/from #{@params.inspect}"
end
in_context(context) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 76
def in_context(context)
  @context = context
  self
end
matches?(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 81
def matches?(controller)
  guess_controller!(controller)
  route_recognized?
end
to(*args) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 71
def to(*args)
  @params = RouteParams.new(args).normalize
  self
end

Private Instance Methods

guess_controller!(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 92
def guess_controller!(controller)
  @params[:controller] ||= controller.controller_path
end
route_recognized?() click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 97
def route_recognized?
  begin
    @context.__send__(:assert_routing,
                  { method: @method, path: @path },
                  @params)

    @failure_message_when_negated = "Didn't expect to #{description}"
    true
  rescue ::ActionController::RoutingError => error
    @failure_message = error.message
    false
  rescue Shoulda::Matchers::AssertionError => error
    @failure_message = error.message
    false
  end
end