File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 72
72
lambda { ConstantSpecs . const_set name , 1 } . should raise_error ( TypeError )
73
73
end
74
74
75
+ describe "when overwriting an existing constant" do
76
+ it "warns if the previous value was a normal value" do
77
+ mod = Module . new
78
+ mod . const_set :Foo , 42
79
+ -> {
80
+ mod . const_set :Foo , 1
81
+ } . should complain ( /already initialized constant/ )
82
+ mod . const_get ( :Foo ) . should == 1
83
+ end
84
+
85
+ it "does not warn if the previous value was an autoload" do
86
+ mod = Module . new
87
+ mod . autoload :Foo , "not-existing"
88
+ -> {
89
+ mod . const_set :Foo , 1
90
+ } . should_not complain
91
+ mod . const_get ( :Foo ) . should == 1
92
+ end
93
+
94
+ it "does not warn if the previous value was undefined" do
95
+ path = fixture ( __FILE__ , "autoload_o.rb" )
96
+ ScratchPad . record [ ]
97
+ mod = Module . new
98
+
99
+ mod . autoload :Foo , path
100
+ -> { mod ::Foo } . should raise_error ( NameError )
101
+
102
+ mod . should have_constant ( :Foo )
103
+ mod . const_defined? ( :Foo ) . should == false
104
+ mod . autoload? ( :Foo ) . should == nil
105
+
106
+ -> {
107
+ mod . const_set :Foo , 1
108
+ } . should_not complain
109
+ mod . const_get ( :Foo ) . should == 1
110
+ end
111
+
112
+ it "does not warn if the new value is an autoload" do
113
+ mod = Module . new
114
+ mod . const_set :Foo , 42
115
+ -> {
116
+ mod . autoload :Foo , "not-existing"
117
+ } . should_not complain
118
+ mod . const_get ( :Foo ) . should == 42
119
+ end
120
+ end
121
+
75
122
describe "on a frozen module" do
76
123
before :each do
77
124
@frozen = Module . new . freeze
You can’t perform that action at this time.
0 commit comments