Skip to content

Commit

Permalink
Pass tags and comments to legacy api formatters correctly
Browse files Browse the repository at this point in the history
Examples tables can have tags, so these needs to be passed to the
legacy api formatters. Backgrounds, Scenarios, Scenario Outlines,
Steps, Examples tables and Examples tables row can have comments, so
these needs to be passed to the legacy api formatters.
  • Loading branch information
brasmusson committed Jun 7, 2015
1 parent 9f60aa0 commit 95bcefa
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/cucumber/formatter/legacy_api/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def after_hook(*)

def before
formatter.before_background Ast::Background.new(feature, node)
Ast::Comments.new(node.comments).accept(formatter)
formatter.background_name node.keyword, node.legacy_conflated_name_and_description, node.location.to_s, indent.of(node)
before_hook_results.accept(formatter)
self
Expand Down Expand Up @@ -520,6 +521,7 @@ def after_test_case(*);end

def before
formatter.before_feature_element(node)
Ast::Comments.new(node.comments).accept(formatter)
Ast::Tags.new(node.tags).accept(formatter)
formatter.scenario_name node.keyword, node.legacy_conflated_name_and_description, node.location.to_s, indent.of(node)
before_hook_results.accept(formatter)
Expand Down Expand Up @@ -594,6 +596,7 @@ def steps

def before
formatter.before_feature_element(node)
Ast::Comments.new(node.comments).accept(formatter)
Ast::Tags.new(node.tags).accept(formatter)
formatter.scenario_name node.keyword, node.legacy_conflated_name_and_description, node.location.to_s, indent.of(node)
OutlineStepsPrinter.new(formatter, configuration, indent).print(node)
Expand Down Expand Up @@ -694,6 +697,8 @@ def after

def before
formatter.before_examples(node)
Ast::Comments.new(node.comments).accept(formatter)
Ast::Tags.new(node.tags).accept(formatter)
formatter.examples_name(node.keyword, node.legacy_conflated_name_and_description)
formatter.before_outline_table(legacy_table)
if !configuration.expand?
Expand Down Expand Up @@ -804,6 +809,7 @@ def legacy_table_row
end

def before
Ast::Comments.new(node.comments).accept(formatter)
formatter.before_table_row(node)
self
end
Expand All @@ -823,6 +829,7 @@ def after
class TableRowPrinter < TableRowPrinterBase
def before
before_hook_results.accept(formatter)
Ast::Comments.new(node.comments).accept(formatter)
formatter.before_table_row(node)
self
end
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/formatter/legacy_api/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def describe_exception_to(formatter)

def accept(formatter)
formatter.before_step(self)
Ast::Comments.new(step.comments).accept(formatter)
messages.each { |message| formatter.puts(message) }
embeddings.each { |embedding| embedding.send_to_formatter(formatter) }
formatter.before_step_result *step_result_attributes
Expand Down
38 changes: 38 additions & 0 deletions spec/cucumber/formatter/legacy_api/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -522,6 +524,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -606,6 +610,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -635,6 +641,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -701,6 +709,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -775,6 +785,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand All @@ -790,6 +802,8 @@ def after_hooks(source)
:after_outline_table,
:after_examples,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -936,6 +950,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1003,6 +1019,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1058,6 +1076,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1123,6 +1143,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1184,6 +1206,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand All @@ -1199,6 +1223,8 @@ def after_hooks(source)
:after_outline_table,
:after_examples,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1258,6 +1284,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1287,6 +1315,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1339,6 +1369,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1456,6 +1488,8 @@ def after_hooks(source)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:scenario_name,
Expand Down Expand Up @@ -1660,6 +1694,8 @@ def apply_before_hooks(test_case)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down Expand Up @@ -1814,6 +1850,8 @@ def apply_after_hooks(test_case)
:after_steps,
:before_examples_array,
:before_examples,
:before_tags,
:after_tags,
:examples_name,
:before_outline_table,
:before_table_row,
Expand Down
96 changes: 96 additions & 0 deletions spec/cucumber/formatter/pretty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,102 @@ module Formatter
1 scenario (1 passed)
2 steps (2 passed)
OUTPUT
end
end

describe "with tags on all levels" do
define_feature <<-FEATURE
@tag1
Feature:
@tag2
Scenario:
Given this step passes
@tag3
Scenario Outline:
Given this step passes
@tag4
Examples:
| dummy |
| dummy |
FEATURE


it "includes the tags in the output " do
expect( @out.string ).to include <<OUTPUT
@tag1
Feature:
@tag2
Scenario:
Given this step passes
@tag3
Scenario Outline:
Given this step passes
@tag4
Examples:
| dummy |
| dummy |
OUTPUT
end
end

describe "with comments on all levels" do
define_feature <<-FEATURE
#comment1
Feature:
#comment2
Background:
#comment3
Given this step passes
#comment4
Scenario:
#comment5
Given this step passes
#comment6
| dummy |
#comment7
Scenario Outline:
#comment8
Given this step passes
#comment9
Examples:
#comment10
| dummy |
#comment11
| dummy |
FEATURE


it "includes the all comments except for data table rows in the output " do
expect( @out.string ).to include <<OUTPUT
#comment1
Feature:
#comment2
Background:
#comment3
Given this step passes
#comment4
Scenario:
#comment5
Given this step passes
| dummy |
#comment7
Scenario Outline:
#comment8
Given this step passes
#comment9
Examples:
#comment10
| dummy |
#comment11
| dummy |
OUTPUT
end
end
Expand Down

0 comments on commit 95bcefa

Please sign in to comment.