How can I assert that no route matches in a Rails integration test?

前端 未结 4 1166
予麋鹿
予麋鹿 2020-12-31 17:53

I have a Rails 3 integration test which tests my routes. It contains tests such as:

assert_routing(
    \"/#{@category.url.path}/#{@foo.url.path}\",
    { :c         


        
4条回答
  •  隐瞒了意图╮
    2020-12-31 18:21

    There is a similar way for checking this in Rails 4 by asserting on the UrlGenerationError exception:

    def test_no_routes_match_when_neither_foo_nor_bar_exist
      assert_raises(ActionController::UrlGenerationError) do
        get '/category/this-is-neither-a-foo-nor-a-bar'
      end
    end
    

提交回复
热议问题