Skip to content

Commit

Permalink
Merge branch 'turn-ast-inside-out'
Browse files Browse the repository at this point in the history
  • Loading branch information
tooky committed May 13, 2013
2 parents 001a20b + b6e1a1c commit ed33297
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 230 deletions.
19 changes: 11 additions & 8 deletions lib/cucumber/ast/background.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Background #:nodoc:
include Names
include HasLocation
attr_accessor :feature
attr_accessor :comment

def initialize(language, location, comment, keyword, title, description, raw_steps)
@language, @location, @comment, @keyword, @title, @description, @raw_steps = language, location, comment, keyword, title, description, raw_steps
Expand Down Expand Up @@ -36,14 +37,16 @@ def step_collection(scenario_step_invocations)

def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_background_name(@keyword, name, file_colon_line, source_indent(first_line_length))
with_visitor(hook_context, visitor) do
visitor.runtime.before(hook_context)
skip_invoke! if failed?
visitor.visit_steps(step_invocations)
@failed = step_invocations.any? { |step_invocation| step_invocation.exception || step_invocation.status != :passed }
visitor.runtime.after(hook_context) if @failed || feature_elements.empty?
visitor.visit_background(self) do
comment.accept(visitor)
visitor.visit_background_name(@keyword, name, file_colon_line, source_indent(first_line_length))
with_visitor(hook_context, visitor) do
visitor.runtime.before(hook_context)
skip_invoke! if failed?
step_invocations.accept(visitor)
@failed = step_invocations.any? { |step_invocation| step_invocation.exception || step_invocation.status != :passed }
visitor.runtime.after(hook_context) if @failed || feature_elements.empty?
end
end
end

Expand Down
7 changes: 5 additions & 2 deletions lib/cucumber/ast/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def empty?

def accept(visitor)
return if Cucumber.wants_to_quit
@value.strip.split("\n").each do |line|
visitor.visit_comment_line(line.strip)
return if empty?
visitor.visit_comment(self) do
@value.strip.split("\n").each do |line|
visitor.visit_comment_line(line.strip)
end
end
end

Expand Down
12 changes: 7 additions & 5 deletions lib/cucumber/ast/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Ast
class Examples #:nodoc:
include Names
include HasLocation
attr_writer :outline_table
attr_reader :comment, :keyword, :outline_table

def initialize(location, comment, keyword, title, description, outline_table)
@location, @comment, @keyword, @title, @description, @outline_table = location, comment, keyword, title, description, outline_table
Expand All @@ -20,9 +20,11 @@ def gherkin_statement(statement=nil)

def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_examples_name(@keyword, name)
visitor.visit_outline_table(@outline_table)
visitor.visit_examples(self) do
comment.accept(visitor)
visitor.visit_examples_name(keyword, name)
outline_table.accept(visitor)
end
end

def skip_invoke!
Expand All @@ -39,7 +41,7 @@ def failed?

def to_sexp
sexp = [:examples, @keyword, name]
comment = @comment.to_sexp
comment = comment.to_sexp
sexp += [comment] if comment
sexp += [@outline_table.to_sexp]
sexp
Expand Down
15 changes: 9 additions & 6 deletions lib/cucumber/ast/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Feature #:nodoc:

attr_accessor :language
attr_reader :feature_elements
attr_reader :comment, :background, :tags

def initialize(location, background, comment, tags, keyword, title, description, feature_elements)
@background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, tags, keyword, title, description, feature_elements
Expand All @@ -30,12 +31,14 @@ def step_count

def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_tags(@tags)
visitor.visit_feature_name(@keyword, indented_name)
visitor.visit_background(@background) if !@background.is_a?(EmptyBackground)
@feature_elements.each do |feature_element|
visitor.visit_feature_element(feature_element)
visitor.visit_feature(self) do
comment.accept(visitor)
tags.accept(visitor)
visitor.visit_feature_name(@keyword, indented_name)
background.accept(visitor)
@feature_elements.each do |feature_element|
feature_element.accept(visitor)
end
end
end

Expand Down
10 changes: 6 additions & 4 deletions lib/cucumber/ast/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ def add_feature(feature)

