我试图在我的rails 2.3.4应用程序上测试路由。有几个网站解释如何测试路线,包括铁轨文件,但是我按照说明收到错误。测试rails路径:找不到ActionController :: Assertions :: RoutingAssertions方法
首先,我假设这些测试可以在相关的单元测试文件中完成。似乎没有更明显的地方,也没有文件指出。
这就是说,这是test/unit/TitlesTest.rb
require File.dirname(__FILE__) + '/../test_helper'
class TitleTest < Test::Unit::TestCase
# include ActionController::Assertions::RoutingAssertions
def test_routes
assert_routing "games", { :controller => "titles", :section => "games", :action => "index", :id => nil }
end
end
rake test:units
的精简版失败,出现错误:
NoMethodError: undefined method `assert_routing' for #<TitleTest:0x7f387232ec98>
/test/unit/title_test.rb:7:in `test_routes'
我认为assert_routing在ActionController::Assertions::RoutingAssertions
定义了Rails API中看到的,所以我尝试包括该模块,只有在其他地方失败。
请注意上面的代码示例中的注释include
行。
NoMethodError: undefined method `clean_backtrace' for #<TitleTest:0x7fd895fadf00>
/test/unit/title_test.rb:7:in `test_routes'
clean_backtrace
是在ActionController :: TestCase :: Assertions中定义的另一种测试方法。
我没有得到这些错误的谷歌搜索结果 - 没有人似乎有这个问题。如果我在新生成的Rails应用程序中重新创建方案,也会发生此问题。我认为我不应该在测试用例中包含这些模块。这里可能有什么问题?
您是否尝试过使用ActionController :: TestCase :: Assertions? – 2009-11-27 01:16:11
包括ActionController :: TestCase :: Assertions后,它似乎工作。不过,我认为我不应该添加这些东西是很正常的。 – 2009-11-27 01:20:11
我也尝试继承ActiveSupport :: TestCase而不是Test :: Unit :: TestCase,但我仍然需要手动包含。 – 2009-11-27 01:22:25