From c530d0faf064d561bf7755c55a34921572d343ef Mon Sep 17 00:00:00 2001 From: eregon Date: Wed, 20 Sep 2017 20:18:52 +0000 Subject: Move spec/rubyspec to spec/ruby for consistency * Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- .../ruby/core/module/remove_class_variable_spec.rb | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 spec/ruby/core/module/remove_class_variable_spec.rb (limited to 'spec/ruby/core/module/remove_class_variable_spec.rb') diff --git a/spec/ruby/core/module/remove_class_variable_spec.rb b/spec/ruby/core/module/remove_class_variable_spec.rb new file mode 100644 index 0000000000..adf2c1d1f8 --- /dev/null +++ b/spec/ruby/core/module/remove_class_variable_spec.rb @@ -0,0 +1,44 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) + +describe "Module#remove_class_variable" do + it "removes class variable" do + m = ModuleSpecs::MVars.dup + m.send(:remove_class_variable, :@@mvar) + m.class_variable_defined?(:@@mvar).should == false + end + + it "returns the value of removing class variable" do + m = ModuleSpecs::MVars.dup + m.send(:remove_class_variable, :@@mvar).should == :mvar + end + + it "removes a class variable defined in a metaclass" do + obj = mock("metaclass class variable") + meta = obj.singleton_class + meta.send :class_variable_set, :@@var, 1 + meta.send(:remove_class_variable, :@@var).should == 1 + meta.class_variable_defined?(:@@var).should be_false + end + + it "raises a NameError when removing class variable declared in included module" do + c = ModuleSpecs::RemoveClassVariable.new { include ModuleSpecs::MVars.dup } + lambda { c.send(:remove_class_variable, :@@mvar) }.should raise_error(NameError) + end + + it "raises a NameError when passed a symbol with one leading @" do + lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@mvar) }.should raise_error(NameError) + end + + it "raises a NameError when passed a symbol with no leading @" do + lambda { ModuleSpecs::MVars.send(:remove_class_variable, :mvar) }.should raise_error(NameError) + end + + it "raises a NameError when an uninitialized class variable is given" do + lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@@nonexisting_class_variable) }.should raise_error(NameError) + end + + it "is public" do + Module.should_not have_private_instance_method(:remove_class_variable) + end +end -- cgit v1.2.3