Read more

Rails 3/4: How to add routes for specs only

Arne Hartherz
October 07, 2013Software engineer at makandra GmbH

If you want to have routes that are only available in tests (e.g. for testing obscure redirects), you can use the with_routing helper -- but that one destroys existing routes which may break a specs that require them to work.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

To keep both "regular" and test routes, do this:

class MyApplicationController < ActionController::Base
  def show
    render text: 'Welcome to my application'
  end
end

test_routes = Proc.new do
  get '/my_application' => 'my_application#show'
end
Rails.application.routes.eval_block(test_routes)

Put it into a place like spec/support/test_routes.rb, or a similar place that's loaded automatically on a spec run.

Posted by Arne Hartherz to makandra dev (2013-10-07 16:32)