Class: Cucumber::Ast::Background

Inherits:
Object
  • Object
show all
Includes:
FeatureElement
Defined in:
lib/cucumber/ast/background.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FeatureElement

#attach_steps, #backtrace_line, #file_colon_line, #matches_scenario_names?, #max_line_length, #previous_step, #source_indent

Constructor Details

#initialize(comment, line, keyword, name, steps) ⇒ Background

Returns a new instance of Background.



9
10
11
12
13
# File 'lib/cucumber/ast/background.rb', line 9

def initialize(comment, line, keyword, name, steps)
  @comment, @line, @keyword, @name, @steps = comment, line, keyword, name, StepCollection.new(steps)
  attach_steps(steps)
  @step_invocations = @steps.step_invocations(true)
end

Instance Attribute Details

#feature=(value) ⇒ Object (writeonly)

Sets the attribute feature

Parameters:

  • value

    the value to set the attribute feature to.



7
8
9
# File 'lib/cucumber/ast/background.rb', line 7

def feature=(value)
  @feature = value
end

Instance Method Details

#accept(visitor) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/cucumber/ast/background.rb', line 24

def accept(visitor)
  visitor.visit_comment(@comment)
  visitor.visit_background_name(@keyword, @name, file_colon_line(@line), source_indent(text_length))
  visitor.step_mother.before_and_after(self)
  visitor.visit_steps(@step_invocations)
  @failed = @step_invocations.detect{|step_invocation| step_invocation.exception}
end

#failed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cucumber/ast/background.rb', line 32

def failed?
  @failed
end

#step_collection(step_invocations) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/cucumber/ast/background.rb', line 15

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

#text_lengthObject



36
37
38
# File 'lib/cucumber/ast/background.rb', line 36

def text_length
  @keyword.jlength
end

#to_sexpObject



40
41
42
43
44
45
46
47
# File 'lib/cucumber/ast/background.rb', line 40

def to_sexp
  sexp = [:background, @line, @keyword]
  comment = @comment.to_sexp
  sexp += [comment] if comment
  steps = @steps.to_sexp
  sexp += steps if steps.any?
  sexp
end