Class: Cucumber::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter, step_mother) ⇒ Executor

Returns a new instance of Executor.



14
15
16
17
18
19
20
# File 'lib/cucumber/executor.rb', line 14

def initialize(formatter, step_mother)
  @formatter = formatter
  @world_proc = lambda{ Object.new }
  @before_procs = []
  @after_procs = []
  @step_mother = step_mother
end

Instance Attribute Details

#failedObject (readonly)

Returns the value of attribute failed.



8
9
10
# File 'lib/cucumber/executor.rb', line 8

def failed
  @failed
end

Instance Method Details

#line=(line) ⇒ Object



10
11
12
# File 'lib/cucumber/executor.rb', line 10

def line=(line)
  @line = line
end

#register_after_proc(&proc) ⇒ Object



31
32
33
34
# File 'lib/cucumber/executor.rb', line 31

def register_after_proc(&proc)
  proc.extend(CoreExt::CallIn)
  @after_procs << proc
end

#register_before_proc(&proc) ⇒ Object



26
27
28
29
# File 'lib/cucumber/executor.rb', line 26

def register_before_proc(&proc)
  proc.extend(CoreExt::CallIn)
  @before_procs << proc
end

#register_world_proc(&proc) ⇒ Object



22
23
24
# File 'lib/cucumber/executor.rb', line 22

def register_world_proc(&proc)
  @world_proc = proc
end

#visit_feature(feature) ⇒ Object



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

def visit_feature(feature)
  feature.accept(self)
end

#visit_features(features) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/cucumber/executor.rb', line 36

def visit_features(features)
  raise "Line number can only be specified when there is 1 feature. There were #{features.length}." if @line && features.length != 1
  @step_mother.visit_features(features)
  @formatter.visit_features(features) if @formatter.respond_to?(:visit_features)
  features.accept(self)
  @formatter.dump
end

#visit_header(header) ⇒ Object



48
49
50
# File 'lib/cucumber/executor.rb', line 48

def visit_header(header)
  @formatter.header_executing(header) if @formatter.respond_to?(:header_executing)
end

#visit_narrative(narrative) ⇒ Object



52
53
54
# File 'lib/cucumber/executor.rb', line 52

def visit_narrative(narrative)
  @formatter.narrative_executing(narrative) if @formatter.respond_to?(:narrative_executing)
end

#visit_scenario(scenario) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cucumber/executor.rb', line 56

def visit_scenario(scenario)
  if @line.nil? || scenario.at_line?(@line)
    @error = nil
    @world = @world_proc.call
    @formatter.scenario_executing(scenario) if @formatter.respond_to?(:scenario_executing)
    @before_procs.each{|p| p.call_in(@world, *[])}
    scenario.accept(self)
    @after_procs.each{|p| p.call_in(@world, *[])}
    @formatter.scenario_executed(scenario) if @formatter.respond_to?(:scenario_executed)
  end
end

#visit_step(step) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cucumber/executor.rb', line 68

def visit_step(step)
  if @error.nil?
    begin
      step.execute_in(@world)
    rescue Pending => ignore
    rescue => e
      @failed = true
      @error = e
    end
    @formatter.step_executed(step)
  else
    @formatter.step_skipped(step)
  end
end