Testing Routes
Although the basics of Rails routing are simple, the desire to customize Rails’ response to URLs can lead to confusion about exactly what your application is going to do when converting between a URL and a Rails action. Rails provides a way to specify route behavior in a test.
Routing tests are not typically part of my TDD process—usually my integration test implicitly covers the routing. That said, sometimes routing gets complicated and has some logic of its own (especially if you’re trying to replicate an existing URL scheme), so it’s nice to have this as part of your test suite.
RSpec-Rails puts route tests in the spec/routing directory. The primary matcher that RSpec-Rails uses for route testing is route_to. Here’s a sample ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access