1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
From: Per Andersson <avtobiff@gmail.com>
Date: Wed, 6 Jun 2012 17:47:15 +0200
Subject: Implement compatibility wrapper for retrieving test name.
In RubyUnit 1.9 the method #name was removed from Test::Unit::TestCase.
Implement wrapper for compatibility with both RubyUnit 1.8 and 1.9.
---
test/testbase.rb | 12 +++++++++++-
test/testtestbase.rb | 4 ++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/test/testbase.rb b/test/testbase.rb
index 0dfb8af..c17ba4e 100644
--- a/test/testbase.rb
+++ b/test/testbase.rb
@@ -102,8 +102,18 @@ class TestBase < Test::Unit::TestCase
end
end
+ # In RubyUnit 1.9 the method #name was removed. Implement wrapper here for
+ # compatibility with both RubyUnit 1.8 and 1.9.
+ def get_test_name
+ if (RUBY_VERSION.to_f < 1.9)
+ name
+ else
+ "#{self.__name__}(#{self.class})"
+ end
+ end
+
def setup
- @scratch_dir = File.join(Dir.getwd, "_scratch_" + name)
+ @scratch_dir = File.join(Dir.getwd, "_scratch_" + get_test_name)
@data_dir = File.join(Dir.getwd, "test", "data")
@scratch_hash = {}
diff --git a/test/testtestbase.rb b/test/testtestbase.rb
index 4ae2b39..254b357 100644
--- a/test/testtestbase.rb
+++ b/test/testtestbase.rb
@@ -76,8 +76,8 @@ class TestTestBase < TestBase
end
def test_name
- assert_match(/\btest_name\b/, name)
- assert_match(/\bTestTestBase\b/, name)
+ assert_match(/\btest_name\b/, get_test_name)
+ assert_match(/\bTestTestBase\b/, get_test_name)
end
def test_scratch_dir
--
|