Permalink
Browse files

- Replaced Runnable#dup and Test#dup with marshal_dump/load. Too many…

… problems cropping up on untested rails code. (tenderlove/rubys)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8568]
  • Loading branch information...
1 parent 285b72a commit 904f2002a6716bbe28d4b0f37f71243ae8c119e9 @zenspider zenspider committed May 20, 2013
Showing with 20 additions and 19 deletions.
  1. +5 −7 lib/minitest.rb
  2. +7 −4 lib/minitest/test.rb
  3. +8 −8 test/minitest/test_minitest_unit.rb
View
@@ -282,14 +282,12 @@ def self.runnables
@@runnables
end
- def dup # :nodoc:
- obj = self.class.new self.name
-
- obj.name = self.name
- obj.failures = self.failures.dup
- obj.assertions = self.assertions
+ def marshal_dump
+ [self.name, self.failures, self.assertions]
+ end
- obj
+ def marshal_load ary
+ self.name, self.failures, self.assertions = ary
end
def failure # :nodoc:
View
@@ -87,10 +87,13 @@ def self.test_order
attr_accessor :time
- def dup # :nodoc:
- obj = super
- obj.time = self.time
- obj
+ def marshal_dump
+ super << self.time
+ end
+
+ def marshal_load ary
+ self.time = ary.pop
+ super
end
##
@@ -638,7 +638,7 @@ def test_setup_and_teardown_survive_inheritance
end
class TestMinitestRunnable < Minitest::Test
- def setup_dup klass
+ def setup_marshal klass
tc = klass.new "whatever"
tc.assertions = 42
tc.failures << "a failure"
@@ -653,8 +653,8 @@ def tc.setup
@tc = tc
end
- def assert_dup expected_ivars
- new_tc = @tc.dup
+ def assert_marshal expected_ivars
+ new_tc = Marshal.load Marshal.dump @tc
ivars = new_tc.instance_variables.map(&:to_s).sort
assert_equal expected_ivars, ivars
@@ -665,20 +665,20 @@ def assert_dup expected_ivars
yield new_tc if block_given?
end
- def test_dup
- setup_dup Minitest::Runnable
+ def test_marshal
+ setup_marshal Minitest::Runnable
- assert_dup %w(@NAME @assertions @failures)
+ assert_marshal %w(@NAME @assertions @failures)
end
end
class TestMinitestTest < TestMinitestRunnable
def test_dup
- setup_dup Minitest::Test do |tc|
+ setup_marshal Minitest::Test do |tc|
tc.time = 3.14
end
- assert_dup %w(@NAME @assertions @failures @time) do |new_tc|
+ assert_marshal %w(@NAME @assertions @failures @time) do |new_tc|
assert_in_epsilon 3.14, new_tc.time
end
end

0 comments on commit 904f200

Please sign in to comment.