mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 03:24:00 +02:00
refactoring: use Proc and Constant.
This commit is contained in:
parent
7342867fc9
commit
7882c43fc3
2 changed files with 5 additions and 12 deletions
|
@ -4,7 +4,7 @@ require 'test/unit'
|
|||
|
||||
class TestConst < Test::Unit::TestCase
|
||||
|
||||
setup_constants_proc = -> do
|
||||
Constants_Setup = -> do
|
||||
remove_const :TEST1 if defined? ::TestConst::TEST1
|
||||
remove_const :TEST2 if defined? ::TestConst::TEST2
|
||||
remove_const :Const if defined? ::TestConst::Const
|
||||
|
@ -24,12 +24,9 @@ class TestConst < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
define_method :setup_constants do
|
||||
setup_constants_proc.call
|
||||
end
|
||||
|
||||
def test_const
|
||||
setup_constants
|
||||
Constants_Setup.call
|
||||
|
||||
assert defined?(TEST1)
|
||||
assert_equal 1, TEST1
|
||||
assert defined?(TEST2)
|
||||
|
|
|
@ -1108,7 +1108,7 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_equal([:bar, :foo], b.local_variables.sort, bug11012)
|
||||
end
|
||||
|
||||
setup_for_test_method_in_method_visibility_should_be_public_proc = -> do
|
||||
MethodInMethodClass_Setup = -> do
|
||||
remove_const :MethodInMethodClass if defined? MethodInMethodClass
|
||||
|
||||
class MethodInMethodClass
|
||||
|
@ -1121,12 +1121,8 @@ class TestMethod < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
define_method :setup_for_test_method_in_method_visibility_should_be_public do
|
||||
setup_for_test_method_in_method_visibility_should_be_public_proc.call
|
||||
end
|
||||
|
||||
def test_method_in_method_visibility_should_be_public
|
||||
setup_for_test_method_in_method_visibility_should_be_public
|
||||
MethodInMethodClass_Setup.call
|
||||
|
||||
assert_equal([:m1].sort, MethodInMethodClass.public_instance_methods(false).sort)
|
||||
assert_equal([].sort, MethodInMethodClass.private_instance_methods(false).sort)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue