Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More cleanup and organizing of Module#name specs.

  • Loading branch information...
commit 5ea363fb175928c156c884e4fa909e6665990c28 1 parent 63ae26d
@brixen brixen authored
View
16 spec/ruby/core/kernel/instance_eval_spec.rb
@@ -118,15 +118,13 @@ def foo
end
end
- ruby_version_is ""..."1.9" do
- it "makes the receiver metaclass the scoped class when used with a string" do
- obj = Object.new
- klass = obj.instance_eval %{
- class B; end
- B
- }
- klass.name.should =~ /(.+)::B/
- end
+ it "makes the receiver metaclass the scoped class when used with a string" do
+ obj = Object.new
+ klass = obj.instance_eval %{
+ class B; end
+ B
+ }
+ obj.singleton_class.const_get(:B).should be_an_instance_of(Class)
end
it "gets constants in the receiver if a string given" do
View
3  spec/ruby/core/kernel/shared/load.rb
@@ -78,8 +78,9 @@
it "sets the enclosing scope to an anonymous module if passed true for 'wrap'" do
path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
@object.load(path, true).should be_true
+
Object.const_defined?(:LoadSpecWrap).should be_false
- ScratchPad.recorded.first.should =~ /::LoadSpecWrap$/
+ ScratchPad.recorded.first.should be_an_instance_of(Class)
end
describe "(shell expansion)" do
View
6 spec/ruby/core/module/const_set_spec.rb
@@ -14,6 +14,12 @@
ConstantSpecs.const_set(:CS_CONST403, :const403).should == :const403
end
+ it "sets the name of an anonymous module" do
+ m = Module.new
+ ConstantSpecs.const_set(:CS_CONST1000, m)
+ m.name.should == "ConstantSpecs::CS_CONST1000"
+ end
+
it "raises a NameError if the name does not start with a capital letter" do
lambda { ConstantSpecs.const_set "name", 1 }.should raise_error(NameError)
end
View
4 spec/ruby/core/module/fixtures/module.rb
@@ -0,0 +1,4 @@
+module ModuleSpecs
+ module Anonymous
+ end
+end
View
94 spec/ruby/core/module/name_spec.rb
@@ -1,39 +1,95 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../fixtures/module', __FILE__)
describe "Module#name" do
ruby_version_is ""..."1.9" do
- it "returns an empty String by default" do
+ it "is an empty string for an anonymous module" do
Module.new.name.should == ""
- Class.new.name.should == ""
+ end
+
+ it "is an empty string when assigning to a constant in an anonymous module" do
+ m = Module.new
+ m::N = Module.new
+ m::N.name.should == ""
+ end
+
+ ruby_bug "http://bugs.ruby-lang.org/issues/6078", "2.0.0" do
+ it "is an empty string for a nested module created with the module keyword" do
+ m = Module.new
+ module m::N; end
+ m::N.name.should == ""
+ end
end
end
ruby_version_is "1.9" do
- it "returns nil by default" do
+ it "is nil for an anonymous module" do
Module.new.name.should be_nil
- Class.new.name.should be_nil
end
- require File.expand_path('../fixtures/name', __FILE__)
- # http://redmine.ruby-lang.org/issues/show/1833
- it "preserves the encoding in which the class was defined" do
- ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8
+ it "is nil when assigned to a constant in an anonymous module" do
+ m = Module.new
+ m::N = Module.new
+ m::N.name.should be_nil
end
- end
- it "returns the name of self" do
+ ruby_bug "http://bugs.ruby-lang.org/issues/6078", "2.0.0" do
+ it "is nil for a nested module created with the module keyword" do
+ m = Module.new
+ module m::N; end
+ m::N.name.should be_nil
+ end
+ end
+ end
+ it "is set when opened with the module keyword" do
ModuleSpecs.name.should == "ModuleSpecs"
- ModuleSpecs::Child.name.should == "ModuleSpecs::Child"
- ModuleSpecs::Parent.name.should == "ModuleSpecs::Parent"
- ModuleSpecs::Basic.name.should == "ModuleSpecs::Basic"
- ModuleSpecs::Super.name.should == "ModuleSpecs::Super"
+ end
- begin
- (ModuleSpecs::X = Module.new).name.should == "ModuleSpecs::X"
- ensure
- ModuleSpecs.send :remove_const, :X
+ it "is set when a nested module is opened with the module keyword" do
+ ModuleSpecs::Anonymous.name.should == "ModuleSpecs::Anonymous"
+ end
+
+ it "is set when assigning to a constant" do
+ m = Module.new
+ ModuleSpecs::Anonymous::A = m
+ m.name.should == "ModuleSpecs::Anonymous::A"
+ end
+
+ it "is not modified when assigning to a new constant after it has been accessed" do
+ m = Module.new
+ ModuleSpecs::Anonymous::B = m
+ m.name.should == "ModuleSpecs::Anonymous::B"
+ ModuleSpecs::Anonymous::C = m
+ m.name.should == "ModuleSpecs::Anonymous::B"
+ end
+
+ ruby_version_is "1.9" do
+ ruby_bug "http://bugs.ruby-lang.org/issues/6067", "2.0.0" do
+ it "is set with a conditional assignment to a nested constant" do
+ eval("ModuleSpecs::Anonymous::F ||= Module.new")
+ ModuleSpecs::Anonymous::F.name.should == "ModuleSpecs::Anonymous::F"
+ end
end
+
+ it "is set with a conditional assignment to a constant" do
+ module ModuleSpecs::Anonymous
+ D ||= Module.new
+ end
+ ModuleSpecs::Anonymous::D.name.should == "ModuleSpecs::Anonymous::D"
+ end
+
+ # http://redmine.ruby-lang.org/issues/show/1833
+ it "preserves the encoding in which the class was defined" do
+ require fixture(__FILE__, "name")
+ ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ it "is set when the anonymous outer module name is set" do
+ m = Module.new
+ m::N = Module.new
+ ModuleSpecs::Anonymous::E = m
+ m::N.name.should == "ModuleSpecs::Anonymous::E::N"
end
end
View
2  spec/ruby/fixtures/code/wrap_fixture.rb
@@ -1,3 +1,3 @@
class LoadSpecWrap
- ScratchPad << self.name
+ ScratchPad << self
end
View
66 spec/ruby/language/module_spec.rb
@@ -54,69 +54,3 @@ module ModuleSpecs::Modules::Klass; end
lambda { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
end
end
-
-describe "A Module's name" do
- ruby_version_is ""..."1.9" do
- it "is an empty string for an anonymous module" do
- Module.new.name.should == ""
- end
-
- it "is an empty string when assigning to a constant in an anonymous module" do
- m = Module.new
- m::N = Module.new
- m::N.name.should == ""
- end
- end
-
- ruby_version_is "1.9" do
- it "is nil for an anonymous module" do
- Module.new.name.should be_nil
- end
-
- it "is nil when assigned to a constant in an anonymous module" do
- m = Module.new
- m::N = Module.new
- m::N.name.should be_nil
- end
- end
-
- it "is set when opened with the module keyword" do
- ModuleSpecs.name.should == "ModuleSpecs"
- end
-
- it "is set when a nested module is opened with the module keyword" do
- ModuleSpecs::Anonymous.name.should == "ModuleSpecs::Anonymous"
- end
-
- it "is set when assigning to a constant" do
- m = Module.new
- ModuleSpecs::Anonymous::A = m
- m.name.should == "ModuleSpecs::Anonymous::A"
- end
-
- it "is not modified when assigning to a new constant after it has been accessed" do
- m = Module.new
- ModuleSpecs::Anonymous::B = m
- m.name.should == "ModuleSpecs::Anonymous::B"
- ModuleSpecs::Anonymous::C = m
- m.name.should == "ModuleSpecs::Anonymous::B"
- end
-
- ruby_version_is "1.9" do
- # TODO: http://bugs.ruby-lang.org/issues/6067
-
- it "is set with a conditional assignment to a constant" do
- module ModuleSpecs::Anonymous
- D ||= Module.new
- end
- ModuleSpecs::Anonymous::D.name.should == "ModuleSpecs::Anonymous::D"
- end
- end
-
- it "is set when the anonymous outer module name is set" do
- m = Module.new
- m::N = Module.new
- ModuleSpecs::Anonymous::E = m
- m::N.name.should == "ModuleSpecs::Anonymous::E::N"
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.