From add748dd77590be5aefe3898174e511c72798a08 Mon Sep 17 00:00:00 2001 From: pfarley Date: Tue, 10 Jun 2008 01:57:53 -0400 Subject: [PATCH] spec exposing inconsistency in where class variables are stored when defined inside Module methods --- spec/core/module/class_variable_defined_spec.rb | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) create mode 100644 spec/core/module/class_variable_defined_spec.rb diff --git a/spec/core/module/class_variable_defined_spec.rb b/spec/core/module/class_variable_defined_spec.rb new file mode 100644 index 0000000..73b0f40 --- /dev/null +++ b/spec/core/module/class_variable_defined_spec.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe "Module#class_variable_defined?" do + it "should assign ownership of class variables to the Modules metaclass when class variables are defined as part of method evaluation" do + declare_class_variable = Module.new do + def define_class_var + @@class_var = :value + end + end + + access_class_variable = Module.new do + extend declare_class_variable + end + + access_class_variable.define_class_var + declare_class_variable.class_variable_defined?("@@class_var").should == false + access_class_variable.class_variable_defined?("@@class_var").should == false + declare_class_variable.instance_eval("class << self; self; end").class_variable_defined?("@@class_var").should == true + end +end -- 1.5.4.4