Permalink
Browse files

clean up some feature envy in the runner

- inspired by the flay report at getcaliper.org
  • Loading branch information...
1 parent beaf23b commit bb15f4fbcc775a0ae1ff7ff5f8063f2b94957102 @dchelimsky dchelimsky committed Apr 7, 2010
Showing with 74 additions and 52 deletions.
  1. +4 −1 lib/rspec/core/configuration.rb
  2. +52 −19 lib/rspec/core/formatters/base_formatter.rb
  3. +18 −32 lib/rspec/core/runner.rb
@@ -184,7 +184,6 @@ def run_all_when_everything_filtered?
@run_all_when_everything_filtered
end
- # Where does output go? For now $stdout
def output
$stdout
end
@@ -230,6 +229,10 @@ def configure_mock_framework
Rspec::Core::ExampleGroup.send(:include, Rspec::Core::MockFrameworkAdapter)
end
+ def require_all_files
+ files_to_run.map {|f| require f }
+ end
+
end
end
end
@@ -1,7 +1,5 @@
module Rspec
-
module Core
-
module Formatters
class BaseFormatter
@@ -15,20 +13,8 @@ def initialize
@example_group = nil
end
- def configuration
- Rspec.configuration
- end
-
def output
- Rspec.configuration.output
- end
-
- def profile_examples?
- Rspec.configuration.profile_examples
- end
-
- def color_enabled?
- configuration.color_enabled?
+ configuration.output
end
def pending_examples
@@ -39,16 +25,34 @@ def failed_examples
@failed_examples ||= ::Rspec::Core.world.find(examples, :positive, :execution_result => { :status => 'failed' })
end
+ def report(count)
+ sync_output do
+ start(count)
+ begin
+ yield
+ ensure
+ stop
+ dump(@duration)
+ close
+ end
+ end
+ end
+
# This method is invoked before any examples are run, right after
# they have all been collected. This can be useful for special
# formatters that need to provide progress on feedback (graphical ones)
#
# This method will only be invoked once, and the next one to be invoked
# is #add_example_group
def start(example_count)
+ @start = Time.now
@example_count = example_count
end
+ def stop
+ @duration = Time.now - @start
+ end
+
def example_finished(example)
examples << example
end
@@ -60,8 +64,13 @@ def example_finished(example)
def add_example_group(example_group)
@example_group = example_group
end
-
- alias_method :add_example_group, :add_example_group
+
+ def dump(duration)
+ start_dump(duration)
+ dump_failures
+ dump_summary
+ dump_pending
+ end
# This method is invoked after all of the examples have executed. The next method
# to be invoked after this one is #dump_failure (once for each failed example),
@@ -95,7 +104,11 @@ def format_backtrace(backtrace, example)
cleansed.empty? ? backtrace : cleansed
end
- protected
+ protected
+
+ def configuration
+ Rspec.configuration
+ end
def backtrace_line(line)
return nil if configuration.cleaned_from_backtrace?(line)
@@ -119,9 +132,29 @@ def read_failed_line(exception, example)
end
end
+ def sync_output
+ begin
+ old_sync, output.sync = output.sync, true if output_supports_sync
+ yield
+ ensure
+ output.sync = old_sync if output_supports_sync
+ end
+ end
+
+ def output_supports_sync
+ output.respond_to?(:sync=)
+ end
+
+ def profile_examples?
+ configuration.profile_examples
+ end
+
+ def color_enabled?
+ configuration.color_enabled?
+ end
+
end
end
end
-
end
@@ -21,46 +21,32 @@ def reporter
configuration.formatter
end
- def require_all_files(configuration)
- configuration.files_to_run.map {|f| require f }
- end
-
def run(args = [])
- Rspec::Core::CommandLineOptions.parse(args).apply(configuration)
-
- require_all_files(configuration)
-
- configuration.configure_mock_framework
+ configure(args)
- total_examples_to_run = Rspec::Core.world.total_examples_to_run
-
- old_sync, reporter.output.sync = reporter.output.sync, true if reporter.output.respond_to?(:sync=)
-
- suite_success = true
-
- reporter_supports_sync = reporter.output.respond_to?(:sync=)
- old_sync, reporter.output.sync = reporter.output.sync, true if reporter_supports_sync
-
- 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(reporter)
+ reporter.report(example_count) do
+ example_groups.inject(true) do |success, example_group|
+ success &= example_group.run(reporter)
+ end
end
+ end
+
+ private
- reporter.start_dump(Time.now - start)
-
- reporter.dump_failures
- reporter.dump_summary
- reporter.dump_pending
- reporter.close
+ def configure(args)
+ Rspec::Core::CommandLineOptions.parse(args).apply(configuration)
+ configuration.require_all_files
+ configuration.configure_mock_framework
+ end
- reporter.output.sync = old_sync if reporter_supports_sync
+ def example_count
+ Rspec::Core.world.total_examples_to_run
+ end
- suite_success
+ def example_groups
+ Rspec::Core.world.example_groups_to_run
end
-
end
end

0 comments on commit bb15f4f

Please sign in to comment.