开发者

Cucumber testing - getting RoutingError

开发者 https://www.devze.com 2023-04-05 22:01 出处:网络
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)

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...开发者_如何学C
    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  


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号