New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested root route results in falsely passing specs #843
Comments
It looks like this is a bug in Rails since the exception should be raised from
I've been able to reproduce the problem using the default Rails testing setup (no rspec). And it affects Rails 4.0.0, but not 4.0.1 which was just released today. I guess we'll be upgrading. Sigh... |
Thanks for tracking this down - definitely an interesting one! |
I'm getting a similar error but possibly for a completely different reason on Rails 4.0.2. Yet to find a way to rescue from the error in the test (which is NOT what I'm testing for)
|
I'd suggest you figure out why your route isn't matching... as you won't be able to proceed without a valid route. |
@JonRowe I know why the route is not matching (again this is not what I'm testing for), but it is disturbing that usual methods involving |
Not really, those are both Rails methods specific to controllers, if you never enter the scope of the controller they cover then they won't be triggered. If you want to actually rescue the exception in the test then use a Ruby begin
get :index
rescue ActionController::UrlGenerationError:
raise 'broken route'
end |
@JonRowe I have already tried that in ApplicationController, but it is not raised at that level, so this is something that is only triggered in Rails.env.test? I can rescue from it in the test, that is certainly not an issue, but I'm more interested in finding out why it is not entering my custom error handling code, and therefore could not be handled like other exceptions, at least on the controller level. I do have a route like the following:
|
Rails handles routes "not found" differently in development, test and production. |
Okay I see now this is related to rails/journey#59 and it has been closed, is there anything that can be done to align the behavior in the specs? |
Yes, as specified in that issue: you specify all of the parameters so the route resolves correctly. |
Meaning, the behaviour of this is left to Rails, |
@JonRowe noted, but I agree with what is mentioned in that issue:
Just throwing this out, maybe there can be a better solution |
Feel free to discuss it with the Rails core team, our aim (with |
I know this is an old issue, but I came across this today and figured I could shed some light for other internet travelers. I believe the core of the problem was first reported here: rails/rails#6459 First attempt to address the problem was here: rails/journey#47 And the actual fix was here: rails/rails@aba0a17 |
To reproduce, create an empty Rails 4.0.0 project and add to your Gemfile:
Then run
bundle
andrails generate rspec:install
.Scaffold a test model/controller with
rails g scaffold post
andbundle exec rake db:migrate RAILS_ENV=test
. The routes file (excluding comments) looks like:Running the generated controller spec passes:
Change the routes file to look like this:
and run the same controller spec. It now fails with errors saying "No route matches...". That's what we expect.
But then change the routes to look like:
Run the controller spec again. I'd expect to get a "No route matches..." error. But instead, the request is routed to
PostsController
as if the route existed.In fact, in our app we noticed that after adding the nested root, all controller specs will route successfully, even if their corresponding routes are deleted.
The text was updated successfully, but these errors were encountered: