Class: Cucumber::Ast::Background
Overview
Instance Attribute Summary collapse
#feature
Instance Method Summary
collapse
#attach_steps, #backtrace_line, #file_colon_line, #first_line_length, #language, #matches_scenario_names?, #max_line_length, #name_line_lengths, #source_indent, #source_tag_names, #tagged_with?, #text_length
Constructor Details
#initialize(comment, line, keyword, name, steps) ⇒ Background
Returns a new instance of Background.
9
10
11
12
13
14
|
# File 'lib/cucumber/ast/background.rb', line 9
def initialize(, line, keyword, name, steps)
@comment, @line, @keyword, @name, @steps = , line, keyword, name, StepCollection.new(steps)
attach_steps(steps)
@step_invocations = @steps.step_invocations(true)
@feature_elements = []
end
|
Instance Attribute Details
#feature_elements ⇒ Object
Returns the value of attribute feature_elements.
7
8
9
|
# File 'lib/cucumber/ast/background.rb', line 7
def feature_elements
@feature_elements
end
|
Instance Method Details
#accept(visitor) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/cucumber/ast/background.rb', line 25
def accept(visitor)
return if Cucumber.wants_to_quit
visitor.(@comment) unless @comment.empty?
visitor.visit_background_name(@keyword, @name, file_colon_line(@line), source_indent(first_line_length))
with_visitor(hook_context, visitor) do
visitor.step_mother.before(hook_context)
visitor.visit_steps(@step_invocations)
@failed = @step_invocations.detect{|step_invocation| step_invocation.exception}
visitor.step_mother.after(hook_context) if @failed || @feature_elements.empty?
end
end
|
#accept_hook?(hook) ⇒ Boolean
47
48
49
50
51
52
53
54
|
# File 'lib/cucumber/ast/background.rb', line 47
def accept_hook?(hook)
if hook_context != self
hook_context.accept_hook?(hook)
else
@feature.accept_hook?(hook)
end
end
|
#failed? ⇒ Boolean
56
57
58
|
# File 'lib/cucumber/ast/background.rb', line 56
def failed?
@failed
end
|
#hook_context ⇒ Object
60
61
62
|
# File 'lib/cucumber/ast/background.rb', line 60
def hook_context
@feature_elements.first || self
end
|
#step_collection(step_invocations) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/cucumber/ast/background.rb', line 16
def step_collection(step_invocations)
unless(@first_collection_created)
@first_collection_created = true
@step_invocations.dup(step_invocations)
else
@steps.step_invocations(true).dup(step_invocations)
end
end
|
64
65
66
67
68
69
70
71
72
|
# File 'lib/cucumber/ast/background.rb', line 64
def to_sexp
sexp = [:background, @line, @keyword]
sexp += [@name] unless @name.empty?
= @comment.to_sexp
sexp += [] if
steps = @steps.to_sexp
sexp += steps if steps.any?
sexp
end
|
#with_visitor(scenario, visitor) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/cucumber/ast/background.rb', line 37
def with_visitor(scenario, visitor)
if self != scenario && scenario.respond_to?(:with_visitor)
scenario.with_visitor(visitor) do
yield
end
else
yield
end
end
|