Permalink
Browse files

Support RSpec 2

- drops support for RSpec 1
  • Loading branch information...
1 parent 6d44a57 commit a54dcb019a3f3eabdfa5ca23c4220cb526458d94 Jon Larkowski and Les Hill committed with leshill Mar 9, 2011
View
@@ -2,14 +2,9 @@ require 'rubygems'
require 'rake'
require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new(:spec) do |spec|
- spec.pattern = 'spec/**/*_spec.rb'
-end
+RSpec::Core::RakeTask.new(:spec)
-RSpec::Core::RakeTask.new(:rcov) do |spec|
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
-end
+RSpec::Core::RakeTask.new(:rcov)
task :default => :spec
View
@@ -26,9 +26,8 @@ module Specjour
autoload :Worker, 'specjour/worker'
autoload :Cucumber, 'specjour/cucumber'
- autoload :Rspec, 'specjour/rspec'
+ autoload :RSpec, 'specjour/rspec'
- VERSION = "0.3.1".freeze
HOOKS_PATH = "./.specjour/hooks.rb"
def self.interrupted?
@@ -37,7 +36,7 @@ def self.interrupted?
def self.interrupted=(bool)
Cucumber.wants_to_quit
- Rspec.wants_to_quit
+ RSpec.wants_to_quit
@interrupted = bool
end
View
@@ -1,15 +1,20 @@
module Specjour
module DbScrub
- require 'rake'
- if defined?(Rails) && Rails.version =~ /^3/
- task(:environment) {}
- load 'rails/tasks/misc.rake'
- load 'active_record/railties/databases.rake'
- else
- load 'tasks/misc.rake'
- load 'tasks/databases.rake'
- Rake::Task["db:structure:dump"].clear
- Rake::Task["environment"].clear
+
+ begin
+ require 'rake'
+ if defined?(Rails) && Rails.version =~ /^3/
+ task(:environment) {}
+ load 'rails/tasks/misc.rake'
+ load 'active_record/railties/databases.rake'
+ else
+ load 'tasks/misc.rake'
+ load 'tasks/databases.rake'
+ Rake::Task["db:structure:dump"].clear
+ Rake::Task["environment"].clear
+ end
+ rescue LoadError
+ $stderr.puts "DbScrub failed to load properly, that's okay though"
end
extend self
View
@@ -99,7 +99,7 @@ def run_order(specs_to_run)
end
def rspec_report
- @rspec_report ||= Rspec::FinalReport.new
+ @rspec_report ||= RSpec::FinalReport.new
end
def cucumber_report
View
@@ -1,35 +1,16 @@
module Specjour
- module Rspec
- def self.load_rspec1
- require 'spec'
- require 'spec/runner/formatter/base_text_formatter'
+ module RSpec
+ require 'rspec/core'
+ require 'rspec/core/formatters/progress_formatter'
- require 'specjour/rspec/distributed_formatter'
- require 'specjour/rspec/final_report'
- require 'specjour/rspec/marshalable_exception'
- require 'specjour/rspec/preloader'
- require 'specjour/rspec/runner'
- end
-
- def self.load_rspec2
- require 'rspec/core'
- require 'rspec/core/formatters/progress_formatter'
-
- require 'specjour/rspec/marshalable_exception'
- require 'specjour/rspec/preloader'
- require 'specjour/rspec2/distributed_formatter'
- require 'specjour/rspec2/final_report'
- require 'specjour/rspec2/runner'
- require 'specjour/rspec2/shared_example_group_ext'
+ require 'specjour/rspec/marshalable_exception'
+ require 'specjour/rspec/preloader'
+ require 'specjour/rspec/distributed_formatter'
+ require 'specjour/rspec/final_report'
+ require 'specjour/rspec/runner'
+ require 'specjour/rspec/shared_example_group_ext'
- ::RSpec::Core::Runner.disable_autorun!
- end
-
- begin
- load_rspec2
- rescue LoadError
- load_rspec1
- end
+ ::RSpec::Core::Runner.disable_autorun!
def self.wants_to_quit
if defined?(::RSpec) && ::RSpec.respond_to?(:wants_to_quit=)
@@ -1,72 +1,48 @@
-module Specjour::Rspec
- class DistributedFormatter < Spec::Runner::Formatter::BaseTextFormatter
- require 'specjour/rspec/marshalable_rspec_failure'
-
- attr_reader :failing_messages, :passing_messages, :pending_messages, :output
- attr_reader :duration, :example_count, :failure_count, :pending_count, :pending_examples, :failing_examples
-
- def initialize(options, output)
- @options = options
- @output = output
- @failing_messages = []
- @passing_messages = []
- @pending_messages = []
- @pending_examples = []
- @failing_examples = []
- end
-
- def example_failed(example, counter, failure)
- failing_messages << colorize_failure('F', failure)
- print_and_flush(failing_messages)
- end
-
- def example_passed(example)
- passing_messages << green('.')
- print_and_flush(passing_messages)
+module Specjour::RSpec
+ class DistributedFormatter < ::RSpec::Core::Formatters::ProgressFormatter
+
+ def metadata_for_examples
+ examples.map do |example|
+ metadata = example.metadata
+ {
+ :execution_result => marshalable_execution_result(example.execution_result),
+ :description => metadata[:description],
+ :file_path => metadata[:file_path],
+ :full_description => metadata[:full_description],
+ :line_number => metadata[:line_number],
+ :location => metadata[:location]
+ }
+ end
end
- def example_pending(example, message, deprecated_pending_location=nil)
- super
- pending_messages << yellow('*')
- print_and_flush(pending_messages)
+ def noop(*args)
end
+ alias dump_pending noop
+ alias dump_failures noop
+ alias start_dump noop
+ alias message noop
- def dump_summary(duration, example_count, failure_count, pending_count)
- @duration = duration
- @example_count = example_count
- @failure_count = failure_count
- @pending_count = pending_count
- output.send_message(:rspec_summary=, to_hash)
+ def color_enabled?
+ true
end
- def dump_pending
- #noop
+ def dump_summary(*args)
+ output.send_message :rspec_summary=, metadata_for_examples
end
- def dump_failure(counter, failure)
- failing_examples << failure
+ def close
+ @examples = []
+ super
end
- def start_dump
- print_and_flush failing_messages
- print_and_flush passing_messages
- print_and_flush pending_messages
- end
+ protected
- def to_hash
- h = {}
- [:duration, :example_count, :failure_count, :pending_count, :pending_examples, :failing_examples].each do |key|
- h[key] = send(key)
+ def marshalable_execution_result(execution_result)
+ if exception = execution_result[:exception_encountered]
+ execution_result[:exception_encountered] = MarshalableException.new(exception)
end
- h
+ execution_result
end
- protected
-
- def print_and_flush(messages)
- output.print messages.join
- output.flush
- messages.replace []
- end
end
end
@@ -1,65 +1,73 @@
-module Specjour
- module Rspec
- class FinalReport
- attr_reader :duration, :example_count, :failure_count, :pending_count, :pending_examples, :failing_examples
+module Specjour::RSpec
+ class FinalReport
+ attr_reader :examples
+ attr_reader :duration
- def initialize
- @duration = 0.0
- @example_count = 0
- @failure_count = 0
- @pending_count = 0
- @pending_examples = []
- @failing_examples = []
- end
-
- def add(stats)
- stats.each do |key, value|
- if key == :duration
- @duration = value.to_f if duration < value.to_f
- else
- increment(key, value)
- end
- end
- end
+ def initialize
+ @examples = []
+ @duration = 0.0
+ ::RSpec.configuration.color_enabled = true
+ ::RSpec.configuration.output_stream = $stdout
+ end
- def exit_status
- failing_examples.empty?
+ def add(data)
+ if data.respond_to?(:has_key?) && data.has_key?(:duration)
+ self.duration = data[:duration]
+ else
+ metadata_for_examples(data)
end
+ end
- def increment(key, value)
- current = instance_variable_get("@#{key}")
- instance_variable_set("@#{key}", current + value)
- end
+ def duration=(value)
+ @duration = value.to_f if duration < value.to_f
+ end
- def formatter_options
- @formatter_options ||= OpenStruct.new(
- :colour => true,
- :autospec => false,
- :dry_run => false
- )
- end
+ def exit_status
+ formatter.failed_examples.empty?
+ end
- def formatter
- @formatter ||= begin
- f = Spec::Runner::Formatter::BaseTextFormatter.new(formatter_options, $stdout)
- f.instance_variable_set(:@pending_examples, pending_examples)
- f
+ def metadata_for_examples(metadata_collection)
+ examples.concat(
+ metadata_collection.map do |partial_metadata|
+ example = ::RSpec::Core::Example.allocate
+ example.instance_variable_set(:@example_group_class,
+ OpenStruct.new(:metadata => {}, :ancestors => [])
+ )
+ metadata = ::RSpec::Core::Metadata.new
+ metadata.merge! partial_metadata
+ example.instance_variable_set(:@metadata, metadata)
+ example
end
- end
+ )
+ end
- def summarize
- if example_count > 0
- formatter.dump_pending
- dump_failures
- formatter.dump_summary(duration, example_count, failure_count, pending_count)
- end
- end
+ def pending_examples
+ ::RSpec.world.find(examples, :execution_result => { :status => 'pending' })
+ end
- def dump_failures
- failing_examples.each_with_index do |failure, index|
- formatter.dump_failure index + 1, failure
- end
+ def failed_examples
+ ::RSpec.world.find(examples, :execution_result => { :status => 'failed' })
+ end
+
+ def formatter
+ @formatter ||= new_progress_formatter
+ end
+
+ def summarize
+ if examples.size > 0
+ formatter.start_dump
+ formatter.dump_pending
+ formatter.dump_failures
+ formatter.dump_summary(duration, examples.size, failed_examples.size, pending_examples.size)
end
end
+
+ protected
+ def new_progress_formatter
+ new_formatter = ::RSpec::Core::Formatters::ProgressFormatter.new($stdout)
+ new_formatter.instance_variable_set(:@failed_examples, failed_examples)
+ new_formatter.instance_variable_set(:@pending_examples, pending_examples)
+ new_formatter
+ end
end
end
@@ -1,4 +1,4 @@
-module Specjour::Rspec
+module Specjour::RSpec
class MarshalableException
attr_accessor :message, :backtrace, :class_name
@@ -1,4 +1,4 @@
-class Specjour::Rspec::Preloader
+class Specjour::RSpec::Preloader
def self.load(spec_file)
$LOAD_PATH.unshift File.join(Dir.pwd, 'spec')
require spec_file
@@ -1,11 +1,12 @@
-module Specjour::Rspec::Runner
+module Specjour::RSpec::Runner
def self.run(spec, output)
- options = Spec::Runner::OptionParser.parse(
- ['--format=Specjour::Rspec::DistributedFormatter', spec],
- $stderr,
- output
- )
- Spec::Runner.use options
- options.run_examples
+ reset
+ args = ['--format=Specjour::RSpec::DistributedFormatter', spec]
+ ::RSpec::Core::Runner.run_in_process args, $stderr, output
+ end
+
+ def self.reset
+ ::RSpec.world.instance_variable_set(:@example_groups, [])
+ ::RSpec.configuration.instance_variable_set(:@formatter, nil)
end
end
Oops, something went wrong.

0 comments on commit a54dcb0

Please sign in to comment.