Class: Cucumber::Ast::ScenarioOutline

Inherits:
Object
  • Object
show all
Includes:
HasLocation, HasSteps, Names
Defined in:
lib/cucumber/ast/scenario_outline.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ExamplesArray

Instance Attribute Summary collapse

Attributes included from Names

#description, #title

Attributes included from HasSteps

#description, #gherkin_statement, #raw_steps, #title

Instance Method Summary collapse

Methods included from HasLocation

#file, #file_colon_line, #location

Methods included from Names

#name

Methods included from HasSteps

#accept_hook?, #attach_steps, #backtrace_line, #first_line_length, #language, #matches_scenario_names?, #max_line_length, #name_line_lengths, #source_indent, #source_tag_names, #source_tags, #text_length

Constructor Details

#initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps, example_sections) ⇒ ScenarioOutline

The example_sections argument must be an Array where each element is another array representing an Examples section. This array has 3 elements:

  • Examples keyword

  • Examples section name

  • Raw matrix



30
31
32
33
# File 'lib/cucumber/ast/scenario_outline.rb', line 30

def initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps, example_sections)
  @language, @location, @background, @comment, @tags, @feature_tags, @keyword, @title, @description, @raw_steps, @example_sections = language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps, example_sections
  attach_steps(@raw_steps)
end

Instance Attribute Details

#featureObject

Returns the value of attribute feature.



12
13
14
# File 'lib/cucumber/ast/scenario_outline.rb', line 12

def feature
  @feature
end

#feature_tagsObject (readonly)

Returns the value of attribute feature_tags.



13
14
15
# File 'lib/cucumber/ast/scenario_outline.rb', line 13

def feature_tags
  @feature_tags
end

Instance Method Details

#accept(visitor) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber/ast/scenario_outline.rb', line 35

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?
end

#each_example_row(&proc) ⇒ Object



75
76
77
78
79
# File 'lib/cucumber/ast/scenario_outline.rb', line 75

def each_example_row(&proc)
  examples_array.each do |examples|
    examples.each_example_row(&proc)
  end
end

#fail!(exception) ⇒ Object



57
58
59
60
# File 'lib/cucumber/ast/scenario_outline.rb', line 57

def fail!(exception)
  # Just a hack for https://rspec.lighthouseapp.com/projects/16211/tickets/413-scenario-outlines-that-fail-with-exception-exit-process
  # Also see http://groups.google.com/group/cukes/browse_thread/thread/41cd567cb9df4bc3
end

#failed?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/cucumber/ast/scenario_outline.rb', line 90

def failed?
  examples_array.select { |examples| examples.failed? }.any?
end

#skip_invoke!Object



62
63
64
# File 'lib/cucumber/ast/scenario_outline.rb', line 62

def skip_invoke!
  examples_array.each { |examples| examples.skip_invoke! }
end

#step_invocations(cells) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/cucumber/ast/scenario_outline.rb', line 66

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
end

#to_sexpObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/cucumber/ast/scenario_outline.rb', line 94

def to_sexp
  sexp = [:scenario_outline, @keyword, name]
  comment = @comment.to_sexp
  sexp += [comment] if comment
  tags = @tags.to_sexp
  sexp += tags if tags.any?
  sexp += steps.to_sexp if steps.any?
  sexp += examples_array.map{|e| e.to_sexp}
  sexp
end

#to_units(background) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
# File 'lib/cucumber/ast/scenario_outline.rb', line 48

def to_units(background)
  raise ArgumentError.new("#{background} != #{@background}") unless background == @background # maybe we don't need this argument, but it seems like the leaf AST nodes would be better not being aware of their parents. However step_invocations uses the ivar at the moment, so we'll just do this check to make sure its OK.
  result = []
  each_example_row do |row|
    result << Unit.new(step_invocations(row))
  end
  result
end

#visit_scenario_name(visitor, row) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/cucumber/ast/scenario_outline.rb', line 81

def visit_scenario_name(visitor, row)
  visitor.visit_scenario_name(
    language.keywords('scenario')[0],
    row.name,
    Location.new(file, row.line).to_s,
    source_indent(first_line_length)
  )
end