黄瓜测试 – 获取RoutingError

怎么了,伙计们。 请帮忙。
当我运行我的黄瓜测试时,我遇到了这个错误:

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

  Scenario: Given... And... Then i should be on Show page 

function/支持/ paths.rb

 when /^Show page$/ account_path @account 

的routes.rb

 Myapp::Application.routes.draw do resources :accounts 

Imho你假设错误,不知何故你有@account变量集。

以下是一些可能的方法。 你可以使用:

 when /the account page/ account_path(Account.first) 

或更好,更干净和可重复使用(我不知道您的帐户架构所以我使用通用’名称’):

 when /the account page for account named ".*"/ account_name = page_name.scan(/".*"/).first.gsub("\"", '') account = Account.find_by_name(account_name) account_path(account) 

当然,只要你已经定义了你的“我在”这样的网站:

 Given /^(?:|I )am on (.+)$/ do |page_name| visit path_to(page_name) end