Class: Spec::Runner::ContextRunner

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ContextRunner

Returns a new instance of ContextRunner.



5
6
7
8
# File 'lib/spec/runner/context_runner.rb', line 5

def initialize(options)
  @contexts = []
  @options = options
end

Instance Method Details

#add_context(context) ⇒ Object



10
11
12
13
14
# File 'lib/spec/runner/context_runner.rb', line 10

def add_context(context)
  return unless spec_description.nil? || context.matches?(spec_description)
  context.run_single_spec(spec_description) if context.matches?(spec_description)
  @contexts << context
end

#number_of_specsObject



44
45
46
# File 'lib/spec/runner/context_runner.rb', line 44

def number_of_specs
  @contexts.inject(0) {|sum, context| sum + context.number_of_specs}
end

#run(exit_when_done) ⇒ Object

Runs all contexts and returns the number of failures.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/spec/runner/context_runner.rb', line 17

def run(exit_when_done)
  @options.reporter.start(number_of_specs)
  begin
    @contexts.each do |context|
      context.run(@options.reporter, @options.dry_run)
    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