Skip to content

Commit afe799b

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

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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)