From ef215e64ff5e4438961cd12130112d9e353e8e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Rasmusson?= Date: Sat, 14 Feb 2015 14:55:39 +0100 Subject: [PATCH] Delay step output until after step has been called. Fixed #806. Delay sending the step output to the gherkin formatter in the JSONFormatter, also for Scenario Outlines in expanded mode, until step has been called on the gherkin formatter. --- .../docs/formatters/json_formatter.feature | 66 ++++++++++++++++++- .../formatter/gherkin_formatter_adapter.rb | 15 +++-- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/features/docs/formatters/json_formatter.feature b/features/docs/formatters/json_formatter.feature index 0add9b82f8..2d3b303809 100644 --- a/features/docs/formatters/json_formatter.feature +++ b/features/docs/formatters/json_formatter.feature @@ -82,6 +82,14 @@ Feature: JSON output formatter Scenario: Given I embed data directly + Scenario Outline: + Given I embed data directly + + Examples: + | dummy | + | 1 | + | 2 | + """ And a file named "features/out_scenario_out_scenario_outline.feature" with: """ @@ -613,7 +621,7 @@ Feature: JSON output formatter @spawn 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: """ [ @@ -652,6 +660,62 @@ Feature: JSON output formatter } } ] + }, + { + "keyword": "Scenario Outline", + "name": "", + "line": 11, + "description": "", + "id": "an-embed-data-directly-feature;;;2", + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "I embed data directly", + "line": 11, + "embeddings": [ + { + "mime_type": "mime-type", + "data": "YWJj" + } + ], + "match": { + "location": "features/step_definitions/json_steps.rb:10" + }, + "result": { + "status": "passed", + "duration": 1 + } + } + ] + }, + { + "keyword": "Scenario Outline", + "name": "", + "line": 12, + "description": "", + "id": "an-embed-data-directly-feature;;;3", + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "I embed data directly", + "line": 12, + "embeddings": [ + { + "mime_type": "mime-type", + "data": "YWJj" + } + ], + "match": { + "location": "features/step_definitions/json_steps.rb:10" + }, + "result": { + "status": "passed", + "duration": 1 + } + } + ] } ] } diff --git a/lib/cucumber/formatter/gherkin_formatter_adapter.rb b/lib/cucumber/formatter/gherkin_formatter_adapter.rb index d6c72b5d46..0c61046dcc 100644 --- a/lib/cucumber/formatter/gherkin_formatter_adapter.rb +++ b/lib/cucumber/formatter/gherkin_formatter_adapter.rb @@ -21,12 +21,10 @@ def before_feature(feature) def before_background(background) @outline = false - @before_steps = true @gf.background(background.gherkin_statement) end def before_feature_element(feature_element) - @before_steps = true case(feature_element) when Core::Ast::Scenario @outline = false @@ -44,6 +42,10 @@ def before_feature_element(feature_element) end end + def before_test_case(test_case) + @delay_output = true + end + def scenario_name(keyword, name, file_colon_line, source_indent) if @outline and @options[:expand] return if not @in_instantiated_scenario @@ -70,10 +72,11 @@ def before_step(step) unless @outline and @options[:expand] @gf.step(step.gherkin_statement) pass_delayed_output - @before_steps = false + @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 @@ -120,7 +123,7 @@ def step_name(keyword, step_match, status, source_indent, background, file_colon @current_step_hash['rows'], @current_step_hash['doc_string'])) pass_delayed_output - @before_steps = false + @delay_output = false @gf.match(@current_match) @gf.result(@current_result) end @@ -165,7 +168,7 @@ def embed(file, mime_type, label) if defined?(JRUBY_VERSION) data = data.to_java_bytes end - unless @before_steps + unless @delay_output @gf.embedding(mime_type, data) else @delayed_embeddings.push [mime_type, data] @@ -173,7 +176,7 @@ def embed(file, mime_type, label) end def puts(message) - unless @before_steps + unless @delay_output @gf.write(message) else @delayed_messages.push message