From fc92a086acbc7e9cb5a9f4d048f9bbf651778679 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 20 Aug 2023 14:47:17 +0200 Subject: [PATCH] Move contents of core/env/shared/key.rb into its caller This was shared between ENV.key and ENV.index, the latter one has been removed in Ruby 3.0. This removed the need for warning suppression as well. --- core/env/key_spec.rb | 25 +++++++++++++++++++++++-- core/env/shared/key.rb | 31 ------------------------------- 2 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 core/env/shared/key.rb diff --git a/core/env/key_spec.rb b/core/env/key_spec.rb index 82cfbefa39..bf4b709450 100644 --- a/core/env/key_spec.rb +++ b/core/env/key_spec.rb @@ -1,11 +1,32 @@ require_relative '../../spec_helper' require_relative 'shared/include' -require_relative 'shared/key' describe "ENV.key?" do it_behaves_like :env_include, :key? end describe "ENV.key" do - it_behaves_like :env_key, :key + before :each do + @saved_foo = ENV["foo"] + end + + after :each do + ENV["foo"] = @saved_foo + end + + it "returns the index associated with the passed value" do + ENV["foo"] = "bar" + ENV.key("bar").should == "foo" + end + + it "returns nil if the passed value is not found" do + ENV.delete("foo") + ENV.key("foo").should be_nil + end + + it "raises TypeError if the argument is not a String and does not respond to #to_str" do + -> { + ENV.key(Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into String") + end end diff --git a/core/env/shared/key.rb b/core/env/shared/key.rb deleted file mode 100644 index 93396d2aca..0000000000 --- a/core/env/shared/key.rb +++ /dev/null @@ -1,31 +0,0 @@ -describe :env_key, shared: true do - before :each do - @saved_foo = ENV["foo"] - end - - after :each do - ENV["foo"] = @saved_foo - end - - it "returns the index associated with the passed value" do - ENV["foo"] = "bar" - suppress_warning { - ENV.send(@method, "bar").should == "foo" - } - end - - it "returns nil if the passed value is not found" do - ENV.delete("foo") - suppress_warning { - ENV.send(@method, "foo").should be_nil - } - end - - it "raises TypeError if the argument is not a String and does not respond to #to_str" do - -> { - suppress_warning { - ENV.send(@method, Object.new) - } - }.should raise_error(TypeError, "no implicit conversion of Object into String") - end -end