Testing Routes

Let’s start the tour with a part of the Rails layer that’s not commonly tested in isolation, but where testing can sometimes be valuable. Although the basics of Rails routing are simple, the desire to customize Rails’s 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 ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.