From 3e7c68119c1528f1589e53d9a795bc303dbddc1c Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 25 Dec 2010 13:32:48 +0000 Subject: [PATCH] * test/digest/test_digest_extend.rb (TestDigestExtend#setup): should not depend on the result of previous tests * test/with_diffent_ofs.rb (DifferentOFS::WithDifferentOFS): give name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++-- test/digest/test_digest_extend.rb | 39 +++++++++++++++++++------------ test/with_diffent_ofs.rb | 11 ++++----- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index efe8b5e6ea..016331eac3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -Sat Dec 25 22:08:04 2010 Nobuyoshi Nakada +Sat Dec 25 22:32:45 2010 Nobuyoshi Nakada + + * test/digest/test_digest_extend.rb (TestDigestExtend#setup): + should not depend on the result of previous tests + + * test/with_diffent_ofs.rb (DifferentOFS::WithDifferentOFS): give + name. * test/with_diffent_ofs.rb (DifferentOFS): test suite for test suites affected by $,. @@ -7,7 +13,7 @@ Sat Dec 25 22:08:04 2010 Nobuyoshi Nakada assume $, invariant. * test/csv/test_data_converters.rb, test/csv/test_table.rb: don't - not call setup within tests. + call setup within tests. Sat Dec 25 20:01:40 2010 KOSAKI Motohiro diff --git a/test/digest/test_digest_extend.rb b/test/digest/test_digest_extend.rb index 131f90d4c1..8f541afa92 100644 --- a/test/digest/test_digest_extend.rb +++ b/test/digest/test_digest_extend.rb @@ -38,6 +38,10 @@ class TestDigestExtend < Test::Unit::TestCase end end + def setup + @MyDigest = Class.new(MyDigest) + end + def test_digest_s_hexencode assert_equal('', Digest.hexencode('')) assert_equal('0102', Digest.hexencode("\1\2")) @@ -63,11 +67,11 @@ class TestDigestExtend < Test::Unit::TestCase end def test_hexdigest - assert_equal("03", MyDigest.hexdigest("foo")) + assert_equal("03", @MyDigest.hexdigest("foo")) end def test_context - digester = MyDigest.new + digester = @MyDigest.new digester.update("foo") assert_equal("\3", digester.digest) digester.update("foobar") @@ -91,7 +95,7 @@ class TestDigestExtend < Test::Unit::TestCase [:digest, :hexdigest].each do |m| exp_1st = "\3"; exp_1st = Digest.hexencode(exp_1st) if m == :hexdigest exp_2nd = "\6"; exp_2nd = Digest.hexencode(exp_2nd) if m == :hexdigest - digester = MyDigest.new + digester = @MyDigest.new digester.update("foo") obj = digester.send(m) # digest w/o param does not reset the org digester. @@ -108,7 +112,7 @@ class TestDigestExtend < Test::Unit::TestCase def test_digest_hexdigest_bang [:digest!, :hexdigest!].each do |m| exp_1st = "\3"; exp_1st = Digest.hexencode(exp_1st) if m == :hexdigest! - digester = MyDigest.new + digester = @MyDigest.new digester.update("foo") obj = digester.send(m) # digest! always resets the org digester. assert_equal(exp_1st, obj) @@ -119,30 +123,35 @@ class TestDigestExtend < Test::Unit::TestCase end def test_to_s - digester = MyDigest.new + digester = @MyDigest.new digester.update("foo") assert_equal("03", digester.to_s) end def test_length - digester = MyDigest.new - assert_equal(2, digester.length) - assert_equal(2, digester.size) - end - - def test_digest_length # breaks MyDigest#digest_length - assert_equal(1, MyDigest.new.digest_length) - MyDigest.class_eval do + @MyDigest.class_eval do def digest_length 2 end end - assert_equal(2, MyDigest.new.digest_length) + digester = @MyDigest.new + assert_equal(2, digester.length) + assert_equal(2, digester.size) + end + + def test_digest_length # breaks @MyDigest#digest_length + assert_equal(1, @MyDigest.new.digest_length) + @MyDigest.class_eval do + def digest_length + 2 + end + end + assert_equal(2, @MyDigest.new.digest_length) end def test_block_length assert_raises(RuntimeError) do - MyDigest.new.block_length + @MyDigest.new.block_length end end end diff --git a/test/with_diffent_ofs.rb b/test/with_diffent_ofs.rb index c3f6a4acc7..3192da9d1f 100644 --- a/test/with_diffent_ofs.rb +++ b/test/with_diffent_ofs.rb @@ -8,15 +8,12 @@ module DifferentOFS super end - mod = Module.new do + module WithDifferentOFS def with_diffrent_ofs - const_set(:DifferentOFS, Class.new(self).class_eval {include DifferentOFS}).name end end - class << self; self; end.class_eval do - define_method(:included) do |klass| - super(klass) - klass.extend(mod) - end + def self.included(klass) + super(klass) + klass.const_set(:DifferentOFS, Class.new(klass).class_eval {include WithDifferentOFS}).name end end