diff --git a/History.md b/History.md index add472af5e..944fe9b466 100644 --- a/History.md +++ b/History.md @@ -1,8 +1,8 @@ ## [In Git](https://github.com/cucumber/cucumber/compare/v1.3.19...v1.3.x-bugfix) -* Your change here? + * Handle step output correctly for Scenario Outlines with the --expand option ([804](https://github.com/cucumber/cucumber/issues/804) @brasmusson) -## [In Git](https://github.com/cucumber/cucumber/compare/v1.3.18...v1.3.19) +## [v1.3.19](https://github.com/cucumber/cucumber/compare/v1.3.18...v1.3.19) * Update multi_test dependency to prevent crashes on ruby 2.2 when no minitest or rspec available (@tooky) diff --git a/features/json_formatter.feature b/features/json_formatter.feature index 63d1ee1b2b..fb295779e1 100644 --- a/features/json_formatter.feature +++ b/features/json_formatter.feature @@ -98,6 +98,14 @@ Feature: JSON output formatter """ Feature: An embed data directly feature + Scenario Outline: + Given I embed data directly + + Examples: + | dummy | + | 1 | + | 2 | + Scenario: Given I embed data directly @@ -437,7 +445,7 @@ Feature: JSON output formatter """ Scenario: embedding data directly - When I run `cucumber -b --format json features/embed_data_directly.feature` + When I run `cucumber -b --format json -x features/embed_data_directly.feature` Then it should pass with JSON: """ [ @@ -449,18 +457,74 @@ Feature: JSON output formatter "line": 1, "description": "", "elements": [ + { + "keyword": "Scenario Outline", + "name": "", + "line": 8, + "description": "", + "id": "an-embed-data-directly-feature;;;2", + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "I embed data directly", + "line": 4, + "embeddings": [ + { + "mime_type": "mime-type", + "data": "YWJj" + } + ], + "match": { + "location": "features/step_definitions/steps.rb:38" + }, + "result": { + "status": "passed", + "duration": 1 + } + } + ] + }, + { + "keyword": "Scenario Outline", + "name": "", + "line": 9, + "description": "", + "id": "an-embed-data-directly-feature;;;3", + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "I embed data directly", + "line": 4, + "embeddings": [ + { + "mime_type": "mime-type", + "data": "YWJj" + } + ], + "match": { + "location": "features/step_definitions/steps.rb:38" + }, + "result": { + "status": "passed", + "duration": 1 + } + } + ] + }, { "id": "an-embed-data-directly-feature;", "keyword": "Scenario", "name": "", - "line": 3, + "line": 11, "description": "", "type": "scenario", "steps": [ { "keyword": "Given ", "name": "I embed data directly", - "line": 4, + "line": 12, "embeddings": [ { "mime_type": "mime-type", diff --git a/lib/cucumber/formatter/gherkin_formatter_adapter.rb b/lib/cucumber/formatter/gherkin_formatter_adapter.rb index 9f0d7843be..43299203ff 100644 --- a/lib/cucumber/formatter/gherkin_formatter_adapter.rb +++ b/lib/cucumber/formatter/gherkin_formatter_adapter.rb @@ -10,6 +10,8 @@ def initialize(gherkin_formatter, print_empty_match, options) @gf = gherkin_formatter @print_empty_match = print_empty_match @options = options + @delayed_messages = [] + @delayed_embeddings = [] end def before_feature(feature) @@ -19,10 +21,12 @@ def before_feature(feature) def before_background(background) @outline = false + @delay_output = true @gf.background(background.gherkin_statement) end def before_feature_element(feature_element) + @delay_output = true case(feature_element) when Ast::Scenario @outline = false @@ -58,6 +62,7 @@ def scenario_name(keyword, name, file_colon_line, source_indent) @current_scenario_hash['description'], example_row_hash['line'], example_row_hash['id']) + @delay_output = true @gf.scenario(scenario) end end @@ -65,9 +70,12 @@ def scenario_name(keyword, name, file_colon_line, source_indent) def before_step(step) unless @outline and @options[:expand] @gf.step(step.gherkin_statement) + pass_delayed_output + @delay_output = false else if @in_instantiated_scenario @current_step_hash = to_hash(step.gherkin_statement) + @delay_output = true end end if @print_empty_match @@ -114,6 +122,8 @@ def step_name(keyword, step_match, status, source_indent, background, file_colon @current_step_hash['line'], @current_step_hash['rows'], @current_step_hash['doc_string'])) + pass_delayed_output + @delay_output = false @gf.match(@current_match) @gf.result(@current_result) end @@ -159,11 +169,19 @@ def embed(file, mime_type, label) if defined?(JRUBY_VERSION) data = data.to_java_bytes end - @gf.embedding(mime_type, data) + unless @delay_output + @gf.embedding(mime_type, data) + else + @delayed_embeddings.push [mime_type, data] + end end def puts(message) - @gf.write(message) + unless @delay_output + @gf.write(message) + else + @delayed_messages.push message + end end private @@ -175,6 +193,13 @@ def to_hash(gherkin_statement) gherkin_statement.to_hash end end + + def pass_delayed_output + @delayed_messages.each { |message| @gf.write(message) } + @delayed_embeddings.each { |embed_data| @gf.embedding(embed_data[0], embed_data[1]) } + @delayed_messages = [] + @delayed_embeddings = [] + end end end end