Class: Lucid::AST::Background
Overview
Instance Attribute Summary collapse
Attributes included from Names
#description, #title
Attributes included from HasSteps
#description, #gherkin_statement, #raw_steps, #title
Instance Method Summary
collapse
#file, #file_colon_line, #line, #location
Methods included from Names
#name
Methods included from HasSteps
#attach_steps, #backtrace_line, #first_line_length, #language, #matches_scenario_names?, #max_line_length, #name_line_lengths, #source_indent, #text_length
Constructor Details
#initialize(language, location, comment, keyword, title, description, raw_steps) ⇒ Background
Returns a new instance of Background.
14
15
16
17
18
19
|
# File 'lib/lucid/ast/background.rb', line 14
def initialize(language, location, , keyword, title, description, raw_steps)
@language, @location, @comment, @keyword, @title, @description, @raw_steps = language, location, , keyword, title, description, raw_steps
@failed = nil
@first_collection_created = false
attach_steps(@raw_steps)
end
|
Instance Attribute Details
Returns the value of attribute comment.
12
13
14
|
# File 'lib/lucid/ast/background.rb', line 12
def
@comment
end
|
Returns the value of attribute feature.
11
12
13
|
# File 'lib/lucid/ast/background.rb', line 11
def feature
@feature
end
|
Instance Method Details
#accept(visitor) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/lucid/ast/background.rb', line 38
def accept(visitor)
return if @already_visited
visitor.visit_background(self) do
.accept(visitor)
visitor.visit_background_name(@keyword, name, file_colon_line, source_indent(first_line_length))
with_visitor(hook_context, visitor) do
visitor.runtime.before(hook_context)
skip_invoke! if failed?
step_invocations.accept(visitor)
@failed = step_invocations.any? { |step_invocation| step_invocation.exception || step_invocation.status != :passed }
visitor.runtime.after(hook_context) if @failed || feature_elements.empty?
end
end
@already_visited = true
end
|
#accept_hook?(hook) ⇒ Boolean
65
66
67
68
69
70
71
72
|
# File 'lib/lucid/ast/background.rb', line 65
def accept_hook?(hook)
if hook_context != self
hook_context.accept_hook?(hook)
else
feature.accept_hook?(hook)
end
end
|
#create_step_invocations(scenario_step_invocations) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/lucid/ast/background.rb', line 29
def create_step_invocations(scenario_step_invocations)
if(@first_collection_created)
steps.step_invocations(true).dup(scenario_step_invocations)
else
@first_collection_created = true
step_invocations.dup(scenario_step_invocations)
end
end
|
#fail!(exception) ⇒ Object
95
96
97
98
99
|
# File 'lib/lucid/ast/background.rb', line 95
def fail!(exception)
@failed = true
@exception = exception
@current_visitor.visit_exception(@exception, :failed)
end
|
#failed? ⇒ Boolean
78
79
80
|
# File 'lib/lucid/ast/background.rb', line 78
def failed?
!!@failed
end
|
#feature_elements ⇒ Object
21
22
23
|
# File 'lib/lucid/ast/background.rb', line 21
def feature_elements
feature.feature_elements
end
|
#hook_context ⇒ Object
82
83
84
|
# File 'lib/lucid/ast/background.rb', line 82
def hook_context
feature_elements.first || self
end
|
#skip_invoke! ⇒ Object
74
75
76
|
# File 'lib/lucid/ast/background.rb', line 74
def skip_invoke!
step_invocations.each{|step_invocation| step_invocation.skip_invoke!}
end
|
#source_tag_names ⇒ Object
108
109
110
|
# File 'lib/lucid/ast/background.rb', line 108
def source_tag_names
source_tags.map { |tag| tag.name }
end
|
Override this method, as there are situations where the background wind up being the one called fore Before scenarios, and backgrounds don’t have tags.
104
105
106
|
# File 'lib/lucid/ast/background.rb', line 104
def source_tags
[]
end
|
#step_invocations ⇒ Object
25
26
27
|
# File 'lib/lucid/ast/background.rb', line 25
def step_invocations
@step_invocations ||= steps.step_invocations(true)
end
|
86
87
88
89
90
91
92
93
|
# File 'lib/lucid/ast/background.rb', line 86
def to_sexp
sexp = [:background, line, @keyword]
sexp += [name] unless name.empty?
= @comment.to_sexp
sexp += [] if
sexp += steps.to_sexp if steps.any?
sexp
end
|
#with_visitor(scenario, visitor) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/lucid/ast/background.rb', line 54
def with_visitor(scenario, visitor)
@current_visitor = visitor
if self != scenario && scenario.respond_to?(:with_visitor)
scenario.with_visitor(visitor) do
yield
end
else
yield
end
end
|