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 Jun 11, 2016
1 parent 955f09d commit cb74d70
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
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 @@ -271,7 +271,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 @@ -305,10 +305,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 @@ -341,6 +339,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 @@ -223,6 +223,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 cb74d70

Please sign in to comment.