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
17
# File 'lib/cucumber/ast/step_collection.rb', line 12

def accept(visitor, &proc)
  return if Cucumber.wants_to_quit
  @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



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

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

#each(&proc) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @steps.empty?
end

#exceptionObject



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

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

#failed?Boolean

Returns:

  • (Boolean)


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

def failed?
  status == :failed
end

#max_line_length(feature_element) ⇒ Object



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

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

#passed?Boolean

Returns:

  • (Boolean)


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

def passed?
  status == :passed
end

#previous_step(step) ⇒ Object



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

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

#statusObject



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

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

#step_invocations(background = false) ⇒ Object



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

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



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

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

#to_sexpObject



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

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