如何在Cucumber中指定路径

时间:2014-03-24 17:50:06

标签: ruby-on-rails cucumber

我已在'spree_fit_card / new_gift_card.feature`中设置了此黄瓜功能:

@gift-card
Feature: access gift cards
  As a general user
  I will be able to place an order for a gift card

  Scenario: The gift card index page will redirect to /new
    When I am on the gift card page
    Then I will be redirected to the new gift card page

support/paths.rb

module NavigationHelpers
  def path_to(page_name)
    when /the gift card page/
      spree.gift_cards_path
    when /the new gift card page/
      spree.new_gift_card_path
    else
      ...
    end
  end
end

当我们结帐step_definitions/new_gift_card_steps.rb时:

When(/^I am on the gift card page$/) do
  pending
end

Then(/^I will be redirected to the new gift card page$/) do
  pending
end

黄瓜产量:

$ zeus cucumber --tags @gift-card
Loading fixtures
Using the default profile...
@gift-card
Feature: access gift cards
  As a general user
  I will be able to place an order for a gift card

  Scenario: The gift card page will redirect to the new gift card page # features/spree_gift_card/new_gift_card.feature:6
    When I am on the gift card page                                 # features/spree_gift_card/new_gift_card.feature:7
      Ambiguous match of "I am on the gift card page":

      features/step_definitions/spree_gift_card/new_gift_cards_steps.rb:1:in `/^I am on the gift card page$/'
      cucumber-websteps-0.10.0/lib/cucumber/websteps/browsing_steps.rb:1:in `/^(?:|I )am on (.+)$/'

      You can run again with --guess to make Cucumber be more smart about it
       (Cucumber::Ambiguous)
      -e:1:in `<main>'
      features/spree_gift_card/new_gift_card.feature:7:in `When I am on the gift card page'
    Then I will be redirected to the new gift card page              # features/step_definitions/spree_gift_card/new_gift_cards_steps.rb:5

Failing Scenarios:
cucumber features/spree_gift_card/new_gift_card.feature:6 # Scenario: The gift card page will redirect to the new gift card page

所以我考虑了Cucumber的建议并运行了zeus cucumber --tags @gift-card --guess

Loading fixtures
Using the default profile...
@gift-card
Feature: access gift cards
  As a general user
  I will be able to place an order for a gift card

  Scenario: The gift card page will redirect to the new gift card page # features/spree_gift_card/new_gift_card.feature:6
    When I am on 'the gift card page'                                  # features/step_definitions/spree_gift_card/new_gift_cards_steps.rb:1
      TODO (Cucumber::Pending)
      ./features/step_definitions/spree_gift_card/new_gift_cards_steps.rb:2:in `/^I am on the gift card page$/'
      features/spree_gift_card/new_gift_card.feature:7:in `When I am on the gift card page'
    Then I will be redirected to the new gift card page              # features/step_definitions/spree_gift_card/new_gift_cards_steps.rb:5

1 scenario (1 pending)
2 steps (1 skipped, 1 pending)
0m0.016s
Cleaning up database

我很高兴它通过了--guess,但我不明白为什么没有它就没有通过它。我想我已经做好了,但我显然没有。如果它对Ruby on Rails版本3.2.17有帮助,我正在使用Spree框架。

1 个答案:

答案 0 :(得分:0)

原因可以在您提供的错误中找到:

cucumber-websteps-0.10.0/lib/cucumber/websteps/browsing_steps.rb:1:in `/^(?:|I )am on (.+)$/'

显示在browse_steps.rb中有一个“默认”步骤,该步骤也与您的测试匹配。这就是你得到这个错误的原因。如你所见,匹配比你的步骤“更少”,这就是“猜测”工作的原因:它将自动选择“最佳拟合”步骤定义。