我正在尝试编写一个测试命名空间控制器的规范,我们称它为Admin::FooController。我的规范是admin_foo_controller_spec.rb。在规范中,我试图编写一个非常基本的规范,看看它是否可以检索控制器的操作。
describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end但是我得到了一个错误:
Failure/Error: get 'index'
No route matches {:controller=>"admin/foo"}对于另一个操作,我有基本上相同的测试,我得到的响应是不成功的。在实际的webapp中,我可以很好地访问这些urls。我应该提到的一件事是,这不是一个RESTful资源(它作为一个资源没有任何意义),所以它实际上只是一组相关的管理操作,所以在我的routes.rb中,它基本上类似于
namespace :admin do
scope "foo" do
match "action1" => "foo#action1"
match "action2" => "foo#action2"
match "/index" => "foo#settings"
match "settings" => "foo#settings"
end
end你知道我做错了什么吗?似乎名称空间给rails带来了麻烦,特别是对于像我这样的新手。谢谢!
发布于 2010-12-24 16:10:46
在您路线中,您的Foo控制器中没有索引操作,请尝试获取“设置”
describe "GET 'index'" do
it "should be successful" do
get 'settings'
response.should be_success
end
end在控制器规范中,您需要定义控制器的操作,而不是真正的路由。您可以在集成测试中尝试这些路由。
https://stackoverflow.com/questions/4524735
复制相似问题