问题
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'
rake routes shows:
account GET /accounts/:id(.:format) {:action=>"show", :controller=>"accounts"}
cucumber_test.feature
Scenario:
Given...
And...
Then i should be on Show page
features/support/paths.rb
when /^Show page$/
account_path @account
routes.rb
Myapp::Application.routes.draw do
resources :accounts
回答1:
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)
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
来源:https://stackoverflow.com/questions/7463191/cucumber-testing-getting-routingerror