From 5b163e285d2e774ac474d3ffad5676bf273820f9 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 16 Nov 2008 18:10:14 -0600 Subject: [PATCH] only try to load Test::Unit if Test::Unit is defined --- History.txt | 3 ++- lib/spec.rb | 8 ++++++-- spec/spec/interop/test/unit/spec_spec.rb | 6 +----- .../interop/test/unit/test_unit_spec_helper.rb | 4 ++++ stories/interop/test_but_not_test_unit | 14 ++++++++++++++ .../test/spec_including_test_but_not_unit.rb | 11 +++++++++++ 6 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 stories/interop/test_but_not_test_unit create mode 100644 stories/resources/test/spec_including_test_but_not_unit.rb diff --git a/History.txt b/History.txt index b2d2b91bc..c5d5a764e 100644 --- a/History.txt +++ b/History.txt @@ -11,9 +11,10 @@ * should throw_symbol accepts an optional argument: should throw_symbol(:sym, arg) * fixed --line for jruby (Zach Moazeni) -* 1 bug fix +* 2 bug fixex * fixed bug where {:a => 1, :b => 2}.should include(:a, :b) failed (Yossef Mendelssohn) + * only try to load Test::Unit if Test::Unit is defined === Version 1.1.11 / 2008-10-24 diff --git a/lib/spec.rb b/lib/spec.rb index f95264e1f..740273f2e 100644 --- a/lib/spec.rb +++ b/lib/spec.rb @@ -7,7 +7,11 @@ require 'spec/version' require 'spec/dsl' -if Object.const_defined?(:Test) +def test_unit_defined? + Object.const_defined?(:Test) && Test.const_defined?(:Unit) +end + +if test_unit_defined? require 'spec/interop/test' end @@ -23,7 +27,7 @@ def run end def exit? - !Object.const_defined?(:Test) || Test::Unit.run? + !test_unit_defined? || Test::Unit.run? end def spec_command? diff --git a/spec/spec/interop/test/unit/spec_spec.rb b/spec/spec/interop/test/unit/spec_spec.rb index f28f95cfe..86bf8b549 100644 --- a/spec/spec/interop/test/unit/spec_spec.rb +++ b/spec/spec/interop/test/unit/spec_spec.rb @@ -2,11 +2,7 @@ describe "ExampleGroup with test/unit/interop" do include TestUnitSpecHelper - - def resources - File.dirname(__FILE__) + "/resources" - end - + describe "with passing examples" do it "should output 0 failures" do output = ruby("#{resources}/spec_that_passes.rb") diff --git a/spec/spec/interop/test/unit/test_unit_spec_helper.rb b/spec/spec/interop/test/unit/test_unit_spec_helper.rb index 04d5d2713..185c76945 100644 --- a/spec/spec/interop/test/unit/test_unit_spec_helper.rb +++ b/spec/spec/interop/test/unit/test_unit_spec_helper.rb @@ -3,6 +3,10 @@ module TestUnitSpecHelper include RubyForker + + def resources + File.dirname(__FILE__) + "/resources" + end def run_script(file_name) output = ruby(file_name) diff --git a/stories/interop/test_but_not_test_unit b/stories/interop/test_but_not_test_unit new file mode 100644 index 000000000..4bd595e6b --- /dev/null +++ b/stories/interop/test_but_not_test_unit @@ -0,0 +1,14 @@ +Story: Test is defined, but not Test::Unit + + As an RSpec user who has my own library named Test (but not Test::Unit) + I want to run examples without getting Test::Unit NameErrors + + Scenario: Run with ruby + Given the file test/spec_including_test_but_not_unit.rb + When I run it with the ruby interpreter + Then the stderr should not match "Test::Unit" + + Scenario: Run with spec + Given the file test/spec_including_test_but_not_unit.rb + When I run it with the spec script + Then the stderr should not match "Test::Unit" diff --git a/stories/resources/test/spec_including_test_but_not_unit.rb b/stories/resources/test/spec_including_test_but_not_unit.rb new file mode 100644 index 000000000..7329fb50b --- /dev/null +++ b/stories/resources/test/spec_including_test_but_not_unit.rb @@ -0,0 +1,11 @@ +$:.push File.join(File.dirname(__FILE__), *%w[.. .. .. lib]) +require 'spec' + +module Test +end + +describe "description" do + it "should description" do + 1.should == 1 + end +end \ No newline at end of file