Where to test routes in ruby on rails

前端 未结 5 1865
耶瑟儿~
耶瑟儿~ 2021-02-19 00:25

Where to test routes in ruby on rails?

  • unit tests?
  • functional tests?
  • integration tests?

Addition:

To be e

5条回答
  •  攒了一身酷
    2021-02-19 00:37

    According to a comment in this rails bug, the proper place is in a functional test. If you try to test them in an integration test, the routes you established in routes.rb will not be available.

    require 'test_helper'
    
    class FooControllerTest < ActionController::TestCase
      test "foo routes" do
        assert_recognizes({:controller => 'foo_controller', :action => 'list'}, '/foos'
      end
    end
    

    Route tests are good places to list links that exist in the wild, and avoid inadvertently breaking them with a code change. It's a little strange that the tests are scoped to a controller, since it's the route set as a whole you're actually testing, but I haven't heard of a 'route set test'.

提交回复
热议问题