Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/module/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ModuleSpecs
def self.without_test_modules(modules)
ignore = %w[MSpecRSpecAdapter PP::ObjectMixin ModuleSpecs::IncludedInObject MainSpecs::Module ConstantSpecs::ModuleA]
ignore = %w[MSpecRSpecAdapter PP::ObjectMixin MainSpecs::Module ConstantSpecs::ModuleA]
modules.reject { |k| ignore.include?(k.name) }
end

Expand Down
42 changes: 41 additions & 1 deletion language/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ class ClassSpecsKeywordWithSemicolon; end
-> {
class ClassSpecsNumber
end
}.should raise_error(TypeError)
}.should raise_error(TypeError, /\AClassSpecsNumber is not a class/)
end

it "raises TypeError if constant given as class name exists and is a Module but not a Class" do
-> {
class ClassSpecs
end
}.should raise_error(TypeError, /\AClassSpecs is not a class/)
end

# test case known to be detecting bugs (JRuby, MRI)
Expand Down Expand Up @@ -346,6 +353,39 @@ def self.m
ClassSpecs::M.m.should == 1
ClassSpecs::L.singleton_class.send(:remove_method, :m)
end

it "does not reopen a class included in Object" do
ruby_exe(<<~RUBY).should == "false"
module IncludedInObject
class IncludedClass
end
end
class Object
include IncludedInObject
end
class IncludedClass
end
print IncludedInObject::IncludedClass == Object::IncludedClass
RUBY
end

it "does not reopen a class included in non-Object modules" do
ruby_exe(<<~RUBY).should == "false/false"
module Included
module IncludedClass; end
end
module M
include Included
module IncludedClass; end
end
class C
include Included
module IncludedClass; end
end
print Included::IncludedClass == M::IncludedClass, "/",
Included::IncludedClass == C::IncludedClass
RUBY
end
end

describe "class provides hooks" do
Expand Down
9 changes: 0 additions & 9 deletions language/fixtures/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,4 @@ class Klass

module Anonymous
end

module IncludedInObject
module IncludedModuleSpecs
end
end
end

class Object
include ModuleSpecs::IncludedInObject
end
32 changes: 28 additions & 4 deletions language/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,34 @@ module ModuleSpecs; Reopened = true; end
end

it "does not reopen a module included in Object" do
module IncludedModuleSpecs; Reopened = true; end
ModuleSpecs::IncludedInObject::IncludedModuleSpecs.should_not == Object::IncludedModuleSpecs
ensure
IncludedModuleSpecs.send(:remove_const, :Reopened)
ruby_exe(<<~RUBY).should == "false"
module IncludedInObject
module IncludedModule; end
end
class Object
include IncludedInObject
end
module IncludedModule; end
print IncludedInObject::IncludedModule == Object::IncludedModule
RUBY
end

it "does not reopen a module included in non-Object modules" do
ruby_exe(<<~RUBY).should == "false/false"
module Included
module IncludedModule; end
end
module M
include Included
module IncludedModule; end
end
class C
include Included
module IncludedModule; end
end
print Included::IncludedModule == M::IncludedModule, "/",
Included::IncludedModule == C::IncludedModule
RUBY
end

it "raises a TypeError if the constant is a Class" do
Expand Down