Skip to content

Commit

Permalink
- Replaced Runnable#dup and Test#dup with marshal_dump/load. Too many…
Browse files Browse the repository at this point in the history
… problems cropping up on untested rails code. (tenderlove/rubys)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8568]
  • Loading branch information
zenspider committed May 20, 2013
1 parent 285b72a commit 904f200
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
12 changes: 5 additions & 7 deletions lib/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions lib/minitest/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
16 changes: 8 additions & 8 deletions test/minitest/test_minitest_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 904f200

Please sign in to comment.