代码之家  ›  专栏  ›  技术社区  ›  Mostafa Hussein

Capybara歧义错误

  •  0
  • Mostafa Hussein  · 技术社区  · 11 年前

    我的应用程序是基于Rails 3的,它有用户身份验证的设计,我得到了这个错误。如何解决这个错误?

    bin/cucumber features/signing_up.feature
    Rack::File headers parameter replaces cache_control after Rack 1.5.
    Using the default profile...
    Feature: Signing up
      In order to be attributed for my work
      As a user
      I want to be able to sign up
    
      Scenario: Signing up                                                 # features/signing_up.feature:6
        Given I am on the homepage                                         # features/step_definitions/web_steps.rb:44
        When I follow "Sign up"                                            # features/step_definitions/web_steps.rb:56
          Ambiguous match, found 2 elements matching link "Sign up" (Capybara::Ambiguous)
          ./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
          features/signing_up.feature:8:in `When I follow "Sign up"'
        And I fill in "Email" with "user@ticketee.com"                     # features/step_definitions/web_steps.rb:60
        And I fill in "Password" with "password"                           # features/step_definitions/web_steps.rb:60
        And I fill in "Password confirmation" with "password"              # features/step_definitions/web_steps.rb:60
        And I press "Sign up"                                              # features/step_definitions/web_steps.rb:52
        Then I should see "You have signed up successfully."               # features/step_definitions/web_steps.rb:105
        Then I should see "Please confirm your account before signing in." # features/step_definitions/web_steps.rb:105
    
    Failing Scenarios:
    cucumber features/signing_up.feature:6 # Scenario: Signing up
    
    1 scenario (1 failed)
    8 steps (1 failed, 6 skipped, 1 passed)
    0m0.272s
    

    步骤定义:57

    When /^(?:|I )follow "([^"]*)"$/ do |link|
      click_link(link)
    end
    

    路线.rb

    Ticketee::Application.routes.draw do
    
      devise_for :users, :controllers => { :registrations => "registrations" }
      get '/awaiting_confirmation', :to => "users#confirmation", :as => 'confirm_user'
    
      resources :projects do
        resources :tickets
      end
      root :to => "projects#index"
    
      namespace :admin do
        root :to => "base#index"
        resources :users
      end
    

    这就是从书中得到的routes.rb,在书中考试通过了,但我没有通过

    1 回复  |  直到 11 年前
        1
  •  0
  •   user740584 user740584    11 年前

    如果链接位于类或id等其他样式中,则可以使用:

    within(<whatever class or id>) do
      click_link(link)
    end
    

    或者,强制它单击您可以使用的第一个链接 first(:link, link).click . 如果你使用这种方法,你将需要这样的东西 all(link)[1].click 稍后点击“注册”按钮。