diff --git a/core/kernel/warn_spec.rb b/core/kernel/warn_spec.rb index 79e78dd4a3..de08cd8cff 100644 --- a/core/kernel/warn_spec.rb +++ b/core/kernel/warn_spec.rb @@ -17,7 +17,7 @@ Kernel.should have_private_instance_method(:warn) end - it "requires multiple arguments" do + it "accepts multiple arguments" do Kernel.method(:warn).arity.should < 0 end @@ -114,6 +114,38 @@ end end + ruby_version_is "3.0" do + it "accepts :category keyword with a symbol" do + -> { + $VERBOSE = true + warn("message", category: :deprecated) + }.should output(nil, "message\n") + end + + it "accepts :category keyword with nil" do + -> { + $VERBOSE = true + warn("message", category: nil) + }.should output(nil, "message\n") + end + + it "accepts :category keyword with object convertible to symbol" do + o = Object.new + def o.to_sym; :deprecated; end + -> { + $VERBOSE = true + warn("message", category: o) + }.should output(nil, "message\n") + end + + it "raises if :category keyword is not nil and not convertible to symbol" do + -> { + $VERBOSE = true + warn("message", category: Object.new) + }.should raise_error(TypeError) + end + end + it "converts first arg using to_s" do w = KernelSpecs::WarnInNestedCall.new diff --git a/core/warning/warn_spec.rb b/core/warning/warn_spec.rb index 21424c6c76..2ded6a109d 100644 --- a/core/warning/warn_spec.rb +++ b/core/warning/warn_spec.rb @@ -51,14 +51,41 @@ def Warning.warn(msg) end end - it "is called by Kernel.warn" do - Warning.should_receive(:warn).with("Chunky bacon!\n") - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose + + ruby_version_is '3.0' do + it "is called by Kernel.warn with nil category keyword" do + Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil) + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!") + ensure + $VERBOSE = verbose + end + end + + it "is called by Kernel.warn with given category keyword converted to a symbol" do + Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated) + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!", category: 'deprecated') + ensure + $VERBOSE = verbose + end + end + end + + ruby_version_is ''...'3.0' do + it "is called by Kernel.warn" do + Warning.should_receive(:warn).with("Chunky bacon!\n") + verbose = $VERBOSE + $VERBOSE = false + begin + Kernel.warn("Chunky bacon!") + ensure + $VERBOSE = verbose + end end end end