Skip to content

Commit

Permalink
Handle incomplete examples to scenario outlines. Fixes #109.
Browse files Browse the repository at this point in the history
Gherkin v4.0 is more allowing with respect to incomplete scenario
outlines, therefore Cucumber::Core::Gherkin::AstBuilder need to also be
that.
  • Loading branch information
brasmusson committed Jul 3, 2016
1 parent c80ecb4 commit c3b42a1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Bugfixes

* Handle incomplete examples to scenario outlines. ([109](https://github.com/cucumber/cucumber-ruby-core/pull/109) @brasmusson)
* Add with_filtered_backtrace method to unknown result ([107](https://github.com/cucumber/cucumber-ruby-core/pull/107) @dansscheider)

## [v1.5.0](https://github.com/cucumber/cucumber-ruby-core/compare/v1.4.0...v1.5.0)
Expand Down
18 changes: 13 additions & 5 deletions lib/cucumber/core/gherkin/ast_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ScenarioOutlineBuilder < Builder
def initialize(*)
super
@step_builders = attributes[:steps].map { |step| OutlineStepBuilder.new(file, step) }
@example_builders = attributes[:examples].map { |example| ExamplesTableBuilder.new(file, example) }
@example_builders = attributes[:examples] ? attributes[:examples].map { |example| ExamplesTableBuilder.new(file, example) } : []
end

def result(language)
Expand Down Expand Up @@ -306,10 +306,8 @@ class ExamplesTableBuilder < Builder

def initialize(*)
super
@header_builder = HeaderBuilder.new(file, attributes[:table_header])
@example_rows_builders = attributes[:table_body].map do |row_attributes|
ExampleRowBuilder.new(file, row_attributes)
end
@header_builder = attributes[:table_header] ? HeaderBuilder.new(file, attributes[:table_header]) : NullHeaderBuilder.new
@example_rows_builders = attributes[:table_body] ? attributes[:table_body].map { |row_attributes| ExampleRowBuilder.new(file, row_attributes) } : []
end

def result(language)
Expand Down Expand Up @@ -342,6 +340,16 @@ def result
end
end

class NullHeaderBuilder < Builder
def initialize
@line = -1 # this inhibits Builder#handle_comments to put any comments in this object.
end

def result
nil
end
end

def children
[header_builder] + example_rows_builders
end
Expand Down
23 changes: 23 additions & 0 deletions spec/cucumber/core/gherkin/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ def feature

end

context "a Scenario Outline with an empty examples table" do
source do
feature do
scenario_outline 'outline name' do
step 'passing <arg>'

examples do
end
end
end
end

it "creates an examples table node but no example table rows" do
allow( visitor ).to receive(:feature).and_yield(visitor)
allow( visitor ).to receive(:scenario_outline).and_yield(visitor)
allow( visitor ).to receive(:outline_step)
expect( visitor ).to receive(:examples_table).and_yield(visitor)
expect( visitor ).to receive(:examples_table_row).exactly(0).times
feature.describe_to(visitor)
end

end

context "a Scenario Outline with no Examples" do
source do
feature(language: 'not-a-language')
Expand Down

0 comments on commit c3b42a1

Please sign in to comment.