4

如果我有一个简单的黄瓜功能场景,像这样(示例代码来自黄瓜维基):

Feature: Eating cucumbers

Scenario: eat 5 out of 12
  Given there are 12 cucumbers
  When I eat 5 cucumbers
  Then I should have 7 cucumbers

我知道如何在钩子中获取功能场景名称:before

Before do |scenario|
  p [scenario.feature.name, scenario.name]
end

上面的代码返回:

["Eating cucumbers", "eat 5 out of 12"]

问题是该功能是否具有场景大纲

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |  12   |  5  |  7   |

当我运行上面的代码时,我得到:

undefined method `feature' for #<Cucumber::Ast::OutlineTable::ExampleRow:0x007fb0f94a8240> (NoMethodError)

如何在黄瓜钩子中获取功能场景大纲名称?before

4

2 回答 2

6

将钩子更改before为此:

Before do |scenario|
  p [scenario.scenario_outline.feature.name, scenario.scenario_outline.name, scenario.name]
end

输出:

["Eating cucumbers", "eating", "| 12 | 5 | 7 |"]
于 2012-06-26T14:01:48.813 回答
0

场景.gets 应该给你功能名称。

于 2018-06-08T20:15:01.077 回答