class Shoulda::Matchers::ActionController::RouteMatcher

@private

Attributes

context[R]
failure_message[R]
method[R]
params[R]
path[R]

Public Class Methods

new(context, method, path, port: nil) click to toggle 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

description() click to toggle 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
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 162
def failure_message_when_negated
  "Didn't expect to #{description}"
end
in_context(context) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 147
def in_context(context)
  @context = context
  self
end
matches?(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 152
def matches?(controller)
  guess_controller_if_necessary(controller)

  route_recognized?
end
to(*args) click to toggle 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

add_port_to_path(path, port) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 178
def add_port_to_path(path, port)
  if port
    "http://example.com:#{port}" + path
  else
    path
  end
end
guess_controller_if_necessary(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 187
def guess_controller_if_necessary(controller)
  params[:controller] ||= controller.controller_path
end
normalize_path(path) click to toggle 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
route_recognized?() click to toggle source
# File lib/shoulda/matchers/action_controller/route_matcher.rb, line 191
def route_recognized?
  context.send(
    :assert_routing,
    { method: method, path: path },
    params,
  )
  true
rescue ::ActionController::RoutingError => error
  @failure_message = error.message
  false
rescue Shoulda::Matchers.assertion_exception_class => error
  @failure_message = error.message
  false
end