mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 20:44:00 +02:00
test/ruby: better assertions
* test/ruby: use better assertions instead of mere assert. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
287d2adab0
commit
3ac0ec4ecd
45 changed files with 532 additions and 510 deletions
|
@ -151,50 +151,50 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_GE # '>='
|
||||
assert(Mixin >= User)
|
||||
assert(Mixin >= Mixin)
|
||||
assert(!(User >= Mixin))
|
||||
assert_operator(Mixin, :>=, User)
|
||||
assert_operator(Mixin, :>=, Mixin)
|
||||
assert_not_operator(User, :>=, Mixin)
|
||||
|
||||
assert(Object >= String)
|
||||
assert(String >= String)
|
||||
assert(!(String >= Object))
|
||||
assert_operator(Object, :>=, String)
|
||||
assert_operator(String, :>=, String)
|
||||
assert_not_operator(String, :>=, Object)
|
||||
end
|
||||
|
||||
def test_GT # '>'
|
||||
assert(Mixin > User)
|
||||
assert(!(Mixin > Mixin))
|
||||
assert(!(User > Mixin))
|
||||
assert_operator(Mixin, :>, User)
|
||||
assert_not_operator(Mixin, :>, Mixin)
|
||||
assert_not_operator(User, :>, Mixin)
|
||||
|
||||
assert(Object > String)
|
||||
assert(!(String > String))
|
||||
assert(!(String > Object))
|
||||
assert_operator(Object, :>, String)
|
||||
assert_not_operator(String, :>, String)
|
||||
assert_not_operator(String, :>, Object)
|
||||
end
|
||||
|
||||
def test_LE # '<='
|
||||
assert(User <= Mixin)
|
||||
assert(Mixin <= Mixin)
|
||||
assert(!(Mixin <= User))
|
||||
assert_operator(User, :<=, Mixin)
|
||||
assert_operator(Mixin, :<=, Mixin)
|
||||
assert_not_operator(Mixin, :<=, User)
|
||||
|
||||
assert(String <= Object)
|
||||
assert(String <= String)
|
||||
assert(!(Object <= String))
|
||||
assert_operator(String, :<=, Object)
|
||||
assert_operator(String, :<=, String)
|
||||
assert_not_operator(Object, :<=, String)
|
||||
end
|
||||
|
||||
def test_LT # '<'
|
||||
assert(User < Mixin)
|
||||
assert(!(Mixin < Mixin))
|
||||
assert(!(Mixin < User))
|
||||
assert_operator(User, :<, Mixin)
|
||||
assert_not_operator(Mixin, :<, Mixin)
|
||||
assert_not_operator(Mixin, :<, User)
|
||||
|
||||
assert(String < Object)
|
||||
assert(!(String < String))
|
||||
assert(!(Object < String))
|
||||
assert_operator(String, :<, Object)
|
||||
assert_not_operator(String, :<, String)
|
||||
assert_not_operator(Object, :<, String)
|
||||
end
|
||||
|
||||
def test_VERY_EQUAL # '==='
|
||||
assert(Object === self)
|
||||
assert(Test::Unit::TestCase === self)
|
||||
assert(TestModule === self)
|
||||
assert(!(String === self))
|
||||
assert_operator(Object, :===, self)
|
||||
assert_operator(Test::Unit::TestCase, :===, self)
|
||||
assert_operator(TestModule, :===, self)
|
||||
assert_not_operator(String, :===, self)
|
||||
end
|
||||
|
||||
def test_ancestors
|
||||
|
@ -214,7 +214,7 @@ class TestModule < Test::Unit::TestCase
|
|||
def test_class_eval
|
||||
Other.class_eval("CLASS_EVAL = 1")
|
||||
assert_equal(1, Other::CLASS_EVAL)
|
||||
assert(Other.constants.include?(:CLASS_EVAL))
|
||||
assert_include(Other.constants, :CLASS_EVAL)
|
||||
assert_equal(2, Other.class_eval { CLASS_EVAL })
|
||||
|
||||
Other.class_eval("@@class_eval = 'a'")
|
||||
|
@ -234,10 +234,10 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_const_defined?
|
||||
assert(Math.const_defined?(:PI))
|
||||
assert(Math.const_defined?("PI"))
|
||||
assert(!Math.const_defined?(:IP))
|
||||
assert(!Math.const_defined?("IP"))
|
||||
assert_operator(Math, :const_defined?, :PI)
|
||||
assert_operator(Math, :const_defined?, "PI")
|
||||
assert_not_operator(Math, :const_defined?, :IP)
|
||||
assert_not_operator(Math, :const_defined?, "IP")
|
||||
end
|
||||
|
||||
def test_bad_constants
|
||||
|
@ -304,9 +304,9 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_const_set
|
||||
assert(!Other.const_defined?(:KOALA))
|
||||
assert_not_operator(Other, :const_defined?, :KOALA)
|
||||
Other.const_set(:KOALA, 99)
|
||||
assert(Other.const_defined?(:KOALA))
|
||||
assert_operator(Other, :const_defined?, :KOALA)
|
||||
assert_equal(99, Other::KOALA)
|
||||
Other.const_set("WOMBAT", "Hi")
|
||||
assert_equal("Hi", Other::WOMBAT)
|
||||
|
@ -315,7 +315,7 @@ class TestModule < Test::Unit::TestCase
|
|||
def n.to_str; @count = defined?(@count) ? @count + 1 : 1; "HOGE"; end
|
||||
def n.count; @count; end
|
||||
def n.count=(v); @count=v; end
|
||||
assert(!Other.const_defined?(:HOGE))
|
||||
assert_not_operator(Other, :const_defined?, :HOGE)
|
||||
Other.const_set(n, 999)
|
||||
assert_equal(1, n.count)
|
||||
n.count = 0
|
||||
|
@ -350,7 +350,7 @@ class TestModule < Test::Unit::TestCase
|
|||
|
||||
b = a.dup
|
||||
|
||||
refute_equal original, b.inspect, bug6454
|
||||
assert_not_equal original, b.inspect, bug6454
|
||||
end
|
||||
|
||||
def test_public_include
|
||||
|
@ -437,9 +437,9 @@ class TestModule < Test::Unit::TestCase
|
|||
def test_module_eval
|
||||
User.module_eval("MODULE_EVAL = 1")
|
||||
assert_equal(1, User::MODULE_EVAL)
|
||||
assert(User.constants.include?(:MODULE_EVAL))
|
||||
assert_include(User.constants, :MODULE_EVAL)
|
||||
User.instance_eval("remove_const(:MODULE_EVAL)")
|
||||
assert(!User.constants.include?(:MODULE_EVAL))
|
||||
assert_not_include(User.constants, :MODULE_EVAL)
|
||||
end
|
||||
|
||||
def test_name
|
||||
|
@ -1264,7 +1264,7 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_constants_with_private_constant
|
||||
assert(!(::TestModule).constants.include?(:PrivateClass))
|
||||
assert_not_include(::TestModule.constants, :PrivateClass)
|
||||
end
|
||||
|
||||
def test_toplevel_private_constant
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue