Permalink
Browse files

Sling the reporter (formatter) around instead of ref'ing a global

  • Loading branch information...
dchelimsky committed Feb 10, 2010
1 parent 976ef91 commit 5089a32b99dcb2590ca8424dc396617b7d6cbb28
View
@@ -1,6 +1,7 @@
require 'rspec/core/load_path'
require 'rspec/core/deprecation'
require 'rspec/core/mocking/with_absolutely_nothing'
+require 'rspec/core/around_proxy'
require 'rspec/core/world'
require 'rspec/core/configuration'
require 'rspec/core/command_line_options'
@@ -0,0 +1,14 @@
+module Rspec
+ module Core
+ class AroundProxy
+ def initialize(example_group_instance, &example_block)
+ @example_group_instance, @example_block = example_group_instance, example_block
+ end
+
+ def run
+ @example_group_instance.instance_eval(&@example_block)
+ end
+ end
+ end
+end
+
View
@@ -35,23 +35,23 @@ def run_started
record_results :started_at => Time.now
end
- def run_passed
- run_finished 'passed'
+ def run_passed(reporter=nil)
+ run_finished reporter, 'passed'
end
- def run_pending(message='Not yet implemented')
- run_finished 'pending', :pending_message => message
+ def run_pending(reporter=nil, message='Not yet implemented')
+ run_finished reporter, 'pending', :pending_message => message
end
- def run_failed(exception)
- run_finished 'failed', :exception_encountered => exception
+ def run_failed(reporter, exception)
+ run_finished reporter, 'failed', :exception_encountered => exception
end
- def run_finished(status, results={})
+ def run_finished(reporter, status, results={})
record_results results.update(:status => status)
finish_time = Time.now
record_results :finished_at => finish_time, :run_time => (finish_time - execution_result[:started_at])
- Rspec::Core.configuration.formatter.example_finished(self)
+ reporter.example_finished(self)
end
def run_before_each
@@ -73,21 +73,11 @@ def assign_auto_description
end
end
- class AroundProxy
- def initialize(example_group_instance, &example_block)
- @example_group_instance, @example_block = example_group_instance, example_block
- end
-
- def run
- @example_group_instance.instance_eval(&@example_block)
- end
- end
-
def runnable?
!metadata[:pending]
end
- def run(example_group_instance)
+ def run(example_group_instance, reporter)
@example_group_instance = example_group_instance
@example_group_instance.running_example = self
@@ -120,9 +110,9 @@ def run(example_group_instance)
end
if exception_encountered
- run_failed(exception_encountered)
+ run_failed(reporter, exception_encountered)
else
- runnable? ? run_passed : run_pending
+ runnable? ? run_passed(reporter) : run_pending(reporter)
end
all_systems_nominal
@@ -8,7 +8,7 @@ class ExampleGroup
extend Advice
include ExampleGroupSubject
- attr_accessor :running_example, :reporter
+ attr_accessor :running_example
def self.inherited(klass)
super
@@ -173,7 +173,7 @@ def self.run(reporter)
# Runs all examples, returning true only if all of them pass
def self.run_examples(example_world, reporter)
examples_to_run.map do |ex|
- result = ex.run(example_world)
+ result = ex.run(example_world, reporter)
example_world.__reset__
before_all_ivars.each { |k, v| example_world.instance_variable_set(k, v) }
result
View
@@ -17,7 +17,7 @@ def configuration
Rspec::Core.configuration
end
- def formatter
+ def reporter
configuration.formatter
end
@@ -32,28 +32,28 @@ def run(args = [])
total_examples_to_run = Rspec::Core.world.total_examples_to_run
- old_sync, formatter.output.sync = formatter.output.sync, true if formatter.output.respond_to?(:sync=)
+ old_sync, reporter.output.sync = reporter.output.sync, true if reporter.output.respond_to?(:sync=)
suite_success = true
- formatter_supports_sync = formatter.output.respond_to?(:sync=)
- old_sync, formatter.output.sync = formatter.output.sync, true if formatter_supports_sync
+ reporter_supports_sync = reporter.output.respond_to?(:sync=)
+ old_sync, reporter.output.sync = reporter.output.sync, true if reporter_supports_sync
- formatter.start(total_examples_to_run) # start the clock
+ reporter.start(total_examples_to_run) # start the clock
start = Time.now
Rspec::Core.world.example_groups_to_run.each do |example_group|
- suite_success &= example_group.run(formatter)
+ suite_success &= example_group.run(reporter)
end
- formatter.start_dump(Time.now - start)
+ reporter.start_dump(Time.now - start)
- formatter.dump_failures
- formatter.dump_summary
- formatter.dump_pending
- formatter.close
+ reporter.dump_failures
+ reporter.dump_summary
+ reporter.dump_pending
+ reporter.close
- formatter.output.sync = old_sync if formatter_supports_sync
+ reporter.output.sync = old_sync if reporter_supports_sync
suite_success
end
@@ -2,10 +2,10 @@
describe Rspec::Core::Runner do
- describe 'formatter' do
+ describe 'reporter' do
it 'should return the configured formatter' do
- Rspec::Core::Runner.new.formatter.should == Rspec::Core.configuration.formatter
+ Rspec::Core::Runner.new.reporter.should == Rspec::Core.configuration.formatter
end
end

0 comments on commit 5089a32

Please sign in to comment.