lib/spec/runner/context_runner.rb in rspec-0.7.4 vs lib/spec/runner/context_runner.rb in rspec-0.7.5
- old
+ new
@@ -2,33 +2,46 @@
module Spec
module Runner
class ContextRunner
- def initialize(reporter, dry_run, single_spec=nil)
+ def initialize(options)
@contexts = []
- @reporter = reporter
- @dry_run = dry_run
- @single_spec = single_spec
+ @options = options
end
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)
+ return if !@options.spec_name.nil? unless context.matches?(@options.spec_name)
+ context.run_single_spec(@options.spec_name) if context.matches?(@options.spec_name)
@contexts << context
end
+ # Runs all contexts and returns the number of failures.
def run(exit_when_done)
- @reporter.start(number_of_specs)
- @contexts.each do |context|
- context.run(@reporter, @dry_run)
+ @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
- @reporter.end
- failure_count = @reporter.dump
+ 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
def number_of_specs
@contexts.inject(0) {|sum, context| sum + context.number_of_specs}
end