【发布时间】:2012-02-05 22:48:02
【问题描述】:
我遇到了一个失败的测试,我在调试时遇到了很大的困难。
我的测试用例是:
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
知道发生了什么吗?
【问题讨论】:
-
我还发现在
before块中使用get会导致同样的错误。
标签: ruby-on-rails rspec-rails rails-routing