gpt4 book ai didi

ruby-on-rails - 路由测试在 : NoMethodError: undefined method `values' for "/the/route":String 上失败

转载 作者:行者123 更新时间:2023-12-03 15:58:50 25 4
gpt4 key购买 nike

我得到了一个失败的测试,我在调试时遇到了很大的困难。

我的测试用例是:

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

知道发生了什么吗?

最佳答案

您在 get 和方法的参数之间放置了一个空格。不要那样做。

你有这个:

it "routes to #active" do
get ("/parties/active").should route_to("parties#active")
end

什么时候应该是这样:
it "routes to #active" do
get("/parties/active").should route_to("parties#active")
end

否则它会像这样评估:
  get(("/parties/active").should route_to("parties#active"))

关于ruby-on-rails - 路由测试在 : NoMethodError: undefined method `values' for "/the/route":String 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com