/
scenario.rb
68 lines (57 loc) · 1.81 KB
/
scenario.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'cucumber/ast/feature_element'
module Cucumber
module Ast
class Scenario
include FeatureElement
def initialize(background, comment, tags, line, keyword, name, steps)
@background, @comment, @tags, @line, @keyword, @name = background, comment, tags, line, keyword, name
attach_steps(steps)
step_invocations = steps.map{|step| step.step_invocation}
if @background
@steps = @background.step_collection(step_invocations)
@background.feature_elements << self
else
@steps = StepCollection.new(step_invocations)
end
end
def accept(visitor)
visitor.visit_comment(@comment)
visitor.visit_tags(@tags)
visitor.visit_scenario_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
skip = @background && @background.failed?
skip_invoke! if skip
visitor.step_mother.before_and_after(self, skip) do
visitor.visit_steps(@steps)
end
end
# Returns true if one or more steps failed
def failed?
@steps.failed?
end
# Returns true if all steps passed
def passed?
@steps.passed?
end
# Returns the first exception (if any)
def exception
@steps.exception
end
def skip_invoke!
@steps.each{|step_invocation| step_invocation.skip_invoke!}
@feature.next_feature_element(self) do |next_one|
next_one.skip_invoke!
end
end
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.to_sexp
sexp += steps if steps.any?
sexp
end
end
end
end