黄瓜测试-获取RoutingError [英] Cucumber testing - getting RoutingError
本文介绍了黄瓜测试-获取RoutingError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
怎么了,伙计们.请帮忙.
当我运行黄瓜测试时,出现此错误:
What's wrong, guys. Please help.
When i run my cucumber test, i've got this error:
No route matches {:action=>"show", :controller=>"accounts"} (ActionController::RoutingError)
./features/support/paths.rb:40:in `path_to'
耙道显示:
account GET /accounts/:id(.:format) {:action=>"show", :controller=>"accounts"}
cucumber_test.feature
cucumber_test.feature
Scenario:
Given...
And...
Then i should be on Show page
features/support/paths.rb
features/support/paths.rb
when /^Show page$/
account_path @account
routes.rb
routes.rb
Myapp::Application.routes.draw do
resources :accounts
推荐答案
我想你错了,以某种方式设置了@account变量.
Imho you're assuming wrong that somehow you have @account variable set.
以下是一些可能的方法.您可以使用:
Here are some of the possible approaches. You could use:
when /the account page/
account_path(Account.first)
或更好,更干净和可重用(我不知道您的Account模式,所以我使用了通用的名称"):
or better, more clean and reusable (I don't know your schema for Account so I used generic 'name'):
when /the account page for account named ".*"/
account_name = page_name.scan(/".*"/).first.gsub("\"", '')
account = Account.find_by_name(account_name)
account_path(account)
当然,只要您定义了这样的我在"网络步骤,就可以了:
Of course as long as you've defined your "I am on" webstep like this:
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
这篇关于黄瓜测试-获取RoutingError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文