summaryrefslogtreecommitdiff
path: root/spec/ruby/core/env/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/env/shared')
-rw-r--r--spec/ruby/core/env/shared/each.rb63
-rw-r--r--spec/ruby/core/env/shared/include.rb11
-rw-r--r--spec/ruby/core/env/shared/key.rb11
-rw-r--r--spec/ruby/core/env/shared/length.rb13
-rw-r--r--spec/ruby/core/env/shared/select.rb32
-rw-r--r--spec/ruby/core/env/shared/store.rb56
-rw-r--r--spec/ruby/core/env/shared/to_hash.rb21
-rw-r--r--spec/ruby/core/env/shared/update.rb21
-rw-r--r--spec/ruby/core/env/shared/value.rb11
9 files changed, 16 insertions, 223 deletions
diff --git a/spec/ruby/core/env/shared/each.rb b/spec/ruby/core/env/shared/each.rb
deleted file mode 100644
index 8a262e4862..0000000000
--- a/spec/ruby/core/env/shared/each.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-require_relative '../../enumerable/shared/enumeratorized'
-
-describe :env_each, shared: true do
- it "returns each pair" do
- orig = ENV.to_hash
- e = []
- begin
- ENV.clear
- ENV["foo"] = "bar"
- ENV["baz"] = "boo"
- ENV.send(@method) { |k, v| e << [k, v] }
- e.should include(["foo", "bar"])
- e.should include(["baz", "boo"])
- ensure
- ENV.replace orig
- end
- end
-
- it "returns an Enumerator if called without a block" do
- ENV.send(@method).should be_an_instance_of(Enumerator)
- end
-
- before :all do
- @object = ENV
- end
- it_should_behave_like :enumeratorized_with_origin_size
-
- describe "with encoding" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
-
- Encoding.default_external = Encoding::BINARY
-
- @locale_encoding = Encoding.find "locale"
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
-
- it "uses the locale encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
-
- ENV.send(@method) do |key, value|
- key.encoding.should equal(@locale_encoding)
- value.encoding.should equal(@locale_encoding)
- end
- end
-
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- Encoding.default_internal = internal = Encoding::IBM437
-
- ENV.send(@method) do |key, value|
- key.encoding.should equal(internal)
- if value.ascii_only?
- value.encoding.should equal(internal)
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/env/shared/include.rb b/spec/ruby/core/env/shared/include.rb
deleted file mode 100644
index 8d8311dcf2..0000000000
--- a/spec/ruby/core/env/shared/include.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-describe :env_include, shared: true do
- 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
- end
-end
diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb
deleted file mode 100644
index 43299beadb..0000000000
--- a/spec/ruby/core/env/shared/key.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-describe :env_key, shared: true do
- 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
- end
-end
diff --git a/spec/ruby/core/env/shared/length.rb b/spec/ruby/core/env/shared/length.rb
deleted file mode 100644
index 6d788a3f4a..0000000000
--- a/spec/ruby/core/env/shared/length.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-describe :env_length, shared: true do
- it "returns the number of ENV entries" do
- orig = ENV.to_hash
- begin
- ENV.clear
- ENV["foo"] = "bar"
- ENV["baz"] = "boo"
- ENV.send(@method).should == 2
- ensure
- ENV.replace orig
- end
- end
-end
diff --git a/spec/ruby/core/env/shared/select.rb b/spec/ruby/core/env/shared/select.rb
deleted file mode 100644
index a0b46a775a..0000000000
--- a/spec/ruby/core/env/shared/select.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-describe :env_select, shared: true do
- 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)
- end
-end
-
-describe :env_select!, shared: true do
- it "removes environment variables for which the block returns true" do
- ENV["foo"] = "bar"
- ENV.send(@method) { |k, v| k != "foo" }
- ENV["foo"].should == nil
- end
-
- it "returns self if any changes were made" do
- ENV["foo"] = "bar"
- (ENV.send(@method) { |k, v| k != "foo" }).should == ENV
- end
-
- it "returns nil if no changes were made" do
- (ENV.send(@method) { true }).should == nil
- end
-
- it "returns an Enumerator if called without a block" do
- ENV.send(@method).should be_an_instance_of(Enumerator)
- end
-end
diff --git a/spec/ruby/core/env/shared/store.rb b/spec/ruby/core/env/shared/store.rb
deleted file mode 100644
index 4949ca8c73..0000000000
--- a/spec/ruby/core/env/shared/store.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-describe :env_store, shared: true do
- after :each do
- ENV.delete("foo")
- end
-
- it "sets the environment variable to the given value" do
- ENV.send(@method, "foo", "bar")
- ENV["foo"].should == "bar"
- end
-
- it "returns the value" do
- value = "bar"
- ENV.send(@method, "foo", value).should equal(value)
- end
-
- it "deletes the environment variable when the value is nil" do
- ENV["foo"] = "bar"
- ENV.send(@method, "foo", nil)
- ENV.key?("foo").should be_false
- end
-
- it "coerces the key argument with #to_str" do
- k = mock("key")
- k.should_receive(:to_str).and_return("foo")
- ENV.send(@method, k, "bar")
- ENV["foo"].should == "bar"
- end
-
- it "coerces the value argument with #to_str" do
- v = mock("value")
- v.should_receive(:to_str).and_return("bar")
- ENV.send(@method, "foo", v)
- ENV["foo"].should == "bar"
- end
-
- it "raises TypeError when the key is not coercible to String" do
- lambda { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError)
- end
-
- it "raises TypeError when the value is not coercible to String" do
- lambda { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError)
- end
-
- it "raises Errno::EINVAL when the key contains the '=' character" do
- lambda { ENV.send(@method, "foo=", "bar") }.should raise_error(Errno::EINVAL)
- end
-
- it "raises Errno::EINVAL when the key is an empty string" do
- lambda { ENV.send(@method, "", "bar") }.should raise_error(Errno::EINVAL)
- end
-
- it "does nothing when the key is not a valid environment variable key and the value is nil" do
- ENV.send(@method, "foo=", nil)
- ENV.key?("foo=").should be_false
- end
-end
diff --git a/spec/ruby/core/env/shared/to_hash.rb b/spec/ruby/core/env/shared/to_hash.rb
index 254054c14d..7868690c38 100644
--- a/spec/ruby/core/env/shared/to_hash.rb
+++ b/spec/ruby/core/env/shared/to_hash.rb
@@ -1,22 +1,33 @@
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.should.instance_of?(Hash)
h["foo"].should == "bar"
- ENV.delete "foo"
end
it "uses the locale encoding for keys" do
- ENV.send(@method).keys.all? {|k| k.encoding == Encoding.find('locale') }.should be_true
+ ENV.send(@method).keys.each {|k| k.should.be_locale_env }
end
it "uses the locale encoding for values" do
- ENV.send(@method).values.all? {|v| v.encoding == Encoding.find('locale') }.should be_true
+ ENV.send(@method).values.each {|k| k.should.be_locale_env }
end
it "duplicates the ENV when converting to a Hash" do
h = ENV.send(@method)
- h.should_not equal ENV
+ 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
deleted file mode 100644
index cd09877243..0000000000
--- a/spec/ruby/core/env/shared/update.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-describe :env_update, shared: true do
- it "adds the parameter hash to ENV" do
- ENV["foo"].should == nil
- ENV.send @method, "foo" => "bar"
- ENV["foo"].should == "bar"
- ENV.delete "foo"
- 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"
- 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
deleted file mode 100644
index d9ee90f12d..0000000000
--- a/spec/ruby/core/env/shared/value.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-describe :env_value, shared: true do
- 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
- end
-end