module ActionDispatch::Assertions::RoutingAssertions
def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
# Tests a route with an HTTP method
assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
# Tests a route, providing a defaults hash
assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
# Asserts a basic route (controller + default action), with an error message if it fails
assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
# Test a route generated with a specific controller, action, and parameter (id)
assert_routing '/home', controller: 'home', action: 'index'
# Asserts a basic route: a controller with the default action (index)
+message+ parameter allows you to specify a custom error message to display upon failure.
The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
and +assert_generates+ into one step.
options and then that options generates path. This essentially combines +assert_recognizes+
Asserts that path and options match both ways; in other words, it verifies that path generates
def assert_routing(path, options, defaults = {}, extras = {}, message = nil) assert_recognizes(options, path, extras, message) controller, default_controller = options[:controller], defaults[:controller] if controller && controller.include?(?/) && default_controller && default_controller.include?(?/) options[:controller] = "/#{controller}" end generate_options = options.dup.delete_if { |k, _| defaults.key?(k) } assert_generates(path.is_a?(Hash) ? path[:path] : path, generate_options, defaults, extras, message) end