[前][次][番号順一覧][スレッド一覧]

ruby-changes:28154

From: nobu <ko1@a...>
Date: Tue, 9 Apr 2013 16:22:00 +0900 (JST)
Subject: [ruby-changes:28154] nobu:r40206 (trunk): test_{env,hash}.rb: descriptive assertions

nobu	2013-04-09 16:21:50 +0900 (Tue, 09 Apr 2013)

  New Revision: 40206

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40206

  Log:
    test_{env,hash}.rb: descriptive assertions
    
    * test/ruby/test_{env,hash}.rb: use descriptive assertions than plain
      assert.

  Modified files:
    trunk/test/ruby/test_env.rb
    trunk/test/ruby/test_hash.rb

Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 40205)
+++ test/ruby/test_hash.rb	(revision 40206)
@@ -21,8 +21,8 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L21
        end)
 
     assert_equal(3, x.length)
-    assert(x.has_key?(1))
-    assert(x.has_value?(4))
+    assert_send([x, :has_key?, 1])
+    assert_send([x, :has_value?, 4])
     assert_equal([4,6], x.values_at(2,3))
     assert_equal({1=>2, 2=>4, 3=>6}, x)
 
@@ -208,17 +208,17 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L208
     h2 = @cls[ "a" => 1, "c" => 2, 7 => 35 ]
     h3 = @cls[ "a" => 1, "c" => 2, 7 => 35 ]
     h4 = @cls[ ]
-    assert(h1 == h1)
-    assert(h2 == h2)
-    assert(h3 == h3)
-    assert(h4 == h4)
-    assert(!(h1 == h2))
-    assert(h2 == h3)
-    assert(!(h3 == h4))
+    assert_equal(h1, h1)
+    assert_equal(h2, h2)
+    assert_equal(h3, h3)
+    assert_equal(h4, h4)
+    assert_not_equal(h1, h2)
+    assert_equal(h2, h3)
+    assert_not_equal(h3, h4)
   end
 
   def test_clear
-    assert(@h.size > 0)
+    assert_operator(@h.size, :>, 0)
     @h.clear
     assert_equal(0, @h.size)
     assert_nil(@h[1])
@@ -235,7 +235,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L235
           b = a.clone
 
           assert_equal(a, b)
-          assert(a.__id__ != b.__id__)
+          assert_not_same(a, b)
           assert_equal(a.frozen?, b.frozen?)
           assert_equal(a.untrusted?, b.untrusted?)
           assert_equal(a.tainted?, b.tainted?)
@@ -327,7 +327,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L327
           b = a.dup
 
           assert_equal(a, b)
-          assert(a.__id__ != b.__id__)
+          assert_not_same(a, b)
           assert_equal(false, b.frozen?)
           assert_equal(a.tainted?, b.tainted?)
           assert_equal(a.untrusted?, b.untrusted?)
@@ -397,8 +397,8 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L397
   end
 
   def test_empty?
-    assert(@cls[].empty?)
-    assert(!@h.empty?)
+    assert_empty(@cls[])
+    assert_not_empty(@h)
   end
 
   def test_fetch
@@ -453,11 +453,11 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L453
 
   def test_values_at
     res = @h.values_at('dog', 'cat', 'horse')
-    assert(res.length == 3)
+    assert_equal(3, res.length)
     assert_equal([nil, nil, nil], res)
 
     res = @h.values_at
-    assert(res.length == 0)
+    assert_equal(0, res.length)
 
     res = @h.values_at(3, 2, 1, nil)
     assert_equal 4, res.length
@@ -476,7 +476,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L476
     assert_equal(nil,  h['nil'])
 
     h.each do |k, v|
-      assert(@h.key?(v))    # not true in general, but works here
+      assert_send([@h, :key?, v])    # not true in general, but works here
     end
 
     h = @cls[ 'a' => 1, 'b' => 2, 'c' => 1].invert
@@ -841,18 +841,18 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L841
   end
 
   def test_equal2
-    assert({} != 0)
+    assert_not_equal(0, {})
     o = Object.new
     def o.to_hash; {}; end
     def o.==(x); true; end
-    assert({} == o)
+    assert_equal({}, o)
     def o.==(x); false; end
-    assert({} != o)
+    assert_not_equal({}, o)
 
     h1 = {1=>2}; h2 = {3=>4}
-    assert(h1 != h2)
+    assert_not_equal(h1, h2)
     h1 = {1=>2}; h2 = {1=>4}
-    assert(h1 != h2)
+    assert_not_equal(h1, h2)
   end
 
   def test_eql
@@ -922,11 +922,11 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L922
 
   def test_compare_by_identity
     a = "foo"
-    assert(!{}.compare_by_identity?)
+    assert_not_predicate({}, :compare_by_identity?)
     h = { a => "bar" }
-    assert(!h.compare_by_identity?)
+    assert_not_predicate(h, :compare_by_identity?)
     h.compare_by_identity
-    assert(h.compare_by_identity?)
+    assert_predicate(h, :compare_by_identity?)
     #assert_equal("bar", h[a])
     assert_nil(h["foo"])
   end
Index: test/ruby/test_env.rb
===================================================================
--- test/ruby/test_env.rb	(revision 40205)
+++ test/ruby/test_env.rb	(revision 40206)
@@ -270,15 +270,15 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L270
 
   def test_empty_p
     ENV.clear
-    assert(ENV.empty?)
+    assert_predicate(ENV, :empty?)
     ENV["test"] = "foo"
-    assert(!ENV.empty?)
+    assert_not_predicate(ENV, :empty?)
   end
 
   def test_has_key
-    assert(!ENV.has_key?("test"))
+    assert_not_send([ENV, :has_key?, "test"])
     ENV["test"] = "foo"
-    assert(ENV.has_key?("test"))
+    assert_send([ENV, :has_key?, "test"])
     assert_raise(ArgumentError) { ENV.has_key?("foo\0bar") }
   end
 
@@ -298,9 +298,9 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L298
 
   def test_has_value2
     ENV.clear
-    assert(!ENV.has_value?("foo"))
+    assert_not_send([ENV, :has_value?, "foo"])
     ENV["test"] = "foo"
-    assert(ENV.has_value?("foo"))
+    assert_send([ENV, :has_value?, "foo"])
   end
 
   def test_rassoc

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]