diff --git a/core/warning/element_reference_spec.rb b/core/warning/element_reference_spec.rb new file mode 100644 index 0000000000..8ca1793c75 --- /dev/null +++ b/core/warning/element_reference_spec.rb @@ -0,0 +1,14 @@ +require_relative '../../spec_helper' + +ruby_version_is '2.7' do + describe "Warning.[]" do + it "returns default values for categories :deprecated and :experimental" do + Warning[:deprecated].should == true + Warning[:experimental].should == true + end + + it "raises for unknown category" do + -> { Warning[:noop] }.should raise_error(ArgumentError, /unknown category: noop/) + end + end +end diff --git a/core/warning/element_set_spec.rb b/core/warning/element_set_spec.rb new file mode 100644 index 0000000000..72fd303a8c --- /dev/null +++ b/core/warning/element_set_spec.rb @@ -0,0 +1,27 @@ +require_relative '../../spec_helper' + +ruby_version_is '2.7' do + describe "Warning.[]=" do + it "sets new values for categories :deprecated and :experimental" do + Warning[:deprecated] = false + Warning[:deprecated].should == false + + Warning[:experimental] = false + Warning[:experimental].should == false + end + + it "raises for unknown category" do + -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/) + end + + it "emits and suppresses warnings for :deprecated" do + ruby_exe('Warning[:deprecated] = true; $; = ""', args: "2>&1").should =~ /is deprecated/ + ruby_exe('Warning[:deprecated] = false; $; = ""', args: "2>&1").should == "" + end + + it "emits and suppresses warnings for :experimental" do + ruby_exe('Warning[:experimental] = true; eval("0 in a")', args: "2>&1").should =~ /is experimental/ + ruby_exe('Warning[:experimental] = false; eval("0 in a")', args: "2>&1").should == "" + end + end +end