diff options
author | Benoit Daloze <[email protected]> | 2023-06-26 15:55:11 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2023-06-26 15:55:11 +0200 |
commit | 515bd4214497b3af02f6eef51b496ad9a0cf6b3b (patch) | |
tree | 4554360d275a3bb9dc696f952b8f3d1bcd88f18a /spec/ruby/core/kernel | |
parent | f73fa299279ac322bd921691d1ba0e8bf2b39b5f (diff) |
Update to ruby/spec@30e1c35
Diffstat (limited to 'spec/ruby/core/kernel')
-rw-r--r-- | spec/ruby/core/kernel/Integer_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/kernel/__dir___spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/kernel/clone_spec.rb | 86 | ||||
-rw-r--r-- | spec/ruby/core/kernel/eval_spec.rb | 43 | ||||
-rw-r--r-- | spec/ruby/core/kernel/initialize_clone_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/kernel/iterator_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/kernel/lambda_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/kernel/open_spec.rb | 42 | ||||
-rw-r--r-- | spec/ruby/core/kernel/proc_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/kernel/shared/require.rb | 40 | ||||
-rw-r--r-- | spec/ruby/core/kernel/singleton_class_spec.rb | 29 | ||||
-rw-r--r-- | spec/ruby/core/kernel/taint_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/kernel/tainted_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/kernel/trust_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/kernel/untaint_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/kernel/untrust_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/core/kernel/untrusted_spec.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/kernel/warn_spec.rb | 141 |
18 files changed, 219 insertions, 304 deletions
diff --git a/spec/ruby/core/kernel/Integer_spec.rb b/spec/ruby/core/kernel/Integer_spec.rb index c691cb4c41..c37733e88d 100644 --- a/spec/ruby/core/kernel/Integer_spec.rb +++ b/spec/ruby/core/kernel/Integer_spec.rb @@ -145,7 +145,7 @@ describe :kernel_integer, shared: true do end end -describe "Integer() given a String", shared: true do +describe :kernel_integer_string, shared: true do it "raises an ArgumentError if the String is a null byte" do -> { Integer("\0") }.should raise_error(ArgumentError) end @@ -348,7 +348,7 @@ describe "Integer() given a String", shared: true do end end -describe "Integer() given a String and base", shared: true do +describe :kernel_integer_string_base, shared: true do it "raises an ArgumentError if the String is a null byte" do -> { Integer("\0", 2) }.should raise_error(ArgumentError) end @@ -784,9 +784,9 @@ describe "Kernel.Integer" do # TODO: fix these specs it_behaves_like :kernel_integer, :Integer, Kernel - it_behaves_like "Integer() given a String", :Integer + it_behaves_like :kernel_integer_string, :Integer - it_behaves_like "Integer() given a String and base", :Integer + it_behaves_like :kernel_integer_string_base, :Integer it "is a public method" do Kernel.Integer(10).should == 10 @@ -798,9 +798,9 @@ describe "Kernel#Integer" do # TODO: fix these specs it_behaves_like :kernel_integer, :Integer, Object.new - it_behaves_like "Integer() given a String", :Integer + it_behaves_like :kernel_integer_string, :Integer - it_behaves_like "Integer() given a String and base", :Integer + it_behaves_like :kernel_integer_string_base, :Integer it "is a private method" do Kernel.should have_private_instance_method(:Integer) diff --git a/spec/ruby/core/kernel/__dir___spec.rb b/spec/ruby/core/kernel/__dir___spec.rb index 324792a408..242adbf48b 100644 --- a/spec/ruby/core/kernel/__dir___spec.rb +++ b/spec/ruby/core/kernel/__dir___spec.rb @@ -19,19 +19,9 @@ describe "Kernel#__dir__" do end end - ruby_version_is ""..."3.0" do - context "when used in eval with top level binding" do - it "returns the real name of the directory containing the currently-executing file" do - eval("__dir__", binding).should == File.realpath(File.dirname(__FILE__)) - end - end - end - - ruby_version_is "3.0" do - context "when used in eval with top level binding" do - it "returns nil" do - eval("__dir__", binding).should == nil - end + context "when used in eval with top level binding" do + it "returns nil" do + eval("__dir__", binding).should == nil end end end diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb index a87c7544fe..5adcbbe603 100644 --- a/spec/ruby/core/kernel/clone_spec.rb +++ b/spec/ruby/core/kernel/clone_spec.rb @@ -45,26 +45,18 @@ describe "Kernel#clone" do end describe "with freeze: nil" do - ruby_version_is ""..."3.0" do - it "raises ArgumentError" do - -> { @obj.clone(freeze: nil) }.should raise_error(ArgumentError, /unexpected value for freeze: NilClass/) - end - end - - ruby_version_is "3.0" do - it "copies frozen state from the original, like #clone without arguments" do - o2 = @obj.clone(freeze: nil) - o2.should_not.frozen? + it "copies frozen state from the original, like #clone without arguments" do + o2 = @obj.clone(freeze: nil) + o2.should_not.frozen? - @obj.freeze - o3 = @obj.clone(freeze: nil) - o3.should.frozen? - end + @obj.freeze + o3 = @obj.clone(freeze: nil) + o3.should.frozen? + end - it "copies frozen?" do - o = "".freeze.clone(freeze: nil) - o.frozen?.should be_true - end + it "copies frozen?" do + o = "".freeze.clone(freeze: nil) + o.frozen?.should be_true end end @@ -74,33 +66,19 @@ describe "Kernel#clone" do @obj.clone(freeze: true).should.frozen? end - ruby_version_is ''...'3.0' do - it 'does not freeze the copy even if the original is not frozen' do - @obj.clone(freeze: true).should_not.frozen? - end - - it "calls #initialize_clone with no kwargs" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: true) - ScratchPad.recorded.should == [obj, {}] - end + it 'freezes the copy even if the original was not frozen' do + @obj.clone(freeze: true).should.frozen? end - ruby_version_is '3.0' do - it 'freezes the copy even if the original was not frozen' do - @obj.clone(freeze: true).should.frozen? - end - - it "calls #initialize_clone with kwargs freeze: true" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: true) - ScratchPad.recorded.should == [obj, { freeze: true }] - end + it "calls #initialize_clone with kwargs freeze: true" do + obj = KernelSpecs::CloneFreeze.new + obj.clone(freeze: true) + ScratchPad.recorded.should == [obj, { freeze: true }] + end - it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do - obj = KernelSpecs::Clone.new - -> { obj.clone(freeze: true) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') - end + it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do + obj = KernelSpecs::Clone.new + -> { obj.clone(freeze: true) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') end end @@ -114,25 +92,15 @@ describe "Kernel#clone" do @obj.clone(freeze: false).should_not.frozen? end - ruby_version_is ''...'3.0' do - it "calls #initialize_clone with no kwargs" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: false) - ScratchPad.recorded.should == [obj, {}] - end + it "calls #initialize_clone with kwargs freeze: false" do + obj = KernelSpecs::CloneFreeze.new + obj.clone(freeze: false) + ScratchPad.recorded.should == [obj, { freeze: false }] end - ruby_version_is '3.0' do - it "calls #initialize_clone with kwargs freeze: false" do - obj = KernelSpecs::CloneFreeze.new - obj.clone(freeze: false) - ScratchPad.recorded.should == [obj, { freeze: false }] - end - - it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do - obj = KernelSpecs::Clone.new - -> { obj.clone(freeze: false) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') - end + it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do + obj = KernelSpecs::Clone.new + -> { obj.clone(freeze: false) }.should raise_error(ArgumentError, 'wrong number of arguments (given 2, expected 1)') end end diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb index 9be0f2dfd3..e6761ab789 100644 --- a/spec/ruby/core/kernel/eval_spec.rb +++ b/spec/ruby/core/kernel/eval_spec.rb @@ -159,37 +159,18 @@ describe "Kernel#eval" do end end - ruby_version_is ""..."3.0" do - it "uses the filename of the binding if none is provided" do - eval("__FILE__").should == "(eval)" - suppress_warning {eval("__FILE__", binding)}.should == __FILE__ - eval("__FILE__", binding, "success").should == "success" - suppress_warning {eval("eval '__FILE__', binding")}.should == "(eval)" - suppress_warning {eval("eval '__FILE__', binding", binding)}.should == __FILE__ - suppress_warning {eval("eval '__FILE__', binding", binding, 'success')}.should == 'success' - end - - it 'uses the given binding file and line for __FILE__ and __LINE__' do - suppress_warning { - eval("[__FILE__, __LINE__]", binding).should == [__FILE__, __LINE__] - } - end - end - - ruby_version_is "3.0" do - it "uses (eval) filename if none is provided" do - eval("__FILE__").should == "(eval)" - eval("__FILE__", binding).should == "(eval)" - eval("__FILE__", binding, "success").should == "success" - eval("eval '__FILE__', binding").should == "(eval)" - eval("eval '__FILE__', binding", binding).should == "(eval)" - eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' - eval("eval '__FILE__', binding, 'success'", binding).should == 'success' - end - - it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do - eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] - end + it "uses (eval) filename if none is provided" do + eval("__FILE__").should == "(eval)" + eval("__FILE__", binding).should == "(eval)" + eval("__FILE__", binding, "success").should == "success" + eval("eval '__FILE__', binding").should == "(eval)" + eval("eval '__FILE__', binding", binding).should == "(eval)" + eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' + eval("eval '__FILE__', binding, 'success'", binding).should == 'success' + end + + it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do + eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] end # Found via Rubinius bug github:#149 diff --git a/spec/ruby/core/kernel/initialize_clone_spec.rb b/spec/ruby/core/kernel/initialize_clone_spec.rb index 2d889f5aad..21a90c19f0 100644 --- a/spec/ruby/core/kernel/initialize_clone_spec.rb +++ b/spec/ruby/core/kernel/initialize_clone_spec.rb @@ -18,11 +18,9 @@ describe "Kernel#initialize_clone" do a.send(:initialize_clone, b) end - ruby_version_is "3.0" do - it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do - a = Object.new - b = Object.new - a.send(:initialize_clone, b, freeze: true).should == a - end + it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do + a = Object.new + b = Object.new + a.send(:initialize_clone, b, freeze: true).should == a end end diff --git a/spec/ruby/core/kernel/iterator_spec.rb b/spec/ruby/core/kernel/iterator_spec.rb deleted file mode 100644 index 3fe8317f26..0000000000 --- a/spec/ruby/core/kernel/iterator_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require_relative '../../spec_helper' -require_relative 'fixtures/classes' - -ruby_version_is ""..."3.0" do - describe "Kernel#iterator?" do - it "is a private method" do - Kernel.should have_private_instance_method(:iterator?) - end - end - - describe "Kernel.iterator?" do - it "needs to be reviewed for spec completeness" - end -end diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb index 2aa4d4f2fb..2f7abc749c 100644 --- a/spec/ruby/core/kernel/lambda_spec.rb +++ b/spec/ruby/core/kernel/lambda_spec.rb @@ -136,15 +136,13 @@ describe "Kernel.lambda" do klass.new.ret.should == 1 end - ruby_version_is "3.0" do - context "when called without a literal block" do - it "warns when proc isn't a lambda" do - -> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n") - end + context "when called without a literal block" do + it "warns when proc isn't a lambda" do + -> { lambda(&proc{}) }.should complain("#{__FILE__}:#{__LINE__}: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n") + end - it "doesn't warn when proc is lambda" do - -> { lambda(&lambda{}) }.should_not complain(verbose: true) - end + it "doesn't warn when proc is lambda" do + -> { lambda(&lambda{}) }.should_not complain(verbose: true) end end end diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb index bad2ae9d2c..99793294c5 100644 --- a/spec/ruby/core/kernel/open_spec.rb +++ b/spec/ruby/core/kernel/open_spec.rb @@ -72,15 +72,13 @@ describe "Kernel#open" do -> { open }.should raise_error(ArgumentError) end - ruby_version_is "3.0" do - it "accepts options as keyword arguments" do - @file = open(@name, "r", 0666, flags: File::CREAT) - @file.should be_kind_of(File) + it "accepts options as keyword arguments" do + @file = open(@name, "r", 0666, flags: File::CREAT) + @file.should be_kind_of(File) - -> { - open(@name, "r", 0666, {flags: File::CREAT}) - }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") - end + -> { + open(@name, "r", 0666, {flags: File::CREAT}) + }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") end describe "when given an object that responds to to_open" do @@ -158,28 +156,14 @@ describe "Kernel#open" do open(@name, nil, nil) { |f| f.gets }.should == @content end - ruby_version_is ""..."3.0" do - it "works correctly when redefined by open-uri" do - code = <<~RUBY + it "is not redefined by open-uri" do + code = <<~RUBY + before = Kernel.instance_method(:open) require 'open-uri' - obj = Object.new - def obj.to_open; self; end - p open(obj) == obj - RUBY - ruby_exe(code, args: "2>&1").should == "true\n" - end - end - - ruby_version_is "3.0" do - it "is not redefined by open-uri" do - code = <<~RUBY - before = Kernel.instance_method(:open) - require 'open-uri' - after = Kernel.instance_method(:open) - p before == after - RUBY - ruby_exe(code, args: "2>&1").should == "true\n" - end + after = Kernel.instance_method(:open) + p before == after + RUBY + ruby_exe(code, args: "2>&1").should == "true\n" end end diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index 231c1f0dfb..6553b8fd04 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -40,19 +40,9 @@ describe "Kernel#proc" do proc end - ruby_version_is ""..."3.0" do - it "can be created when called with no block" do - -> { - some_method { "hello" } - }.should complain(/Capturing the given block using Kernel#proc is deprecated/) - end - end - - ruby_version_is "3.0" do - it "raises an ArgumentError when passed no block" do - -> { - some_method { "hello" } - }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - end + it "raises an ArgumentError when passed no block" do + -> { + some_method { "hello" } + }.should raise_error(ArgumentError, 'tried to create Proc object without a block') end end diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb index 5cbc11c9ec..61081b200c 100644 --- a/spec/ruby/core/kernel/shared/require.rb +++ b/spec/ruby/core/kernel/shared/require.rb @@ -262,13 +262,11 @@ describe :kernel_require, shared: true do ScratchPad.recorded.should == [:loaded] end - ruby_bug "#16926", ""..."3.0" do - it "does not load a feature twice when $LOAD_PATH has been modified" do - $LOAD_PATH.replace [CODE_LOADING_DIR] - @object.require("load_fixture").should be_true - $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR] - @object.require("load_fixture").should be_false - end + it "does not load a feature twice when $LOAD_PATH has been modified" do + $LOAD_PATH.replace [CODE_LOADING_DIR] + @object.require("load_fixture").should be_true + $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR] + @object.require("load_fixture").should be_false end end @@ -566,23 +564,21 @@ describe :kernel_require, shared: true do -> { @object.require("unicode_normalize") }.should raise_error(LoadError) end - ruby_version_is "3.0" do - it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do - Dir.chdir CODE_LOADING_DIR do - @object.send(@method, "../code/load_fixture").should be_true - end - ScratchPad.recorded.should == [:loaded] + it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do + Dir.chdir CODE_LOADING_DIR do + @object.send(@method, "../code/load_fixture").should be_true + end + ScratchPad.recorded.should == [:loaded] - $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b" - # This loads because the above load was not on the $LOAD_PATH - @object.send(@method, "load_fixture").should be_true - ScratchPad.recorded.should == [:loaded, :loaded] + $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b" + # This loads because the above load was not on the $LOAD_PATH + @object.send(@method, "load_fixture").should be_true + ScratchPad.recorded.should == [:loaded, :loaded] - $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c" - # This does not load because the above load was on the $LOAD_PATH - @object.send(@method, "load_fixture").should be_false - ScratchPad.recorded.should == [:loaded, :loaded] - end + $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c" + # This does not load because the above load was on the $LOAD_PATH + @object.send(@method, "load_fixture").should be_false + ScratchPad.recorded.should == [:loaded, :loaded] end end diff --git a/spec/ruby/core/kernel/singleton_class_spec.rb b/spec/ruby/core/kernel/singleton_class_spec.rb index 4865e29c10..23c400f9bd 100644 --- a/spec/ruby/core/kernel/singleton_class_spec.rb +++ b/spec/ruby/core/kernel/singleton_class_spec.rb @@ -1,3 +1,4 @@ +# truffleruby_primitives: true require_relative '../../spec_helper' describe "Kernel#singleton_class" do @@ -42,4 +43,32 @@ describe "Kernel#singleton_class" do obj.freeze obj.singleton_class.frozen?.should be_true end + + context "for an IO object with a replaced singleton class" do + it "looks up singleton methods from the fresh singleton class after an object instance got a new one" do + proxy = -> io { io.foo } + if RUBY_ENGINE == 'truffleruby' + # We need an inline cache with only this object seen, the best way to do that is to use a Primitive + sclass = -> io { Primitive.singleton_class(io) } + else + sclass = -> io { io.singleton_class } + end + + io = File.new(__FILE__) + io.define_singleton_method(:foo) { "old" } + sclass1 = sclass.call(io) + proxy.call(io).should == "old" + + # IO#reopen is the only method which can replace an object's singleton class + io2 = File.new(__FILE__) + io.reopen(io2) + io.define_singleton_method(:foo) { "new" } + sclass2 = sclass.call(io) + sclass2.should_not.equal?(sclass1) + proxy.call(io).should == "new" + ensure + io2.close + io.close + end + end end diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index eff9b4a450..0c16b1dbbf 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -4,9 +4,11 @@ require_relative 'fixtures/classes' describe "Kernel#taint" do ruby_version_is ""..."3.2" do it "is a no-op" do - o = Object.new - o.taint - o.should_not.tainted? + suppress_warning do + o = Object.new + o.taint + o.should_not.tainted? + end end it "warns in verbose mode" do diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb index 4e81971e58..fcae433069 100644 --- a/spec/ruby/core/kernel/tainted_spec.rb +++ b/spec/ruby/core/kernel/tainted_spec.rb @@ -4,11 +4,13 @@ require_relative 'fixtures/classes' describe "Kernel#tainted?" do ruby_version_is ""..."3.2" do it "is a no-op" do - o = mock('o') - p = mock('p') - p.taint - o.should_not.tainted? - p.should_not.tainted? + suppress_warning do + o = mock('o') + p = mock('p') + p.taint + o.should_not.tainted? + p.should_not.tainted? + end end it "warns in verbose mode" do diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb index 3a49ab3085..db6f17e0fb 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -4,10 +4,12 @@ require_relative 'fixtures/classes' describe "Kernel#trust" do ruby_version_is ""..."3.2" do it "is a no-op" do - o = Object.new.untrust - o.should_not.untrusted? - o.trust - o.should_not.untrusted? + suppress_warning do + o = Object.new.untrust + o.should_not.untrusted? + o.trust + o.should_not.untrusted? + end end it "warns in verbose mode" do diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb index a543025c5d..26b2aabbe9 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -4,10 +4,12 @@ require_relative 'fixtures/classes' describe "Kernel#untaint" do ruby_version_is ""..."3.2" do it "is a no-op" do - o = Object.new.taint - o.should_not.tainted? - o.untaint - o.should_not.tainted? + suppress_warning do + o = Object.new.taint + o.should_not.tainted? + o.untaint + o.should_not.tainted? + end end it "warns in verbose mode" do diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb index 6eefb624c0..5310cd8eb4 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -4,9 +4,11 @@ require_relative 'fixtures/classes' describe "Kernel#untrust" do ruby_version_is ""..."3.2" do it "is a no-op" do - o = Object.new - o.untrust - o.should_not.untrusted? + suppress_warning do + o = Object.new + o.untrust + o.should_not.untrusted? + end end it "warns in verbose mode" do diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb index bd0bf154ed..ea36d6c98c 100644 --- a/spec/ruby/core/kernel/untrusted_spec.rb +++ b/spec/ruby/core/kernel/untrusted_spec.rb @@ -4,10 +4,12 @@ require_relative 'fixtures/classes' describe "Kernel#untrusted?" do ruby_version_is ""..."3.2" do it "is a no-op" do - o = mock('o') - o.should_not.untrusted? - o.untrust - o.should_not.untrusted? + suppress_warning do + o = mock('o') + o.should_not.untrusted? + o.untrust + o.should_not.untrusted? + end end it "warns in verbose mode" do diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb index 7df6fa72d1..00164ad90b 100644 --- a/spec/ruby/core/kernel/warn_spec.rb +++ b/spec/ruby/core/kernel/warn_spec.rb @@ -128,36 +128,34 @@ describe "Kernel#warn" do 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 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 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 "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 + 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 it "converts first arg using to_s" do @@ -212,67 +210,52 @@ describe "Kernel#warn" do -> { warn('foo', **h) }.should complain("foo\n") end - ruby_version_is '3.0' do - it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do - verbose = $VERBOSE - $VERBOSE = false - class << Warning - alias_method :_warn, :warn - def warn(message) - ScratchPad.record(message) - end - end - - begin - ScratchPad.clear - Kernel.warn("Chunky bacon!") - ScratchPad.recorded.should == "Chunky bacon!\n" - - Kernel.warn("Deprecated bacon!", category: :deprecated) - ScratchPad.recorded.should == "Deprecated bacon!\n" - ensure - class << Warning - remove_method :warn - alias_method :warn, :_warn - remove_method :_warn - end - $VERBOSE = verbose + it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do + verbose = $VERBOSE + $VERBOSE = false + class << Warning + alias_method :_warn, :warn + def warn(message) + ScratchPad.record(message) end end - it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" do - Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil) - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose + begin + ScratchPad.clear + Kernel.warn("Chunky bacon!") + ScratchPad.recorded.should == "Chunky bacon!\n" + + Kernel.warn("Deprecated bacon!", category: :deprecated) + ScratchPad.recorded.should == "Deprecated bacon!\n" + ensure + class << Warning + remove_method :warn + alias_method :warn, :_warn + remove_method :_warn end + $VERBOSE = verbose end + end - it "calls Warning.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 + it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" 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 - ruby_version_is ''...'3.0' do - it "calls Warning.warn with no keyword arguments" do - Warning.should_receive(:warn).with("Chunky bacon!\n") - verbose = $VERBOSE - $VERBOSE = false - begin - Kernel.warn("Chunky bacon!") - ensure - $VERBOSE = verbose - end + it "calls Warning.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 |