diff options
Diffstat (limited to 'spec/ruby/core/warning')
| -rw-r--r-- | spec/ruby/core/warning/categories_spec.rb | 12 | ||||
| -rw-r--r-- | spec/ruby/core/warning/element_reference_spec.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/core/warning/element_set_spec.rb | 24 | ||||
| -rw-r--r-- | spec/ruby/core/warning/warn_spec.rb | 30 |
4 files changed, 59 insertions, 23 deletions
diff --git a/spec/ruby/core/warning/categories_spec.rb b/spec/ruby/core/warning/categories_spec.rb new file mode 100644 index 0000000000..1e310ef38b --- /dev/null +++ b/spec/ruby/core/warning/categories_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' + +ruby_version_is "3.4" do + describe "Warning.categories" do + # There might be more, but these are standard across Ruby implementations + it "returns the list of possible warning categories" do + Warning.categories.should.include? :deprecated + Warning.categories.should.include? :experimental + Warning.categories.should.include? :performance + end + end +end diff --git a/spec/ruby/core/warning/element_reference_spec.rb b/spec/ruby/core/warning/element_reference_spec.rb index c0ed37ef13..5f977759ec 100644 --- a/spec/ruby/core/warning/element_reference_spec.rb +++ b/spec/ruby/core/warning/element_reference_spec.rb @@ -10,20 +10,18 @@ describe "Warning.[]" do ruby_exe('p [Warning[:deprecated], Warning[:experimental]]', options: "-w").chomp.should == "[true, true]" end - ruby_version_is '3.3' do - it "returns default values for :performance category" do - ruby_exe('p Warning[:performance]').chomp.should == "false" - ruby_exe('p Warning[:performance]', options: "-w").chomp.should == "false" - end + it "returns default values for :performance category" do + ruby_exe('p Warning[:performance]').chomp.should == "false" + ruby_exe('p Warning[:performance]', options: "-w").chomp.should == "false" end it "raises for unknown category" do - -> { Warning[:noop] }.should raise_error(ArgumentError, /unknown category: noop/) + -> { Warning[:noop] }.should.raise(ArgumentError, /unknown category: noop/) end it "raises for non-Symbol category" do - -> { Warning[42] }.should raise_error(TypeError) - -> { Warning[false] }.should raise_error(TypeError) - -> { Warning["noop"] }.should raise_error(TypeError) + -> { Warning[42] }.should.raise(TypeError) + -> { Warning[false] }.should.raise(TypeError) + -> { Warning["noop"] }.should.raise(TypeError) end end diff --git a/spec/ruby/core/warning/element_set_spec.rb b/spec/ruby/core/warning/element_set_spec.rb index d59a7d4c9e..3c8ceb721e 100644 --- a/spec/ruby/core/warning/element_set_spec.rb +++ b/spec/ruby/core/warning/element_set_spec.rb @@ -17,25 +17,23 @@ describe "Warning.[]=" do end end - ruby_version_is '3.3' do - it "enables or disables performance warnings" do - original = Warning[:performance] - begin - Warning[:performance] = !original - Warning[:performance].should == !original - ensure - Warning[:performance] = original - end + it "enables or disables performance warnings" do + original = Warning[:performance] + begin + Warning[:performance] = !original + Warning[:performance].should == !original + ensure + Warning[:performance] = original end end it "raises for unknown category" do - -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/) + -> { Warning[:noop] = false }.should.raise(ArgumentError, /unknown category: noop/) end it "raises for non-Symbol category" do - -> { Warning[42] = false }.should raise_error(TypeError) - -> { Warning[false] = false }.should raise_error(TypeError) - -> { Warning["noop"] = false }.should raise_error(TypeError) + -> { Warning[42] = false }.should.raise(TypeError) + -> { Warning[false] = false }.should.raise(TypeError) + -> { Warning["noop"] = false }.should.raise(TypeError) end end diff --git a/spec/ruby/core/warning/warn_spec.rb b/spec/ruby/core/warning/warn_spec.rb index 572885c2b4..62f36e3454 100644 --- a/spec/ruby/core/warning/warn_spec.rb +++ b/spec/ruby/core/warning/warn_spec.rb @@ -16,7 +16,7 @@ describe "Warning.warn" do end it "extends itself" do - Warning.singleton_class.ancestors.should include(Warning) + Warning.singleton_class.ancestors.should.include?(Warning) end it "has Warning as the method owner" do @@ -97,6 +97,20 @@ describe "Warning.warn" do end end + ruby_version_is "3.4" do + it "warns when category is :strict_unused_block but Warning[:strict_unused_block] is false" do + warn_strict_unused_block = Warning[:strict_unused_block] + Warning[:strict_unused_block] = true + begin + -> { + Warning.warn("foo", category: :strict_unused_block) + }.should complain("foo") + ensure + Warning[:strict_unused_block] = warn_strict_unused_block + end + end + end + it "doesn't print message when category is :deprecated but Warning[:deprecated] is false" do warn_deprecated = Warning[:deprecated] Warning[:deprecated] = false @@ -121,6 +135,20 @@ describe "Warning.warn" do end end + ruby_version_is "3.4" do + it "doesn't print message when category is :strict_unused_block but Warning[:strict_unused_block] is false" do + warn_strict_unused_block = Warning[:strict_unused_block] + Warning[:strict_unused_block] = false + begin + -> { + Warning.warn("foo", category: :strict_unused_block) + }.should_not complain + ensure + Warning[:strict_unused_block] = warn_strict_unused_block + end + end + end + ruby_bug '#20573', ''...'3.4' do it "isn't called by Kernel.warn when category is :deprecated but Warning[:deprecated] is false" do warn_deprecated = Warning[:deprecated] |
