Route search error

I am writing a book in Rails 3 at the moment and the past - I wrote in chapter 3 or so that when a certain function is executed, a routing error is created. Now, unlike me, I write things that are not true, so I'm sure that this happened in the past.

I have not yet been able to play the script myself, but I am sure that this is one of the forgotten settings in the environment file.

To duplicate this problem:

  • Create a new rails project
  • important : delete the file public/index.html
  • Add the cucumber rails and capybara to the "test" group in the Gemfile
  • run bundle install
  • run rails g cucumber:skeleton
  • Create a new function, name it features/creating_projects.feature
  • Inside this function is put:

It:

 Feature: Creating projects In order to value As a role I want feature Scenario: title Given I am on the homepage 

When you run this function with bundle exec cucumber features/creating_projects.feature , it should fail with the error "No routes matched /" because you did not determine the root route. However, what I and others are observing is that it is not.

Now I have set a parameter in test.rb that will display this exception page, but I would prefer that Rails make a hard raise for the exception, so that it appears in Cucumber as an unsuccessful step, for example, I'm pretty sure it was, and not a step behind step.

Does anyone know what could have changed since last May for Rails to not do this? I am pretty sure that this is a setting in config/environments/test.rb , but for life I can not understand.

+4
source share
1 answer

After I examine the Rails source code, it looks like the ActionDispatch::ShowExceptions responsible for collecting ActionController::RoutingError exceptions is ActionController::RoutingError from the test environment. Confirmed when running rake middleware and rake middleware RAILS_ENV=test .

You can see that at https://github.com/josh/rack-mount/blob/master/lib/rack/mount/route_set.rb#L152 it returns the title X-Cascade => 'pass' , and ActionDispatch::ShowExceptions is responsible for getting it (at https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L52 )

So, the reason you see your test case passing is because rack-mount returns the text β€œNot Found” with a status of 404.


I will git blame people and fix them. Here it is conditional: https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L159 . If the setting is correct, the error was translated correctly, but we got the error page output. If this is a lie, then this middleware does not load at all. Hold on ...


Refresh . To clear the previous block, you get stuck here. If you set action_dispatch.show_exceptions to false , you will not download this middleware, resulting in a 404 error from rack-mount . If you set action_dispatch.show_exceptions to true , this middleware will be downloaded, but it will save the error and display a nice "exception" page for you.

+3
source

Source: https://habr.com/ru/post/1340087/


All Articles