Handy Helper Methods Testing Domain-specific Routing for Functional Tests

We've been doing some domain-specific routing lately with a Rails project, so here's a few helper methods that we use in our test environment to test these routes.

First, we have a little method to set the test host's domain value. This is in addition to just setting @request.host, since we're using some plugins for additional routing flexibility, we mock out the response from ActionController itself:



And then we can use the assert_routing method in our tests to make sure our routing is working. Since it's often nice to make sure that a particular route does NOT exist as well, here's a little method to assert_not_routing, which takes the same arguments as assert_routing:



And see it all together in a functional test:

Tags: rails testing mocha