From 05410b1af5bd655cdec10b2c6d3d9cc3c2145823 Mon Sep 17 00:00:00 2001 From: Nick Gauthier Date: Mon, 23 Aug 2010 14:42:51 -0400 Subject: [PATCH] rspec 2.0 support --- Rakefile | 2 +- hydra.gemspec | 8 +++--- lib/hydra/runner.rb | 27 +++++++------------ lib/hydra/spec/autorun_override.rb | 13 ++------- lib/hydra/spec/hydra_formatter.rb | 23 +++++++++++----- test/fixtures/write_file_alternate_spec.rb | 2 +- test/fixtures/write_file_spec.rb | 2 +- test/fixtures/write_file_with_pending_spec.rb | 2 +- test/runner_test.rb | 3 ++- 9 files changed, 38 insertions(+), 44 deletions(-) diff --git a/Rakefile b/Rakefile index 4a46708..481ecaa 100644 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ begin gem.homepage = "http://github.com/ngauthier/hydra" gem.authors = ["Nick Gauthier"] gem.add_development_dependency "shoulda", "= 2.10.3" - gem.add_development_dependency "rspec", "= 1.3.0" + gem.add_development_dependency "rspec", "= 2.0.0.beta.19" gem.add_development_dependency "cucumber", "= 0.8.5" gem.add_development_dependency "therubyracer", "= 0.7.4" end diff --git a/hydra.gemspec b/hydra.gemspec index 6b0200c..de7816e 100644 --- a/hydra.gemspec +++ b/hydra.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Nick Gauthier"] - s.date = %q{2010-08-20} + s.date = %q{2010-08-23} s.default_executable = %q{warmsnake.rb} s.description = %q{Spread your tests over multiple machines to test your code faster.} s.email = %q{nick@smartlogicsolutions.com} @@ -112,18 +112,18 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q, ["= 2.10.3"]) - s.add_development_dependency(%q, ["= 1.3.0"]) + s.add_development_dependency(%q, ["= 2.0.0.beta.19"]) s.add_development_dependency(%q, ["= 0.8.5"]) s.add_development_dependency(%q, ["= 0.7.4"]) else s.add_dependency(%q, ["= 2.10.3"]) - s.add_dependency(%q, ["= 1.3.0"]) + s.add_dependency(%q, ["= 2.0.0.beta.19"]) s.add_dependency(%q, ["= 0.8.5"]) s.add_dependency(%q, ["= 0.7.4"]) end else s.add_dependency(%q, ["= 2.10.3"]) - s.add_dependency(%q, ["= 1.3.0"]) + s.add_dependency(%q, ["= 2.0.0.beta.19"]) s.add_dependency(%q, ["= 0.8.5"]) s.add_dependency(%q, ["= 0.7.4"]) end diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb index e44eae2..aa5ea32 100644 --- a/lib/hydra/runner.rb +++ b/lib/hydra/runner.rb @@ -107,7 +107,7 @@ module Hydra #:nodoc: def run_rspec_file(file) # pull in rspec begin - require 'spec' + require 'rspec' require 'hydra/spec/hydra_formatter' # Ensure we override rspec's at_exit require 'hydra/spec/autorun_override' @@ -115,22 +115,15 @@ module Hydra #:nodoc: return ex.to_s end hydra_output = StringIO.new - Spec::Runner.options.instance_variable_set(:@formatters, [ - Spec::Runner::Formatter::HydraFormatter.new( - Spec::Runner.options.formatter_options, - hydra_output - ) - ]) - Spec::Runner.options.instance_variable_set( - :@example_groups, [] - ) - Spec::Runner.options.instance_variable_set( - :@files, [file] - ) - Spec::Runner.options.instance_variable_set( - :@files_loaded, false - ) - Spec::Runner.options.run_examples + + config = [ + '-f', 'RSpec::Core::Formatters::HydraFormatter', + file + ] + + RSpec.instance_variable_set(:@world, nil) + RSpec::Core::Runner.run(config, hydra_output, hydra_output) + hydra_output.rewind output = hydra_output.read.chomp output = "" if output.gsub("\n","") =~ /^\.*$/ diff --git a/lib/hydra/spec/autorun_override.rb b/lib/hydra/spec/autorun_override.rb index bf00179..829c6f6 100644 --- a/lib/hydra/spec/autorun_override.rb +++ b/lib/hydra/spec/autorun_override.rb @@ -1,12 +1,3 @@ -if defined?(Spec) - module Spec - module Runner - class << self - # stop the auto-run at_exit - def run - return 0 - end - end - end - end +if defined?(RSpec) + RSpec::Core::Runner.disable_autorun! end diff --git a/lib/hydra/spec/hydra_formatter.rb b/lib/hydra/spec/hydra_formatter.rb index 0bf27cc..3069d87 100644 --- a/lib/hydra/spec/hydra_formatter.rb +++ b/lib/hydra/spec/hydra_formatter.rb @@ -1,14 +1,23 @@ -require 'spec/runner/formatter/progress_bar_formatter' -module Spec - module Runner - module Formatter - class HydraFormatter < ProgressBarFormatter +require 'rspec/core/formatters/progress_formatter' +module RSpec + module Core + module Formatters + class HydraFormatter < ProgressFormatter + def example_passed(example) + end + + def example_pending(example) + end + + def example_failed(example) + end + # Stifle the post-test summary def dump_summary(duration, example, failure, pending) end - # Stifle the output of pending examples - def example_pending(*args) + # Stifle pending specs + def dump_pending end end end diff --git a/test/fixtures/write_file_alternate_spec.rb b/test/fixtures/write_file_alternate_spec.rb index 543858a..d3fbb0e 100644 --- a/test/fixtures/write_file_alternate_spec.rb +++ b/test/fixtures/write_file_alternate_spec.rb @@ -1,5 +1,5 @@ require 'tmpdir' -require 'spec' +require 'rspec' context "file writing" do it "writes to a file" do File.open(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'), 'a') do |f| diff --git a/test/fixtures/write_file_spec.rb b/test/fixtures/write_file_spec.rb index ea617f0..60ece30 100644 --- a/test/fixtures/write_file_spec.rb +++ b/test/fixtures/write_file_spec.rb @@ -1,5 +1,5 @@ require 'tmpdir' -require 'spec' +require 'rspec' context "file writing" do it "writes to a file" do File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f| diff --git a/test/fixtures/write_file_with_pending_spec.rb b/test/fixtures/write_file_with_pending_spec.rb index 3399ada..f37d444 100644 --- a/test/fixtures/write_file_with_pending_spec.rb +++ b/test/fixtures/write_file_with_pending_spec.rb @@ -1,5 +1,5 @@ require 'tmpdir' -require 'spec' +require 'rspec' context "file writing" do it "writes to a file" do File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f| diff --git a/test/runner_test.rb b/test/runner_test.rb index 87786f0..9642a2b 100644 --- a/test/runner_test.rb +++ b/test/runner_test.rb @@ -50,6 +50,7 @@ class RunnerTest < Test::Unit::TestCase end should "run two rspec tests" do + puts "First test" runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w')) runner.run_file(rspec_file) assert File.exists?(target_file) @@ -60,7 +61,7 @@ class RunnerTest < Test::Unit::TestCase runner.run_file(alternate_rspec_file) assert File.exists?(alternate_target_file) assert_equal "HYDRA", File.read(alternate_target_file) - assert !File.exists?(target_file) + assert !File.exists?(target_file), "Tests are double running!" end should "run rspec tests with pending examples" do