mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Avoid E constant clashing with Minitest defined version.
Minitest sets an E constant to an empty string to save GC time. This clashes with autoloading tests which define an E constant.
This commit is contained in:
parent
7f60bedd7a
commit
afb6a2c08d
8 changed files with 45 additions and 43 deletions
|
@ -1,2 +0,0 @@
|
||||||
class A::C::E::F
|
|
||||||
end
|
|
2
activesupport/test/autoloading_fixtures/a/c/em/f.rb
Normal file
2
activesupport/test/autoloading_fixtures/a/c/em/f.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class A::C::EM::F
|
||||||
|
end
|
2
activesupport/test/autoloading_fixtures/d.rb
Normal file
2
activesupport/test/autoloading_fixtures/d.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class D
|
||||||
|
end
|
|
@ -1,2 +0,0 @@
|
||||||
class E
|
|
||||||
end
|
|
2
activesupport/test/autoloading_fixtures/em.rb
Normal file
2
activesupport/test/autoloading_fixtures/em.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class EM
|
||||||
|
end
|
|
@ -636,37 +636,37 @@ module AutoloadingCacheBehavior
|
||||||
include DependenciesTestHelpers
|
include DependenciesTestHelpers
|
||||||
def test_simple_autoloading
|
def test_simple_autoloading
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
@cache.write('foo', E.new)
|
@cache.write('foo', EM.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
assert_kind_of E, @cache.read('foo')
|
assert_kind_of EM, @cache.read('foo')
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_two_classes_autoloading
|
def test_two_classes_autoloading
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
@cache.write('foo', [E.new, ClassFolder.new])
|
@cache.write('foo', [EM.new, ClassFolder.new])
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E, :ClassFolder)
|
remove_constants(:EM, :ClassFolder)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
loaded = @cache.read('foo')
|
loaded = @cache.read('foo')
|
||||||
assert_kind_of Array, loaded
|
assert_kind_of Array, loaded
|
||||||
assert_equal 2, loaded.size
|
assert_equal 2, loaded.size
|
||||||
assert_kind_of E, loaded[0]
|
assert_kind_of EM, loaded[0]
|
||||||
assert_kind_of ClassFolder, loaded[1]
|
assert_kind_of ClassFolder, loaded[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E, :ClassFolder)
|
remove_constants(:EM, :ClassFolder)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
remove_constants(:E, :ClassFolder)
|
remove_constants(:EM, :ClassFolder)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "that Marshal#load still works" do
|
test "that Marshal#load still works" do
|
||||||
|
@ -22,14 +22,14 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
test "that a missing class is autoloaded from string" do
|
test "that a missing class is autoloaded from string" do
|
||||||
dumped = nil
|
dumped = nil
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
dumped = Marshal.dump(E.new)
|
dumped = Marshal.dump(EM.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
assert_kind_of E, Marshal.load(dumped)
|
assert_kind_of EM, Marshal.load(dumped)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,16 +50,16 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
test "that more than one missing class is autoloaded" do
|
test "that more than one missing class is autoloaded" do
|
||||||
dumped = nil
|
dumped = nil
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
dumped = Marshal.dump([E.new, ClassFolder.new])
|
dumped = Marshal.dump([EM.new, ClassFolder.new])
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E, :ClassFolder)
|
remove_constants(:EM, :ClassFolder)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
loaded = Marshal.load(dumped)
|
loaded = Marshal.load(dumped)
|
||||||
assert_equal 2, loaded.size
|
assert_equal 2, loaded.size
|
||||||
assert_kind_of E, loaded[0]
|
assert_kind_of EM, loaded[0]
|
||||||
assert_kind_of ClassFolder, loaded[1]
|
assert_kind_of ClassFolder, loaded[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,10 +67,10 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
test "that a real missing class is causing an exception" do
|
test "that a real missing class is causing an exception" do
|
||||||
dumped = nil
|
dumped = nil
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
dumped = Marshal.dump(E.new)
|
dumped = Marshal.dump(EM.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
assert_raise(NameError) do
|
assert_raise(NameError) do
|
||||||
|
@ -84,10 +84,10 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
dumped = Marshal.dump([E.new, SomeClass.new])
|
dumped = Marshal.dump([EM.new, SomeClass.new])
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
self.class.send(:remove_const, :SomeClass)
|
self.class.send(:remove_const, :SomeClass)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
Marshal.load(dumped)
|
Marshal.load(dumped)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_nothing_raised("E failed to load while we expect only SomeClass to fail loading") do
|
assert_nothing_raised("EM failed to load while we expect only SomeClass to fail loading") do
|
||||||
E.new
|
EM.new
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_raise(NameError, "We expected SomeClass to not be loaded but it is!") do
|
assert_raise(NameError, "We expected SomeClass to not be loaded but it is!") do
|
||||||
|
@ -109,15 +109,15 @@ class MarshalTest < ActiveSupport::TestCase
|
||||||
test "loading classes from files trigger autoloading" do
|
test "loading classes from files trigger autoloading" do
|
||||||
Tempfile.open("object_serializer_test") do |f|
|
Tempfile.open("object_serializer_test") do |f|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
Marshal.dump(E.new, f)
|
Marshal.dump(EM.new, f)
|
||||||
end
|
end
|
||||||
|
|
||||||
f.rewind
|
f.rewind
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
|
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
assert_kind_of E, Marshal.load(f)
|
assert_kind_of EM, Marshal.load(f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -187,7 +187,7 @@ class DependenciesTest < ActiveSupport::TestCase
|
||||||
assert_kind_of Module, A
|
assert_kind_of Module, A
|
||||||
assert_kind_of Class, A::B
|
assert_kind_of Class, A::B
|
||||||
assert_kind_of Class, A::C::D
|
assert_kind_of Class, A::C::D
|
||||||
assert_kind_of Class, A::C::E::F
|
assert_kind_of Class, A::C::EM::F
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -552,24 +552,24 @@ class DependenciesTest < ActiveSupport::TestCase
|
||||||
def test_const_missing_in_anonymous_modules_loads_top_level_constants
|
def test_const_missing_in_anonymous_modules_loads_top_level_constants
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
# class_eval STRING pushes the class to the nesting of the eval'ed code.
|
# class_eval STRING pushes the class to the nesting of the eval'ed code.
|
||||||
klass = Class.new.class_eval "E"
|
klass = Class.new.class_eval "EM"
|
||||||
assert_equal E, klass
|
assert_equal EM, klass
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_const_missing_in_anonymous_modules_raises_if_the_constant_belongs_to_Object
|
def test_const_missing_in_anonymous_modules_raises_if_the_constant_belongs_to_Object
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
require_dependency 'e'
|
require_dependency 'em'
|
||||||
|
|
||||||
mod = Module.new
|
mod = Module.new
|
||||||
e = assert_raise(NameError) { mod::E }
|
e = assert_raise(NameError) { mod::EM }
|
||||||
assert_equal 'E cannot be autoloaded from an anonymous class or module', e.message
|
assert_equal 'EM cannot be autoloaded from an anonymous class or module', e.message
|
||||||
assert_equal :E, e.name
|
assert_equal :EM, e.name
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_removal_from_tree_should_be_detected
|
def test_removal_from_tree_should_be_detected
|
||||||
|
@ -664,19 +664,19 @@ class DependenciesTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_preexisting_constants_are_not_marked_as_autoloaded
|
def test_preexisting_constants_are_not_marked_as_autoloaded
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
require_dependency 'e'
|
require_dependency 'em'
|
||||||
assert ActiveSupport::Dependencies.autoloaded?(:E)
|
assert ActiveSupport::Dependencies.autoloaded?(:EM)
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
Object.const_set :E, Class.new
|
Object.const_set :EM, Class.new
|
||||||
with_autoloading_fixtures do
|
with_autoloading_fixtures do
|
||||||
require_dependency 'e'
|
require_dependency 'em'
|
||||||
assert ! ActiveSupport::Dependencies.autoloaded?(:E), "E shouldn't be marked autoloaded!"
|
assert ! ActiveSupport::Dependencies.autoloaded?(:EM), "EM shouldn't be marked autoloaded!"
|
||||||
ActiveSupport::Dependencies.clear
|
ActiveSupport::Dependencies.clear
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
remove_constants(:E)
|
remove_constants(:EM)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_constants_in_capitalized_nesting_marked_as_autoloaded
|
def test_constants_in_capitalized_nesting_marked_as_autoloaded
|
||||||
|
|
Loading…
Reference in a new issue