Class: Cucumber::Ast::ScenarioOutline

Inherits:
Object
  • Object
show all
Includes:
FeatureElement
Defined in:
lib/cucumber/ast/scenario_outline.rb

Instance Method Summary collapse

Methods included from FeatureElement

#attach_steps, #backtrace_line, #file_colon_line, #has_tags?, #matches_lines?, #matches_scenario_names?, #max_line_length, #previous_step, #source_indent, #text_length

Constructor Details

#initialize(background, comment, tags, line, keyword, name, 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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cucumber/ast/scenario_outline.rb', line 12

def initialize(background, comment, tags, line, keyword, name, steps, example_sections)
  @background, @comment, @tags, @line, @keyword, @name = background, comment, tags, line, keyword, name
  attach_steps(steps)
  @steps = StepCollection.new(steps)

  @examples_array = example_sections.map do |example_section|
    examples_line       = example_section[0]
    examples_keyword    = example_section[1]
    examples_name       = example_section[2]
    examples_matrix     = example_section[3]

    examples_table = OutlineTable.new(examples_matrix, self)
    Examples.new(examples_line, examples_keyword, examples_name, examples_table)
  end
end

Instance Method Details

#accept(visitor) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cucumber/ast/scenario_outline.rb', line 43

def accept(visitor)
  visitor.visit_comment(@comment)
  visitor.visit_tags(@tags)
  visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(text_length))
  visitor.visit_steps(@steps)

  skip_invoke! if @background && @background.failed?
  @examples_array.each do |examples|
    visitor.visit_examples(examples) if examples.descend?(visitor)
  end
end

#descend?(visitor) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cucumber/ast/scenario_outline.rb', line 33

def descend?(visitor)
  @examples_array.detect { |examples| examples.descend?(visitor) }
end

#each_example_row(&proc) ⇒ Object



71
72
73
74
75
# File 'lib/cucumber/ast/scenario_outline.rb', line 71

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

#feature=(feature) ⇒ Object



28
29
30
31
# File 'lib/cucumber/ast/scenario_outline.rb', line 28

def feature=(feature)
  @feature = feature
  @background.feature = feature if @background
end

#matches_tags_and_name?(visitor) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/cucumber/ast/scenario_outline.rb', line 37

def matches_tags_and_name?(visitor)
  visitor.included_by_tags?(self) &&
  !visitor.excluded_by_tags?(self) &&
  visitor.matches_scenario_names?(self)
end

#skip_invoke!Object



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

def skip_invoke!
  @examples_array.each{|examples| examples.skip_invoke!}
  @feature.next_feature_element(self) do |next_one|
    next_one.skip_invoke!
  end
end

#step_invocations(cells) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/cucumber/ast/scenario_outline.rb', line 62

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



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cucumber/ast/scenario_outline.rb', line 77

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?
  steps = @steps.to_sexp
  sexp += steps if steps.any?
  sexp += @examples_array.map{|e| e.to_sexp}
  sexp
end