Write a failed test for an action that has no route, even with the pipeline turned on

I'm on rails 3.2 with the conveyor on. I am testing an action that has not yet been built (TDD, trying to run the test first). When I initially ran the test, I get a failure as expected.

class AccountsControllerTest < ActionController::TestCase def test_my_path get :my_path puts @response.body assert_template :my_path end end #=> test_my_path(AccountsControllerTest): AbstractController::ActionNotFound: The action 'my_path' could not be found for AccountsController 

When I add the appropriate view (app / views / my_path.html.erb), I still expect the test to fail, since I did not specify a route for this action. It passes though, and I think because the page is being processed by the asset pipeline. In the view, I call <%= request.fullpath %> and invert /assets?action=my_path from the puts @response.body call.

When I try to access the / my _path accounts in the browser, I see "There are no route matches [GET]" / accounts / my _path ", so I want to make sure I have a test too. Why is this happening and how should I fix the test? Should I instead test the route separately with assert_recognizes? To narrow down the source of the problem, my route file is empty.

+4
source share
1 answer

First, the Rails controller displays the existing template, even if the corresponding action is not defined ( http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action ). This is why your test passed after adding the template.

Functional tests directly invoke the action of the controller and do not pass through the router. Thus, the tests pass even if the route is undefined and does not work in the browser. Use separate test cases to test routes (or test routes in integration tests).

+1
source

All Articles