2013-10-16 142 views
0

我有这个模块在我的lib文件夹中使用模块:在lib文件夹中的测试

module Exceptions 
    class NotAuthorized < StandardError 
    end 
end 

然后,我有这样一个控制器的测试:

class Admin::ApplicationControllerTest < ActionController::TestCase 

    test "should not be authorized" do 
     assert_raise(Exceptions::NotAuthorized) { 
     get :index 
     } 
    end 
end 

我也试图把此行我的环境/ test.rb

config.autoload_paths +=%W(#{config.root}/lib) 

但是,当我运行测试我总是得到:

NameError: unitialized constant Admin::ApplicationControllerTest::Exceptions 

如何在测试中包含模块异常?

回答

0

移动

config.autoload_paths +=%W(#{config.root}/lib) 

application.rb中来修复它。

相关问题