Class: Cucumber::Ast::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/ast/scenario.rb

Direct Known Subclasses

Background, ScenarioOutline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment, tags, line, keyword, name, steps) ⇒ Scenario

Returns a new instance of Scenario.



6
7
8
9
10
11
# File 'lib/cucumber/ast/scenario.rb', line 6

def initialize(comment, tags, line, keyword, name, steps)
  @comment, @tags, @line, @keyword, @name = comment, tags, line, keyword, name
  steps.each {|step| step.scenario = self}
  @steps = steps
  @steps_helper = Steps.new(self)
end

Instance Attribute Details

#background=(value) ⇒ Object (writeonly)

Sets the attribute background

Parameters:

  • value

    the value to set the attribute background to.



4
5
6
# File 'lib/cucumber/ast/scenario.rb', line 4

def background=(value)
  @background = value
end

#feature=(value) ⇒ Object (writeonly)

Sets the attribute feature

Parameters:

  • value

    the value to set the attribute feature to.



4
5
6
# File 'lib/cucumber/ast/scenario.rb', line 4

def feature=(value)
  @feature = value
end

Instance Method Details

#accept(visitor) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/cucumber/ast/scenario.rb', line 25

def accept(visitor)
  visitor.visit_background(@background) if @background
  visitor.visit_comment(@comment)
  visitor.visit_tags(@tags)
  visitor.visit_scenario_name(@keyword, @name, file_line(@line), source_indent(text_length))
  visitor.visit_steps(@steps_helper)

  @feature.scenario_executed(self) if @feature && !@executed
  @executed = true
end

#accept_steps(visitor) ⇒ Object



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

def accept_steps(visitor)
  prior_world = @background ? @background.world : nil
  visitor.world(self, prior_world) do |world|
    previous = @background ? @background.status : :passed
    @steps.each do |step|
      step.previous = previous
      step.world    = world
      visitor.visit_step(step)
      previous = step.status
    end
  end
end

#at_header_or_step_lines?(lines) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/cucumber/ast/scenario.rb', line 66

def at_header_or_step_lines?(lines)
  lines.empty? || lines.index(@line) || @steps.detect {|step| step.at_lines?(lines)} || @tags.at_lines?(lines)
end

#at_lines?(lines) ⇒ Boolean

Returns:

  • (Boolean)


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

def at_lines?(lines)
  at_header_or_step_lines?(lines)
end

#backtrace_line(name = "#{@keyword} #{@name}", line = @line) ⇒ Object



78
79
80
# File 'lib/cucumber/ast/scenario.rb', line 78

def backtrace_line(name = "#{@keyword} #{@name}", line = @line)
  @feature.backtrace_line(name, line) if @feature
end

#file_line(line = @line) ⇒ Object



82
83
84
# File 'lib/cucumber/ast/scenario.rb', line 82

def file_line(line = @line)
  @feature.file_line(line) if @feature
end

#matches_scenario_names?(scenario_names) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cucumber/ast/scenario.rb', line 21

def matches_scenario_names?(scenario_names)
  scenario_names.detect{|name| @name == name}
end

#max_line_lengthObject



53
54
55
56
# File 'lib/cucumber/ast/scenario.rb', line 53

def max_line_length
  lengths = (@steps + [self]).map{|e| e.text_length}
  lengths.max
end

#previous_step(step) ⇒ Object



86
87
88
89
# File 'lib/cucumber/ast/scenario.rb', line 86

def previous_step(step)
  i = @steps.index(step) || -1
  @steps[i-1]
end

#source_indent(text_length) ⇒ Object



49
50
51
# File 'lib/cucumber/ast/scenario.rb', line 49

def source_indent(text_length)
  max_line_length - text_length
end

#statusObject



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

def status
  @steps.map{|step| step.status}
end

#step_executed(step) ⇒ Object



74
75
76
# File 'lib/cucumber/ast/scenario.rb', line 74

def step_executed(step)
  @feature.step_executed(step) if @feature
end

#tagged_with?(tag_names) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cucumber/ast/scenario.rb', line 17

def tagged_with?(tag_names)
  @tags.among?(tag_names) || @feature.tagged_with?(tag_names, false)
end

#text_lengthObject



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

def text_length
  @keyword.jlength + @name.jlength
end

#to_sexpObject



91
92
93
94
95
96
97
98
99
100
# File 'lib/cucumber/ast/scenario.rb', line 91

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

#undefined?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/cucumber/ast/scenario.rb', line 70

def undefined?
  @steps.empty?
end