diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-11-30 21:26:52 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-11-30 21:26:52 +0100 |
commit | 1243255c3a36433041012b6107a5ac48658a0895 (patch) | |
tree | 04440f84b48999ff08d4a2a16d066d0ad731400e /spec/ruby/core/env/shared | |
parent | ab8345271eb87ff155d8bd5f22f53a4cf2902c26 (diff) | |
download | ruby-1243255c3a36433041012b6107a5ac48658a0895.tar.gz |
Update to ruby/spec@4eec3dc
Diffstat (limited to 'spec/ruby/core/env/shared')
-rw-r--r-- | spec/ruby/core/env/shared/to_hash.rb | 13 | ||||
-rw-r--r-- | spec/ruby/core/env/shared/update.rb | 44 |
2 files changed, 51 insertions, 6 deletions
diff --git a/spec/ruby/core/env/shared/to_hash.rb b/spec/ruby/core/env/shared/to_hash.rb index 254054c14d..bfa5699e8d 100644 --- a/spec/ruby/core/env/shared/to_hash.rb +++ b/spec/ruby/core/env/shared/to_hash.rb @@ -1,10 +1,17 @@ describe :env_to_hash, shared: true do + before :each do + @saved_foo = ENV["foo"] + end + + after :each do + ENV["foo"]= @saved_foo + end + it "returns the ENV as a hash" do ENV["foo"] = "bar" h = ENV.send(@method) h.should be_an_instance_of(Hash) h["foo"].should == "bar" - ENV.delete "foo" end it "uses the locale encoding for keys" do @@ -18,5 +25,9 @@ describe :env_to_hash, shared: true do it "duplicates the ENV when converting to a Hash" do h = ENV.send(@method) h.should_not equal ENV + h.size.should == ENV.size + h.each_pair do |k, v| + ENV[k].should == v + end end end diff --git a/spec/ruby/core/env/shared/update.rb b/spec/ruby/core/env/shared/update.rb index 430cda5185..129a56544c 100644 --- a/spec/ruby/core/env/shared/update.rb +++ b/spec/ruby/core/env/shared/update.rb @@ -9,8 +9,8 @@ describe :env_update, shared: true do ENV["bar"] = @saved_bar end - it "adds the parameter hash to ENV" do - ENV.send @method, {"foo" => "0", "bar" => "1"} + it "adds the parameter hash to ENV, returning ENV" do + ENV.send(@method, "foo" => "0", "bar" => "1").should equal(ENV) ENV["foo"].should == "0" ENV["bar"].should == "1" end @@ -19,17 +19,43 @@ describe :env_update, shared: true do ENV.send(@method, {"foo" => "0", "bar" => "1"}).should equal(ENV) end - it "yields key, the old value and the new value when replacing entries" do + it "yields key, the old value and the new value when replacing an entry" do ENV.send @method, {"foo" => "0", "bar" => "3"} a = [] ENV.send @method, {"foo" => "1", "bar" => "4"} do |key, old, new| a << [key, old, new] + new + end + a[0].should == ["foo", "0", "1"] + a[1].should == ["bar", "3", "4"] + end + + it "yields key, the old value and the new value when replacing an entry" do + ENV.send @method, {"foo" => "0", "bar" => "3"} + ENV.send @method, {"foo" => "1", "bar" => "4"} do |key, old, new| (new.to_i + 1).to_s end ENV["foo"].should == "2" ENV["bar"].should == "5" - a[0].should == ["foo", "0", "1"] - a[1].should == ["bar", "3", "4"] + end + + ruby_version_is "2.7" do + # BUG: https://bugs.ruby-lang.org/issues/16192 + it "does not evaluate the block when the name is new" do + ENV.delete("bar") + ENV.send @method, {"foo" => "0"} + ENV.send(@method, "bar" => "1") { |key, old, new| fail "Should not get here" } + ENV["bar"].should == "1" + end + + # BUG: https://bugs.ruby-lang.org/issues/16192 + it "does not use the block's return value as the value when the name is new" do + ENV.delete("bar") + ENV.send @method, {"foo" => "0"} + ENV.send(@method, "bar" => "1") { |key, old, new| "Should not use this value" } + ENV["foo"].should == "0" + ENV["bar"].should == "1" + end end it "returns ENV when block given" do @@ -44,6 +70,14 @@ describe :env_update, shared: true do -> { ENV.send @method, "foo" => Object.new }.should raise_error(TypeError, "no implicit conversion of Object into String") end + it "raises Errno::EINVAL when a name contains the '=' character" do + -> { ENV.send(@method, "foo=" => "bar") }.should raise_error(Errno::EINVAL) + end + + it "raises Errno::EINVAL when a name is an empty string" do + -> { ENV.send(@method, "" => "bar") }.should raise_error(Errno::EINVAL) + end + it "updates good data preceding an error" do ENV["foo"] = "0" begin |