路由测试失败:NoMethodError:未定义的方法“值”对于“/the/route”:字符串
我的测试失败了,调试起来非常困难。
我的测试用例是:
it "routes to #active" do
get ("/parties/active").should route_to("parties#active")
end
我的路线是:
resources :parties do
get 'active', :on => :collection
end
当我运行测试用例时,出现以下错误:
NoMethodError: undefined method `values' for "/parties/active":String
完整错误输出位于: https://gist.github.com/1748264
当我运行 rake 路由时,我看到:
active_parties GET /parties/active(.:format) parties#active
parties GET /parties(.:format) parties#index
POST /parties(.:format) parties#create
new_party GET /parties/new(.:format) parties#new
edit_party GET /parties/:id/edit(.:format) parties#edit
party GET /parties/:id(.:format) parties#show
PUT /parties/:id(.:format) parties#update
DELETE /parties/:id(.:format) parties#destroy
root / parties#show
我正在运行的测试实际上与脚手架生成的新测试相同:
it "routes to #new" do
get("/parties/new").should route_to("parties#new")
end
知道发生了什么吗?
I'm getting a failing test that I'm having great difficulty debugging.
My test case is:
it "routes to #active" do
get ("/parties/active").should route_to("parties#active")
end
My route is:
resources :parties do
get 'active', :on => :collection
end
When I run the test case, I get the following error:
NoMethodError: undefined method `values' for "/parties/active":String
Full error output at: https://gist.github.com/1748264
When I run rake routes, I see:
active_parties GET /parties/active(.:format) parties#active
parties GET /parties(.:format) parties#index
POST /parties(.:format) parties#create
new_party GET /parties/new(.:format) parties#new
edit_party GET /parties/:id/edit(.:format) parties#edit
party GET /parties/:id(.:format) parties#show
PUT /parties/:id(.:format) parties#update
DELETE /parties/:id(.:format) parties#destroy
root / parties#show
The test I am running is practically identical to the test for new generated by scaffolding:
it "routes to #new" do
get("/parties/new").should route_to("parties#new")
end
Any idea what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在 get 和该方法的参数之间放置一个空格。不要那样做。
你有这样的:
当它应该是这样的:
否则它将像这样评估:
You're putting a space between get and the arguments for the method. Don't do that.
You have this:
When it should be this:
Otherwise it's going to evaluate like this:
尝试使用散列式路由:
Try using a hash-style route: