Skip to content

Commit f0b43d2

Browse files
committed
Add more tests for reopening classes
1 parent 8bb046b commit f0b43d2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

core/module/fixtures/classes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module ModuleSpecs
22
def self.without_test_modules(modules)
3-
ignore = %w[MSpecRSpecAdapter PP::ObjectMixin ModuleSpecs::IncludedInObject MainSpecs::Module ConstantSpecs::ModuleA]
3+
ignore =
4+
%w[MSpecRSpecAdapter PP::ObjectMixin ModuleSpecs::IncludedInObject
5+
ClassSpecs::IncludedInObjectWithClass MainSpecs::Module ConstantSpecs::ModuleA]
46
modules.reject { |k| ignore.include?(k.name) }
57
end
68

fixtures/class.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def self.get_class_name
126126
DEFINE_CLASS = -> do
127127
class ::A; end
128128
end
129+
130+
module IncludedInObjectWithClass
131+
class IncludedClassSpecs
132+
end
133+
end
129134
end
130135

131136
class Class
@@ -137,6 +142,8 @@ def example_instance_method_of_singleton_class; end
137142
def self.example_class_method_of_singleton_class; end
138143
end
139144
class Object
145+
include ClassSpecs::IncludedInObjectWithClass
146+
140147
def example_instance_method_of_object; end
141148
def self.example_class_method_of_object; end
142149
end

language/class_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ class ClassSpecsKeywordWithSemicolon; end
4646
-> {
4747
class ClassSpecsNumber
4848
end
49-
}.should raise_error(TypeError)
49+
}.should raise_error(TypeError, /\AClassSpecsNumber is not a class/)
50+
end
51+
52+
it "raises TypeError if constant given as class name exists and is not a Class" do
53+
-> {
54+
class ClassSpecs::IncludedInObjectWithClass
55+
end
56+
}.should raise_error(TypeError, /\AIncludedInObjectWithClass is not a class/)
5057
end
5158

5259
# test case known to be detecting bugs (JRuby, MRI)
@@ -346,6 +353,11 @@ def self.m
346353
ClassSpecs::M.m.should == 1
347354
ClassSpecs::L.singleton_class.send(:remove_method, :m)
348355
end
356+
357+
it "does not reopen a class included in Object" do
358+
class IncludedClassSpecs; end
359+
ClassSpecs::IncludedInObjectWithClass::IncludedClassSpecs.should_not == Object::IncludedClassSpecs
360+
end
349361
end
350362

351363
describe "class provides hooks" do

0 commit comments

Comments
 (0)