Ruby on rails 黄瓜测试-获取路由错误
怎么了,伙计们。请帮忙。Ruby on rails 黄瓜测试-获取路由错误,ruby-on-rails,cucumber,bdd,Ruby On Rails,Cucumber,Bdd,怎么了,伙计们。请帮忙。 当我运行cucumber测试时,出现以下错误: No route matches {:action=>"show", :controller=>"accounts"} (ActionController::RoutingError) ./features/support/paths.rb:40:in `path_to' rake routes显示: account GET /accounts/:id(.:format) {:
当我运行cucumber测试时,出现以下错误:
No route matches {:action=>"show", :controller=>"accounts"} (ActionController::RoutingError)
./features/support/paths.rb:40:in `path_to'
rake routes显示:
account GET /accounts/:id(.:format) {:action=>"show", :controller=>"accounts"}
黄瓜试验特性
Scenario:
Given...
And...
Then i should be on Show page
功能/支持/路径.rb
when /^Show page$/
account_path @account
routes.rb
Myapp::Application.routes.draw do
resources :accounts
我想你错了,你设置了@account变量 以下是一些可能的方法。您可以使用:
when /the account page/
account_path(Account.first)
或者更好,更干净和可重用(我不知道您的帐户模式,所以我使用了通用的“名称”):
当然,只要您将“我在”Web步骤定义为:
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
@account.inspect显示了什么?安迪,我如何将@account.inspect添加到我正在运行的cucumber测试中?在When步骤的第一行添加“put@account.inspect”。是的,伙计们。你是对的,它返回零。现在我要打破我的大脑,因为我真的不知道为什么它是零:(好吧,它更像是:为什么你不希望它是零??非常感谢。我将使用你伟大的方法。
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end