Skip to content

Instantly share code, notes, and snippets.

@toamitkumar
Created May 4, 2011 14:27
Show Gist options
  • Save toamitkumar/955308 to your computer and use it in GitHub Desktop.
Save toamitkumar/955308 to your computer and use it in GitHub Desktop.
dynamic routes in unit tests
# Add a controller to test some functionality in controller rspec
class MyTestController < ApplicationController
def index
render :nothing => true
end
end
# add
before do
YourApplication::Application.routes.draw do
match "/my_routes", :to => "my_test#index"
# other routes in the app which your tests might need
# as they are gone after you opened the draw block :(
end
end
# reload the routes from routes.rb
after do
YourApplication::Application.reload_routes!
end
# your unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment