summaryrefslogtreecommitdiff
path: root/spec/ruby/core/module/deprecate_constant_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-10-28 18:54:01 +0200
committerBenoit Daloze <eregontp@gmail.com>2021-10-28 18:54:01 +0200
commitc75df796d875b02d7b97974c7fe840f0a9de171f (patch)
treeea9a4e1b98cdd1be834fe608e24ba20399184e5a /spec/ruby/core/module/deprecate_constant_spec.rb
parent3bf36979d888cfa958c22fbf094ad10dabfe624d (diff)
Update to ruby/spec@21a48d9
Diffstat (limited to 'spec/ruby/core/module/deprecate_constant_spec.rb')
-rw-r--r--spec/ruby/core/module/deprecate_constant_spec.rb25
1 files changed, 19 insertions, 6 deletions
diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb
index 7bcced981b..faacbea03e 100644
--- a/spec/ruby/core/module/deprecate_constant_spec.rb
+++ b/spec/ruby/core/module/deprecate_constant_spec.rb
@@ -9,7 +9,6 @@ describe "Module#deprecate_constant" do
@module::PRIVATE = @value
@module.private_constant :PRIVATE
@module.deprecate_constant :PRIVATE
- @pattern = /deprecated/
end
describe "when accessing the deprecated module" do
@@ -19,7 +18,7 @@ describe "Module#deprecate_constant" do
value = nil
-> {
value = @module::PUBLIC1
- }.should complain(@pattern)
+ }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
value.should equal(@value)
-> { @module::PRIVATE }.should raise_error(NameError)
@@ -28,16 +27,30 @@ describe "Module#deprecate_constant" do
it "warns with a message" do
@module.deprecate_constant :PUBLIC1
- -> { @module::PUBLIC1 }.should complain(@pattern)
- -> { @module.const_get :PRIVATE }.should complain(@pattern)
+ -> { @module::PUBLIC1 }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
+ -> { @module.const_get :PRIVATE }.should complain(/warning: constant .+::PRIVATE is deprecated/)
+ end
+
+ ruby_version_is '2.7' do
+ it "does not warn if Warning[:deprecated] is false" do
+ @module.deprecate_constant :PUBLIC1
+
+ deprecated = Warning[:deprecated]
+ begin
+ Warning[:deprecated] = false
+ -> { @module::PUBLIC1 }.should_not complain
+ ensure
+ Warning[:deprecated] = deprecated
+ end
+ end
end
end
it "accepts multiple symbols and strings as constant names" do
@module.deprecate_constant "PUBLIC1", :PUBLIC2
- -> { @module::PUBLIC1 }.should complain(@pattern)
- -> { @module::PUBLIC2 }.should complain(@pattern)
+ -> { @module::PUBLIC1 }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
+ -> { @module::PUBLIC2 }.should complain(/warning: constant .+::PUBLIC2 is deprecated/)
end
it "returns self" do