3

通常、Cucumber は、機能ファイルで定義したものと同じように見えるようにバックグラウンド ステップを出力します (上部に 1 回)。

$ bundle exec cucumber --color --format pretty

Feature: Something

  Background:
    Given step 1
    And step 2

  Scenario: a scenario
    When I do step 3
    Then it works

  Scenario: another scenario
    When I do a different step 3
    Then it works

シナリオの開始時に常にステップを表示できれば、バックグラウンド ステップが正常に実行されたことを確認するのがはるかに簡単になります。この動作を有効にするにはどうすればよいですか?

Feature: Something

  Scenario: a scenario
    Given step 1
    And step 2
    When I do step 3
    Then it works

  Scenario: another scenario
    Given step 1
    And step 2
    When I do a different step 3
    Then it works
4

2 に答える 2

0

承認された解決策は、この記事の執筆時点での Cucumber の現在のバージョンである 2.3.3 では機能しません。バックグラウンド ステップが に到達することはありませんbefore_step_result。このバージョンの Cucumber で見つけた最良の解決策は次のとおりです。

メソッドCucumber::Formatter::LegacyApi::Adapter::FeaturePrinter. same_background_as_previous_test_case?(cucumber gem で定義されているlib/cucumber/formatter/legacy_api/adapter.rb) を次のように変更します。

def same_background_as_previous_test_case?(source)
  source.background == @previous_test_case_background
end

def same_background_as_previous_test_case?(source)
  false
end

は動的に定義されるためFeaturePrinter、 のファイルで新しいメソッドを定義してモンキー パッチを適用することはできませんfeatures/support。gem を fork する必要があります。または、この変更をデバッグのために時々行うだけでよい場合は、インストールされている gem のコピーでファイルを編集します。

于 2016-05-09T14:10:41.907 に答える