Class: Cucumber::Tree::Scenario

Inherits:
BaseScenario show all
Defined in:
lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb

Direct Known Subclasses

ScenarioOutline

Constant Summary collapse

MIN_PADDING =
2
INDENT =
2

Instance Attribute Summary collapse

Attributes inherited from BaseScenario

#feature

Instance Method Summary collapse

Methods inherited from BaseScenario

#accept, #at_line?, #file, #outline?, #pending?, #previous_step

Constructor Details

#initialize(feature, name, line, &proc) ⇒ Scenario

Returns a new instance of Scenario.



51
52
53
54
55
56
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 51

def initialize(feature, name, line, &proc)
  require 'cucumber/core_ext/string'
  @feature, @name, @line = feature, name, line
  @steps_and_given_scenarios = []
  instance_eval(&proc) if block_given?
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



49
50
51
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 49

def line
  @line
end

#nameObject (readonly)

Returns the value of attribute name.



49
50
51
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 49

def name
  @name
end

#table_column_widthsObject

Returns the value of attribute table_column_widths.



48
49
50
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 48

def table_column_widths
  @table_column_widths
end

#table_headerObject

If a table follows, the header will be stored here. Weird, but convenient.



47
48
49
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 47

def table_header
  @table_header
end

Instance Method Details

#And(name) ⇒ Object



132
133
134
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 132

def And(name)
  create_step('And', name, *caller[0].split(':')[1].to_i)
end

#create_given_scenario(name, line) ⇒ Object



114
115
116
117
118
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 114

def create_given_scenario(name, line)
  given_scenario =  GivenScenario.new(self, name, line)
  @steps_and_given_scenarios << given_scenario
  given_scenario
end

#create_step(keyword, name, line) ⇒ Object



108
109
110
111
112
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 108

def create_step(keyword, name, line)
  step = Step.new(self, keyword, name, line)
  @steps_and_given_scenarios << step
  step
end

#Given(name) ⇒ Object



120
121
122
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 120

def Given(name)
  create_step('Given', name, *caller[0].split(':')[1].to_i)
end

#given_scenario_steps(name) ⇒ Object



67
68
69
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 67

def given_scenario_steps(name)
  sibling_named(name).steps
end

#lengthObject



75
76
77
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 75

def length
  @length ||= Cucumber.language['scenario'].jlength + 2 + (@name.nil? ? 0 : @name.jlength)
end

#max_line_lengthObject



79
80
81
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 79

def max_line_length
  [length, max_step_length].max
end

#max_step_lengthObject



95
96
97
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 95

def max_step_length
  @max_step_length ||= (steps.map{|step| step.length}.max || 0)
end

#padding_lengthObject



83
84
85
86
87
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 83

def padding_length
  padding = (max_line_length - length) + MIN_PADDING
  padding += INDENT if length != max_line_length
  padding
end

#row?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 104

def row?
  false
end

#sibling_named(name) ⇒ Object



71
72
73
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 71

def sibling_named(name)
  @feature.scenario_named(name)
end

#step_padding_length(step) ⇒ Object



89
90
91
92
93
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 89

def step_padding_length(step)
  padding = (max_line_length - step.length) + MIN_PADDING
  padding -= INDENT if length == max_line_length
  padding
end

#stepsObject



63
64
65
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 63

def steps
  @steps ||= @steps_and_given_scenarios.map{|step| step.steps}.flatten
end

#Then(name) ⇒ Object



128
129
130
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 128

def Then(name)
  create_step('Then', name, *caller[0].split(':')[1].to_i)
end

#update_table_column_widths(values) ⇒ Object



99
100
101
102
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 99

def update_table_column_widths values
  @table_column_widths ||= [0] * values.size
  @table_column_widths = @table_column_widths.zip(values).map {|max, value| [max, value.size].max}
end

#When(name) ⇒ Object



124
125
126
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/tree/scenario.rb', line 124

def When(name)
  create_step('When', name, *caller[0].split(':')[1].to_i)
end