Class: Spec::Runner::ContextRunner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter, standalone, dry_run, single_spec = nil) ⇒ ContextRunner

Returns a new instance of ContextRunner.



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

def initialize(reporter, standalone, dry_run, single_spec=nil)
  @contexts = []
  @reporter = reporter
  @standalone = standalone
  @dry_run = dry_run
  @single_spec = single_spec
end

Instance Attribute Details

#standaloneObject (readonly)

Returns the value of attribute standalone.



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

def standalone
  @standalone
end

Instance Method Details

#add_context(context) ⇒ Object



16
17
18
19
20
# File 'lib/spec/runner/context_runner.rb', line 16

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

#number_of_specsObject



35
36
37
# File 'lib/spec/runner/context_runner.rb', line 35

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

#run(exit_when_done) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spec/runner/context_runner.rb', line 22

def run(exit_when_done)
  @reporter.start(number_of_specs)
  @contexts.each do |context|
    context.run(@reporter, @dry_run)
  end
  @reporter.end
  failure_count = @reporter.dump
  if(exit_when_done)
    exit_code = (failure_count == 0) ? 0 : 1
    exit(exit_code)
  end
end