Ich legte eine Debug-Print-Anweisung in einem Abschnitt Background
Gurke.Warum wird die Ausgabe eines Gurkenhintergrunds nur einmal angezeigt?
Da Background
einmal für jedes Szenario ausgeführt wird, erwartete ich Ausgabe von Background
einmal für jedes Szenario. Die Ausgabe wird jedoch nur einmal angezeigt. Warum?
Hier ist ein einfaches Beispiel, das meine Frage stellt:
Rechner/features/adding.feature:
Feature: Adding
Background:
Given calculator is ready
Scenario: Add two numbers
Given the input "2" and "2"
When the calculator is run
Then the output should be "4"
Scenario: Add another two numbers
Given the input "2" and "3"
When the calculator is run
Then the output should be "5"
Rechner/features/step_definitions/calculator_steps.rb:
counter = 0
Given(/^calculator is ready$/) do
puts "*** background ***"
counter += 1
end
Given(/^the input "([^"]*)" and "([^"]*)"$/) do |x1, x2|
@x1 = x1
@x2 = x2
end
When(/^the calculator is run$/) do
@output = `ruby calc.rb #{@x1} #{@x2}`
end
Then(/^the output should be "([^"]*)"$/) do |expected_output|
expect(@output).to eq(expected_output)
puts "counter=#{counter}"
end
Rechner/calc.rb:
x1 = ARGV[0].to_i
x2 = ARGV[1].to_i
print ("#{x1+x2}")
Hier ist die Ausgabe, wenn Szenarien ausgeführt werden:
$ cucumber
Feature: Adding
Background: # features/adding.feature:3
Given calculator is ready # features/step_definitions/calculator_steps.rb:3
*** background ***
Scenario: Add two numbers # features/adding.feature:6
Given the input "2" and "2" # features/step_definitions/calculator_steps.rb:8
When the calculator is run # features/step_definitions/calculator_steps.rb:13
Then the output should be "4" # features/step_definitions/calculator_steps.rb:17
counter=1
Scenario: Add another two numbers # features/adding.feature:11
Given the input "2" and "3" # features/step_definitions/calculator_steps.rb:8
When the calculator is run # features/step_definitions/calculator_steps.rb:13
Then the output should be "5" # features/step_definitions/calculator_steps.rb:17
counter=2
2 scenarios (2 passed)
8 steps (8 passed)
0m0.094s
ich die Linie *** background ***
zweimal zu sehen erwartet (weil Background
zweimal ausgeführt wird), aber es wird nur einmal gezeigt. Warum?
Dank Dave, die Lösung, die Sie für Cucumber 2.3.3 beschrieben haben, funktioniert für mich, und da dies normalerweise für Debugging-Zwecke benötigt wird, ist es kein Problem, den Edelstein lokal zu modifizieren. –