Class: Turnip::Builder::ScenarioOutline

Inherits:
Object
  • Object
show all
Includes:
Name, Tags
Defined in:
lib/turnip/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Name

#name

Methods included from Tags

#metadata_hash, #tags, #tags_hash

Constructor Details

#initialize(raw) ⇒ ScenarioOutline

Returns a new instance of ScenarioOutline.



77
78
79
80
# File 'lib/turnip/builder.rb', line 77

def initialize(raw)
  @raw = raw
  @steps = []
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



75
76
77
# File 'lib/turnip/builder.rb', line 75

def steps
  @steps
end

Instance Method Details

#to_scenarios(examples) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/turnip/builder.rb', line 82

def to_scenarios(examples)
  rows = examples.rows.map(&:cells)
  headers = rows.shift
  rows.map do |row|
    Scenario.new(@raw).tap do |scenario|
      scenario.steps = steps.map do |step|
        new_description = substitute(step.description, headers, row)
        new_extra_args = step.extra_args.map do |ea|
          next ea unless ea.instance_of?(Turnip::Table)
          Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
        end
        Step.new(new_description, new_extra_args, step.line)
      end
    end
  end
end