如果我有一个简单的黄瓜功能和场景,就像这样(示例代码来自cucumber wiki):
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
钩子中获取功能和方案大纲名称?
2 回答
改变
before
挂钩到这个:输出:
scenario.gets应该为您提供功能名称 .