Class: Cucumber::Ast::StepCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cucumber/ast/step_collection.rb

Overview

Holds an Array of Step or StepDefinition

Instance Method Summary collapse

Constructor Details

#initialize(steps) ⇒ StepCollection

Returns a new instance of StepCollection.



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

def initialize(steps)
  @steps = steps
  @steps.each{|step| step.step_collection = self}
end

Instance Method Details

#accept(visitor, &proc) ⇒ Object



12
13
14
15
16
# File 'lib/cucumber/ast/step_collection.rb', line 12

def accept(visitor, &proc)
  @steps.each do |step|
    visitor.visit_step(step) if proc.nil? || proc.call(step)
  end
end

#dup(step_invocations = []) ⇒ Object

Duplicates this instance and adds step_invocations to the end



31
32
33
# File 'lib/cucumber/ast/step_collection.rb', line 31

def dup(step_invocations = [])
  StepCollection.new(@steps + step_invocations)
end

#each(&proc) ⇒ Object



35
36
37
# File 'lib/cucumber/ast/step_collection.rb', line 35

def each(&proc)
  @steps.each(&proc)
end

#empty?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/cucumber/ast/step_collection.rb', line 44

def empty?
  @steps.empty?
end

#exceptionObject



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

def exception
  @exception ||= ((failed = @steps.detect {|step| step.exception}) && failed.exception)
end

#failed?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/cucumber/ast/step_collection.rb', line 57

def failed?
  status == :failed
end

#max_line_length(feature_element) ⇒ Object



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

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

#passed?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/cucumber/ast/step_collection.rb', line 61

def passed?
  status == :passed
end

#previous_step(step) ⇒ Object



39
40
41
42
# File 'lib/cucumber/ast/step_collection.rb', line 39

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

#statusObject



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

def status
  @steps.each{|step_invocation| return step_invocation.status if step_invocation.status != :passed}
  :passed
end

#step_invocations(background = false) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/cucumber/ast/step_collection.rb', line 18

def step_invocations(background = false)
  StepCollection.new(@steps.map{ |step| 
    i = step.step_invocation
    i.background = background
    i
  })
end

#step_invocations_from_cells(cells) ⇒ Object



26
27
28
# File 'lib/cucumber/ast/step_collection.rb', line 26

def step_invocations_from_cells(cells)
  @steps.map{|step| step.step_invocation_from_cells(cells)}
end

#to_sexpObject



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

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