Cucumber testing - getting RoutingError

橙三吉。 提交于 2019-12-11 16:43:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!