def accept(visitor)
return if Cucumber.wants_to_quit
start = Time.now
self.each do |feature|
visitor.visit_feature(feature)
visitor.visit_features(self) do
start = Time.now
self.each do |feature|
feature.accept(visitor)
end
@duration = Time.now - start
end
@duration = Time.now - start
end

def step_count
Expand Down
55 changes: 20 additions & 35 deletions lib/cucumber/ast/outline_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,16 @@ def initialize(raw, scenario_outline)
super(raw)
@scenario_outline = scenario_outline
@cells_class = ExampleRow
init
end

def init
create_step_invocations_for_example_rows!(@scenario_outline)
end

def to_sexp
init
super
example_rows.each do |cells|
cells.create_step_invocations!(scenario_outline)
end
end

def accept(visitor)
return if Cucumber.wants_to_quit
init
cells_rows.each_with_index do |row, n|
if(visitor.configuration.expand?)
visitor.visit_outline_table(self) do
cells_rows.each do |row|
row.accept(visitor)
else
visitor.visit_table_row(row)
end
end
nil
Expand All @@ -43,20 +33,11 @@ def source_tag_names
end

def skip_invoke!
init
example_rows.each do |cells|
cells.skip_invoke!
end
end

def create_step_invocations_for_example_rows!(scenario_outline)
return if @dunit
@dunit = true
example_rows.each do |cells|
cells.create_step_invocations!(scenario_outline)
end
end

def example_rows
cells_rows[1..-1]
end
Expand Down Expand Up @@ -104,14 +85,20 @@ def skip_invoke!

def accept(visitor)
return if Cucumber.wants_to_quit
visitor.configuration.expand? ? accept_expand(visitor) : accept_plain(visitor)
if visitor.configuration.expand?
accept_expand(visitor)
else
visitor.visit_table_row(self) do
accept_plain(visitor)
end
end
end

def accept_plain(visitor)
if header?
@cells.each do |cell|
cell.status = :skipped_param
visitor.visit_table_cell(cell)
cell.accept(visitor)
end
else
visitor.runtime.with_hooks(self) do
Expand All @@ -121,7 +108,7 @@ def accept_plain(visitor)
end

@cells.each do |cell|
visitor.visit_table_cell(cell)
cell.accept(visitor)
end

visitor.visit_exception(@scenario_exception, :failed) if @scenario_exception
Expand All @@ -130,14 +117,12 @@ def accept_plain(visitor)
end

def accept_expand(visitor)
if header?
else
visitor.runtime.with_hooks(self) do
@table.visit_scenario_name(visitor, self)
@step_invocations.each do |step_invocation|
visitor.visit_step(step_invocation)
@exception ||= step_invocation.reported_exception
end
return if header?
visitor.runtime.with_hooks(self) do
@table.visit_scenario_name(visitor, self)
@step_invocations.each do |step_invocation|
step_invocation.accept(visitor)
@exception ||= step_invocation.reported_exception
end
end
end
Expand Down
18 changes: 10 additions & 8 deletions lib/cucumber/ast/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Scenario #:nodoc:

attr_reader :feature_tags
attr_accessor :feature
attr_reader :comment, :tags, :keyword

def initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps)
@language, @location, @background, @comment, @tags, @feature_tags, @keyword, @title, @description, @raw_steps = language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps
Expand All @@ -23,15 +24,16 @@ def initialize(language, location, background, comment, tags, feature_tags, keyw
def accept(visitor)
return if Cucumber.wants_to_quit

visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_tags(@tags)
visitor.visit_scenario_name(@keyword, name, file_colon_line, source_indent(first_line_length))

skip_invoke! if @background.failed?
with_visitor(visitor) do
visitor.execute(self, skip_hooks?)
visitor.visit_feature_element(self) do
comment.accept(visitor)
tags.accept(visitor)
visitor.visit_scenario_name(keyword, name, file_colon_line, source_indent(first_line_length))
skip_invoke! if @background.failed?
with_visitor(visitor) do
visitor.execute(self, skip_hooks?)
end
@executed = true
end
@executed = true
end

def to_units(background)
Expand Down
30 changes: 15 additions & 15 deletions lib/cucumber/ast/scenario_outline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class ScenarioOutline #:nodoc:

attr_accessor :feature
attr_reader :feature_tags
attr_reader :comment, :tags, :keyword

module ExamplesArray #:nodoc:
def accept(visitor)
return if self.empty?
return if Cucumber.wants_to_quit
each do |examples|
visitor.visit_examples(examples)
visitor.visit_examples_array(self) do
each do |examples|
examples.accept(visitor)
end
end
end
end
Expand All @@ -35,14 +39,14 @@ def initialize(language, location, background, comment, tags, feature_tags, keyw
def accept(visitor)
return if Cucumber.wants_to_quit
raise_missing_examples_error unless @example_sections

visitor.visit_comment(@comment) unless @comment.empty?
visitor.visit_tags(@tags)
visitor.visit_scenario_name(@keyword, name, file_colon_line, source_indent(first_line_length))
visitor.visit_steps(steps)

skip_invoke! if @background.failed?
visitor.visit_examples_array(examples_array) unless examples_array.empty?
visitor.visit_feature_element(self) do
comment.accept(visitor)
tags.accept(visitor)
visitor.visit_scenario_name(keyword, name, file_colon_line, source_indent(first_line_length))
steps.accept(visitor)
skip_invoke! if @background.failed?
examples_array.accept(visitor)
end
end

def to_units(background)
Expand All @@ -65,11 +69,7 @@ def skip_invoke!

def step_invocations(cells)
step_invocations = steps.step_invocations_from_cells(cells)
if @background
@background.step_collection(step_invocations)
else
StepCollection.new(step_invocations)
end
@background.step_collection(step_invocations)
end

def each_example_row(&proc)
Expand Down
8 changes: 5 additions & 3 deletions lib/cucumber/ast/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ def step_invocation_from_cells(cells)

def accept(visitor)
return if Cucumber.wants_to_quit
# The only time a Step is visited is when it is in a ScenarioOutline.
# Otherwise it's always StepInvocation that gets visited instead.
visit_step_result(visitor, first_match(visitor), @multiline_arg, :skipped, nil, nil)
visitor.visit_step(self) do
# The only time a Step is visited is when it is in a ScenarioOutline.
# Otherwise it's always StepInvocation that gets visited instead.
visit_step_result(visitor, first_match(visitor), @multiline_arg, :skipped, nil, nil)
end
end

def visit_step_result(visitor, step_match, multiline_arg, status, exception, background)
Expand Down
6 changes: 4 additions & 2 deletions lib/cucumber/ast/step_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def inspect

def accept(visitor)
return if Cucumber.wants_to_quit
@steps.each do |step|
visitor.visit_step(step)
visitor.visit_steps(self) do
@steps.each do |step|
step.accept(visitor)
end
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/cucumber/ast/step_invocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def skip_invoke!

def accept(visitor)
return if Cucumber.wants_to_quit
invoke(visitor.runtime, visitor.configuration)
visit_step_result(visitor)
visitor.visit_step(self) do # TODO: consider using visit_step_invocation here
invoke(visitor.runtime, visitor.configuration)
visit_step_result(visitor)
end
end

def visit_step_result(visitor)
Expand Down
12 changes: 8 additions & 4 deletions lib/cucumber/ast/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def each_cells_row(&proc) #:nodoc:
def accept(visitor) #:nodoc:
return if Cucumber.wants_to_quit
cells_rows.each do |row|
visitor.visit_table_row(row)
row.accept(visitor)
end
nil
end
Expand Down Expand Up @@ -632,8 +632,10 @@ def initialize(table, cells)

def accept(visitor)
return if Cucumber.wants_to_quit
each do |cell|
visitor.visit_table_cell(cell)
visitor.visit_table_row(self) do
each do |cell|
cell.accept(visitor)
end
end
nil
end
Expand Down Expand Up @@ -688,7 +690,9 @@ def initialize(value, table, line)

def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_table_cell_value(value, status)
visitor.visit_table_cell(self) do
visitor.visit_table_cell_value(value, status)
end
end

def inspect!
Expand Down
Loading

0 comments on commit ed33297

Please sign in to comment.