How to use Rails routes in feature specs
Want to use Rails’ routes in your acceptance specs? No problem. Here’s what you want:
Fair warning: I’ve seen some folks say that you shouldn’t do this, and instead should define your routes in paths.rb. This way testing your routes is part of your acceptance suite.
I see where they’re coming from, but this just doesn’t seem worth it to me. I don’t find routes to be a very bug-prone area in my apps, so keeping duplicate my routes in two files is too high a price to pay.
I’ve been using Rails’ built-in route helpers in my specs for several months now, and can’t think of a single routing issue that’s come up. YMMV.