4

このような単純なキュウリの機能シナリオがある場合(コード例はキュウリの 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

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

scenario.gets は機能名を提供する必要があります。

于 2018-06-08T20:15:01.077 に答える