aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/env/shared
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-10-26 20:53:01 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-10-26 20:53:01 +0200
commit664e96b1de816c813c29f61e16a2031a7af7ba86 (patch)
tree7f4691847cd6b3282812eea7e2be3758e08d1433 /spec/ruby/core/env/shared
parent3eb0d50c0baae916f4486c264605b18e77bee0dc (diff)
downloadruby-664e96b1de816c813c29f61e16a2031a7af7ba86.tar.gz
Update to ruby/spec@28a728b
Diffstat (limited to 'spec/ruby/core/env/shared')
-rw-r--r--spec/ruby/core/env/shared/each.rb6
-rw-r--r--spec/ruby/core/env/shared/include.rb16
-rw-r--r--spec/ruby/core/env/shared/key.rb16
-rw-r--r--spec/ruby/core/env/shared/select.rb33
-rw-r--r--spec/ruby/core/env/shared/store.rb10
-rw-r--r--spec/ruby/core/env/shared/update.rb71
-rw-r--r--spec/ruby/core/env/shared/value.rb15
7 files changed, 142 insertions, 25 deletions
diff --git a/spec/ruby/core/env/shared/each.rb b/spec/ruby/core/env/shared/each.rb
index 261ad3a2a6..eb375046d6 100644
--- a/spec/ruby/core/env/shared/each.rb
+++ b/spec/ruby/core/env/shared/each.rb
@@ -17,7 +17,11 @@ describe :env_each, shared: true do
end
it "returns an Enumerator if called without a block" do
- ENV.send(@method).should be_an_instance_of(Enumerator)
+ enum = ENV.send(@method)
+ enum.should be_an_instance_of(Enumerator)
+ enum.each do |name, value|
+ ENV[name].should == value
+ end
end
before :all do
diff --git a/spec/ruby/core/env/shared/include.rb b/spec/ruby/core/env/shared/include.rb
index 8d8311dcf2..3efcd523d6 100644
--- a/spec/ruby/core/env/shared/include.rb
+++ b/spec/ruby/core/env/shared/include.rb
@@ -1,11 +1,23 @@
describe :env_include, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
it "returns true if ENV has the key" do
ENV["foo"] = "bar"
ENV.send(@method, "foo").should == true
- ENV.delete "foo"
end
it "returns false if ENV doesn't include the key" do
- ENV.send(@method, "should_never_be_set").should == false
+ ENV.delete("foo")
+ ENV.send(@method, "foo").should == false
+ end
+
+ it "raises TypeError if the argument is not a String and does not respond to #to_str" do
+ -> { ENV.send(@method, Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
end
end
diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb
index 43299beadb..fcb3a9b8c5 100644
--- a/spec/ruby/core/env/shared/key.rb
+++ b/spec/ruby/core/env/shared/key.rb
@@ -1,11 +1,23 @@
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"
ENV.send(@method, "bar").should == "foo"
- ENV.delete "foo"
end
it "returns nil if the passed value is not found" do
- ENV.send(@method, "should_never_be_set").should be_nil
+ ENV.delete("foo")
+ 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
+ -> { ENV.send(@method, Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
end
end
diff --git a/spec/ruby/core/env/shared/select.rb b/spec/ruby/core/env/shared/select.rb
index a0b46a775a..75ba112a32 100644
--- a/spec/ruby/core/env/shared/select.rb
+++ b/spec/ruby/core/env/shared/select.rb
@@ -1,16 +1,38 @@
describe :env_select, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
it "returns a Hash of names and values for which block return true" do
ENV["foo"] = "bar"
(ENV.send(@method) { |k, v| k == "foo" }).should == { "foo" => "bar" }
- ENV.delete "foo"
end
it "returns an Enumerator when no block is given" do
- ENV.send(@method).should be_an_instance_of(Enumerator)
+ enum = ENV.send(@method)
+ enum.should be_an_instance_of(Enumerator)
+ end
+
+ it "selects via the enumerator" do
+ enum = ENV.send(@method)
+ ENV["foo"] = "bar"
+ enum.each { |k, v| k == "foo" }.should == { "foo" => "bar"}
end
end
describe :env_select!, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
it "removes environment variables for which the block returns true" do
ENV["foo"] = "bar"
ENV.send(@method) { |k, v| k != "foo" }
@@ -29,4 +51,11 @@ describe :env_select!, shared: true do
it "returns an Enumerator if called without a block" do
ENV.send(@method).should be_an_instance_of(Enumerator)
end
+
+ it "selects via the enumerator" do
+ enum = ENV.send(@method)
+ ENV["foo"] = "bar"
+ enum.each { |k, v| k != "foo" }
+ ENV["foo"].should == nil
+ end
end
diff --git a/spec/ruby/core/env/shared/store.rb b/spec/ruby/core/env/shared/store.rb
index 6ae91ef8fc..d6265c66a5 100644
--- a/spec/ruby/core/env/shared/store.rb
+++ b/spec/ruby/core/env/shared/store.rb
@@ -1,6 +1,10 @@
describe :env_store, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
after :each do
- ENV.delete("foo")
+ ENV["foo"] = @saved_foo
end
it "sets the environment variable to the given value" do
@@ -34,11 +38,11 @@ describe :env_store, shared: true do
end
it "raises TypeError when the key is not coercible to String" do
- -> { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError)
+ -> { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError, "no implicit conversion of Object into String")
end
it "raises TypeError when the value is not coercible to String" do
- -> { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError)
+ -> { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
end
it "raises Errno::EINVAL when the key contains the '=' character" do
diff --git a/spec/ruby/core/env/shared/update.rb b/spec/ruby/core/env/shared/update.rb
index cd09877243..430cda5185 100644
--- a/spec/ruby/core/env/shared/update.rb
+++ b/spec/ruby/core/env/shared/update.rb
@@ -1,21 +1,66 @@
describe :env_update, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ @saved_bar = ENV["bar"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ ENV["bar"] = @saved_bar
+ end
+
it "adds the parameter hash to ENV" do
- ENV["foo"].should == nil
- ENV.send @method, "foo" => "bar"
- ENV["foo"].should == "bar"
- ENV.delete "foo"
+ ENV.send @method, {"foo" => "0", "bar" => "1"}
+ ENV["foo"].should == "0"
+ ENV["bar"].should == "1"
+ end
+
+ it "returns ENV when no block given" 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
- ENV.send @method, "foo" => "bar"
- ENV["foo"].should == "bar"
- ENV.send(@method, "foo" => "boo") do |key, old, new|
- key.should == "foo"
- old.should == "bar"
- new.should == "boo"
- "rab"
+ ENV.send @method, {"foo" => "0", "bar" => "3"}
+ a = []
+ ENV.send @method, {"foo" => "1", "bar" => "4"} do |key, old, new|
+ a << [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
+
+ it "returns ENV when block given" do
+ ENV.send(@method, {"foo" => "0", "bar" => "1"}){}.should equal(ENV)
+ end
+
+ it "raises TypeError when a name is not coercible to String" do
+ -> { ENV.send @method, Object.new => "0" }.should raise_error(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises TypeError when a value is not coercible to String" do
+ -> { ENV.send @method, "foo" => Object.new }.should raise_error(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "updates good data preceding an error" do
+ ENV["foo"] = "0"
+ begin
+ ENV.send @method, {"foo" => "2", Object.new => "1"}
+ rescue TypeError
+ ensure
+ ENV["foo"].should == "2"
+ end
+ end
+
+ it "does not update good data following an error" do
+ ENV["foo"] = "0"
+ begin
+ ENV.send @method, {Object.new => "1", "foo" => "2"}
+ rescue TypeError
+ ensure
+ ENV["foo"].should == "0"
end
- ENV["foo"].should == "rab"
- ENV.delete "foo"
end
end
diff --git a/spec/ruby/core/env/shared/value.rb b/spec/ruby/core/env/shared/value.rb
index d9ee90f12d..bef96b5fef 100644
--- a/spec/ruby/core/env/shared/value.rb
+++ b/spec/ruby/core/env/shared/value.rb
@@ -1,11 +1,22 @@
describe :env_value, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
it "returns true if ENV has the value" do
ENV["foo"] = "bar"
ENV.send(@method, "bar").should == true
- ENV["foo"] = nil
end
it "returns false if ENV doesn't have the value" do
- ENV.send(@method, "this_value_should_never_exist").should == false
+ ENV.send(@method, "foo").should == false
+ end
+
+ it "returns nil if the argument is not a String and does not respond to #to_str" do
+ ENV.send(@method, Object.new).should == nil
end
end