Class: Spec::Runner::ContextRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/spekmachine/runner/context_runner.rb

Instance Method Summary collapse

Instance Method Details

#create_path(ctxMap) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/spekmachine/runner/context_runner.rb', line 11

def create_path(ctxMap)
  g = CPP.new
  @contexts.each do |c|
    c.goto_parts.keys.each {|dest| g.addArc(nil, c.context_id, dest) }
  end
  g.solve
  mp = g.printCPT(g.convert_to_index(@start_name)).map {|arcLabel, from, to| [g.convert(from), g.convert(to)] }
  mp.map {|from, to| [ctxMap[from], to] }
end

#run(exit_when_done) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/spekmachine/runner/context_runner.rb', line 21

def run(exit_when_done)
  raise unless @setup
  @setup.call
  cm = {}
  @contexts.each {|c| cm[c.context_id] = c }
  @options.reporter.start(number_of_specs)
  begin
    path = create_path(cm)
    path.each do |ctx, dest|
      ctx.run(@options.reporter, @options.dry_run)
      ctx.jump_to dest
    end
  rescue Interrupt
  ensure
    @options.reporter.end
  end
  failure_count = @options.reporter.dump
  
  if(failure_count == 0 && !@options.heckle_runner.nil?)
    heckle_runner = @options.heckle_runner
    @options.heckle_runner = nil
    context_runner = self.class.new(@options)
    context_runner.instance_variable_set(:@contexts, @contexts)
    heckle_runner.heckle_with(context_runner)
  end
  
  if(exit_when_done)
    exit_code = (failure_count == 0) ? 0 : 1
    exit(exit_code)
  end
  failure_count
end

#set_start(name, block) ⇒ Object



6
7
8
9
# File 'lib/spekmachine/runner/context_runner.rb', line 6

def set_start(name, block)
  @start_name = name
  @setup = block
end