1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

23
spec/ruby/core/env/assoc_spec.rb vendored Normal file
View file

@ -0,0 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.assoc" do
after :each do
ENV.delete("foo")
end
it "returns an array of the key and value of the environment variable with the given key" do
ENV["foo"] = "bar"
ENV.assoc("foo").should == ["foo", "bar"]
end
it "returns nil if no environment variable with the given key exists" do
ENV.assoc("foo").should == nil
end
it "returns the key element coerced with #to_str" do
ENV["foo"] = "bar"
k = mock('key')
k.should_receive(:to_str).and_return("foo")
ENV.assoc(k).should == ["foo", "bar"]
end
end

20
spec/ruby/core/env/clear_spec.rb vendored Normal file
View file

@ -0,0 +1,20 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.clear" do
it "deletes all environment variables" do
orig = ENV.to_hash
begin
ENV.clear
# This used 'env' the helper before. That shells out to 'env' which
# itself sets up certain environment variables before it runs, because
# the shell sets them up before it runs any command.
#
# Thusly, you can ONLY test this by asking through ENV itself.
ENV.size.should == 0
ensure
ENV.replace orig
end
end
end

27
spec/ruby/core/env/delete_if_spec.rb vendored Normal file
View file

@ -0,0 +1,27 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "ENV.delete_if" do
it "deletes pairs if the block returns true" do
ENV["foo"] = "bar"
ENV.delete_if { |k, v| k == "foo" }
ENV["foo"].should == nil
end
it "returns ENV even if nothing deleted" do
ENV.delete_if { false }.should_not == nil
end
it "returns an Enumerator if no block given" do
ENV.delete_if.should be_an_instance_of(Enumerator)
end
it "deletes pairs through enumerator" do
ENV["foo"] = "bar"
enum = ENV.delete_if
enum.each { |k, v| k == "foo" }
ENV["foo"].should == nil
end
it_behaves_like :enumeratorized_with_origin_size, :delete_if, ENV
end

24
spec/ruby/core/env/delete_spec.rb vendored Normal file
View file

@ -0,0 +1,24 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.delete" do
after :each do
ENV.delete("foo")
end
it "removes the variable from the environment" do
ENV["foo"] = "bar"
ENV.delete("foo")
ENV["foo"].should == nil
end
it "returns the previous value" do
ENV["foo"] = "bar"
ENV.delete("foo").should == "bar"
end
it "yields the name to the given block if the named environment variable does not exist" do
ENV.delete("foo")
ENV.delete("foo") { |name| ScratchPad.record name }
ScratchPad.recorded.should == "foo"
end
end

32
spec/ruby/core/env/each_key_spec.rb vendored Normal file
View file

@ -0,0 +1,32 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "ENV.each_key" do
it "returns each key" do
e = []
orig = ENV.to_hash
begin
ENV.clear
ENV["1"] = "3"
ENV["2"] = "4"
ENV.each_key { |k| e << k }
e.should include("1")
e.should include("2")
ensure
ENV.replace orig
end
end
it "returns an Enumerator if called without a block" do
ENV.each_key.should be_an_instance_of(Enumerator)
end
it "returns keys in the locale encoding" do
ENV.each_key do |key|
key.encoding.should == Encoding.find('locale')
end
end
it_behaves_like :enumeratorized_with_origin_size, :each_key, ENV
end

6
spec/ruby/core/env/each_pair_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/each.rb', __FILE__)
describe "ENV.each_pair" do
it_behaves_like(:env_each, :each_pair)
end

6
spec/ruby/core/env/each_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/each.rb', __FILE__)
describe "ENV.each" do
it_behaves_like(:env_each, :each)
end

32
spec/ruby/core/env/each_value_spec.rb vendored Normal file
View file

@ -0,0 +1,32 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "ENV.each_value" do
it "returns each value" do
e = []
orig = ENV.to_hash
begin
ENV.clear
ENV["1"] = "3"
ENV["2"] = "4"
ENV.each_value { |v| e << v }
e.should include("3")
e.should include("4")
ensure
ENV.replace orig
end
end
it "returns an Enumerator if called without a block" do
ENV.each_value.should be_an_instance_of(Enumerator)
end
it "uses the locale encoding" do
ENV.each_value do |value|
value.encoding.should == Encoding.find('locale')
end
end
it_behaves_like :enumeratorized_with_origin_size, :each_value, ENV
end

View file

@ -0,0 +1,66 @@
# -*- encoding: ascii-8bit -*-
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.[]" do
before :each do
@variable = "returns_only_frozen_values"
end
after :each do
ENV.delete @variable
end
it "returns nil if the variable isn't found" do
ENV["this_var_is_never_set"].should == nil
end
it "returns only frozen values" do
ENV[@variable] = "a non-frozen string"
ENV[@variable].frozen?.should == true
end
platform_is :windows do
it "looks up values case-insensitively" do
ENV[@variable] = "bar"
ENV[@variable.upcase].should == "bar"
end
end
end
with_feature :encoding do
describe "ENV.[]" do
before :each do
@variable = "env_element_reference_encoding_specs"
@external = Encoding.default_external
@internal = Encoding.default_internal
Encoding.default_external = Encoding::ASCII_8BIT
end
after :each do
Encoding.default_external = @external
Encoding.default_internal = @internal
ENV.delete @variable
end
it "uses the locale encoding if Encoding.default_internal is nil" do
Encoding.default_internal = nil
locale = Encoding.find('locale')
locale = Encoding::ASCII_8BIT if locale == Encoding::US_ASCII
ENV[@variable] = "\xC3\xB8"
ENV[@variable].encoding.should == locale
end
it "transcodes from the locale encoding to Encoding.default_internal if set" do
# We cannot reliably know the locale encoding, so we merely check that
# the result string has the expected encoding.
ENV[@variable] = ""
Encoding.default_internal = Encoding::IBM437
ENV[@variable].encoding.should equal(Encoding::IBM437)
end
end
end

View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/store.rb', __FILE__)
describe "ENV.[]=" do
it_behaves_like(:env_store, :[]=)
end

23
spec/ruby/core/env/empty_spec.rb vendored Normal file
View file

@ -0,0 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.empty?" do
it "returns true if the Environment is empty" do
if ENV.keys.size > 0
ENV.empty?.should == false
end
orig = ENV.to_hash
begin
ENV.clear
ENV.empty?.should == true
ensure
ENV.replace orig
end
end
it "returns false if not empty" do
if ENV.keys.size > 0
ENV.empty?.should == false
end
end
end

35
spec/ruby/core/env/fetch_spec.rb vendored Normal file
View file

@ -0,0 +1,35 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.fetch" do
it "returns a value" do
ENV["foo"] = "bar"
ENV.fetch("foo").should == "bar"
ENV.delete "foo"
end
it "raises a TypeError if the key is not a String" do
lambda { ENV.fetch :should_never_be_set }.should raise_error(TypeError)
end
it "raises a KeyError if the key is not found" do
lambda { ENV.fetch "should_never_be_set" }.should raise_error(KeyError)
end
it "provides the given default parameter" do
ENV.fetch("should_never_be_set", "default").should == "default"
end
it "provides a default value from a block" do
ENV.fetch("should_never_be_set") { |k| "wanted #{k}" }.should == "wanted should_never_be_set"
end
it "warns on block and default parameter given" do
lambda do
ENV.fetch("should_never_be_set", "default") { 1 }.should == 1
end.should complain(/block supersedes default value argument/)
end
it "uses the locale encoding" do
ENV.fetch(ENV.keys.first).encoding.should == Encoding.find('locale')
end
end

6
spec/ruby/core/env/has_key_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
describe "ENV.has_key?" do
it_behaves_like(:env_include, :has_key?)
end

6
spec/ruby/core/env/has_value_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/value.rb', __FILE__)
describe "ENV.has_value?" do
it_behaves_like(:env_value, :has_value?)
end

6
spec/ruby/core/env/include_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
describe "ENV.include?" do
it_behaves_like(:env_include, :include?)
end

6
spec/ruby/core/env/index_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/key.rb', __FILE__)
describe "ENV.index" do
it_behaves_like(:env_key, :index)
end

1
spec/ruby/core/env/indexes_spec.rb vendored Normal file
View file

@ -0,0 +1 @@
require File.expand_path('../../../spec_helper', __FILE__)

1
spec/ruby/core/env/indices_spec.rb vendored Normal file
View file

@ -0,0 +1 @@
require File.expand_path('../../../spec_helper', __FILE__)

11
spec/ruby/core/env/inspect_spec.rb vendored Normal file
View file

@ -0,0 +1,11 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.inspect" do
it "returns a String that looks like a Hash with real data" do
ENV["foo"] = "bar"
ENV.inspect.should =~ /\{.*"foo"=>"bar".*\}/
ENV.delete "foo"
end
end

16
spec/ruby/core/env/invert_spec.rb vendored Normal file
View file

@ -0,0 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.invert" do
before :each do
ENV["foo"] = "bar"
end
after :each do
ENV.delete "foo"
end
it "returns a hash with ENV.keys as the values and vice versa" do
ENV.invert["bar"].should == "foo"
ENV["foo"].should == "bar"
end
end

33
spec/ruby/core/env/keep_if_spec.rb vendored Normal file
View file

@ -0,0 +1,33 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "ENV.keep_if" do
before :each do
ENV["foo"] = "bar"
end
after :each do
ENV.delete "foo"
end
it "deletes pairs if the block returns false" do
ENV.keep_if { |k, v| k != "foo" }
ENV["foo"].should == nil
end
it "returns ENV even if nothing deleted" do
ENV.keep_if { true }.should_not == nil
end
it "returns an Enumerator if no block given" do
ENV.keep_if.should be_an_instance_of(Enumerator)
end
it "deletes pairs through enumerator" do
enum = ENV.keep_if
enum.each { |k, v| k != "foo" }
ENV["foo"].should == nil
end
it_behaves_like :enumeratorized_with_origin_size, :keep_if, ENV
end

11
spec/ruby/core/env/key_spec.rb vendored Normal file
View file

@ -0,0 +1,11 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
require File.expand_path('../shared/key.rb', __FILE__)
describe "ENV.key?" do
it_behaves_like(:env_include, :key?)
end
describe "ENV.key" do
it_behaves_like(:env_key, :key)
end

14
spec/ruby/core/env/keys_spec.rb vendored Normal file
View file

@ -0,0 +1,14 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.keys" do
it "returns all the keys" do
ENV.keys.sort.should == ENV.to_hash.keys.sort
end
it "returns the keys in the locale encoding" do
ENV.keys.each do |key|
key.encoding.should == Encoding.find('locale')
end
end
end

6
spec/ruby/core/env/length_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/length.rb', __FILE__)
describe "ENV.length" do
it_behaves_like(:env_length, :length)
end

6
spec/ruby/core/env/member_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
describe "ENV.member?" do
it_behaves_like(:env_include, :member?)
end

23
spec/ruby/core/env/rassoc_spec.rb vendored Normal file
View file

@ -0,0 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.rassoc" do
after :each do
ENV.delete("foo")
end
it "returns an array of the key and value of the environment variable with the given value" do
ENV["foo"] = "bar"
ENV.rassoc("bar").should == ["foo", "bar"]
end
it "returns nil if no environment variable with the given value exists" do
ENV.rassoc("bar").should == nil
end
it "returns the value element coerced with #to_str" do
ENV["foo"] = "bar"
v = mock('value')
v.should_receive(:to_str).and_return("bar")
ENV.rassoc(v).should == ["foo", "bar"]
end
end

1
spec/ruby/core/env/rehash_spec.rb vendored Normal file
View file

@ -0,0 +1 @@
require File.expand_path('../../../spec_helper', __FILE__)

77
spec/ruby/core/env/reject_spec.rb vendored Normal file
View file

@ -0,0 +1,77 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "ENV.reject!" do
it "rejects entries based on key" do
ENV["foo"] = "bar"
ENV.reject! { |k, v| k == "foo" }
ENV["foo"].should == nil
end
it "rejects entries based on value" do
ENV["foo"] = "bar"
ENV.reject! { |k, v| v == "bar" }
ENV["foo"].should == nil
end
it "returns itself or nil" do
ENV.reject! { false }.should == nil
ENV["foo"] = "bar"
ENV.reject! { |k, v| k == "foo" }.should == ENV
ENV["foo"].should == nil
end
it "returns an Enumerator if called without a block" do
ENV.reject!.should be_an_instance_of(Enumerator)
end
it "doesn't raise if empty" do
orig = ENV.to_hash
begin
ENV.clear
lambda { ENV.reject! }.should_not raise_error(LocalJumpError)
ensure
ENV.replace orig
end
end
it_behaves_like :enumeratorized_with_origin_size, :reject!, ENV
end
describe "ENV.reject" do
it "rejects entries based on key" do
ENV["foo"] = "bar"
e = ENV.reject { |k, v| k == "foo" }
e["foo"].should == nil
ENV["foo"].should == "bar"
ENV["foo"] = nil
end
it "rejects entries based on value" do
ENV["foo"] = "bar"
e = ENV.reject { |k, v| v == "bar" }
e["foo"].should == nil
ENV["foo"].should == "bar"
ENV["foo"] = nil
end
it "returns a Hash" do
ENV.reject { false }.should be_kind_of(Hash)
end
it "returns an Enumerator if called without a block" do
ENV.reject.should be_an_instance_of(Enumerator)
end
it "doesn't raise if empty" do
orig = ENV.to_hash
begin
ENV.clear
lambda { ENV.reject }.should_not raise_error(LocalJumpError)
ensure
ENV.replace orig
end
end
it_behaves_like :enumeratorized_with_origin_size, :reject, ENV
end

15
spec/ruby/core/env/replace_spec.rb vendored Normal file
View file

@ -0,0 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.replace" do
it "replaces ENV with a Hash" do
ENV["foo"] = "bar"
e = ENV.reject { |k, v| k == "foo" }
e["baz"] = "bam"
ENV.replace e
ENV["foo"].should == nil
ENV["baz"].should == "bam"
ENV.delete "baz"
end
end

39
spec/ruby/core/env/select_spec.rb vendored Normal file
View file

@ -0,0 +1,39 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "ENV.select!" do
it "removes environment variables for which the block returns true" do
ENV["foo"] = "bar"
ENV.select! { |k, v| k != "foo" }
ENV["foo"].should == nil
end
it "returns self if any changes were made" do
ENV["foo"] = "bar"
ENV.select! { |k, v| k != "foo" }.should == ENV
end
it "returns nil if no changes were made" do
ENV.select! { true }.should == nil
end
it "returns an Enumerator if called without a block" do
ENV.select!.should be_an_instance_of(Enumerator)
end
it_behaves_like :enumeratorized_with_origin_size, :select!, ENV
end
describe "ENV.select" do
it "returns a Hash of names and values for which block return true" do
ENV["foo"] = "bar"
ENV.select { |k, v| k == "foo" }.should == {"foo" => "bar"}
ENV.delete "foo"
end
it "returns an Enumerator when no block is given" do
ENV.select.should be_an_instance_of(Enumerator)
end
it_behaves_like :enumeratorized_with_origin_size, :select, ENV
end

65
spec/ruby/core/env/shared/each.rb vendored Normal file
View file

@ -0,0 +1,65 @@
require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)
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
with_feature :encoding do
describe "with encoding" do
before :each do
@external = Encoding.default_external
@internal = Encoding.default_internal
Encoding.default_external = Encoding::ASCII_8BIT
@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
end

11
spec/ruby/core/env/shared/include.rb vendored Normal file
View file

@ -0,0 +1,11 @@
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

15
spec/ruby/core/env/shared/key.rb vendored Normal file
View file

@ -0,0 +1,15 @@
describe :env_key, shared: true do
it "needs to be reviewed for completeness"
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

13
spec/ruby/core/env/shared/length.rb vendored Normal file
View file

@ -0,0 +1,13 @@
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

56
spec/ruby/core/env/shared/store.rb vendored Normal file
View file

@ -0,0 +1,56 @@
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

22
spec/ruby/core/env/shared/to_hash.rb vendored Normal file
View file

@ -0,0 +1,22 @@
describe :env_to_hash, shared: true do
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
ENV.send(@method).keys.all? {|k| k.encoding == Encoding.find('locale') }.should be_true
end
it "uses the locale encoding for values" do
ENV.send(@method).values.all? {|v| v.encoding == Encoding.find('locale') }.should be_true
end
it "duplicates the ENV when converting to a Hash" do
h = ENV.send(@method)
h.object_id.should_not == ENV.object_id
end
end

11
spec/ruby/core/env/shared/value.rb vendored Normal file
View file

@ -0,0 +1,11 @@
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

59
spec/ruby/core/env/shift_spec.rb vendored Normal file
View file

@ -0,0 +1,59 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.shift" do
it "returns a pair and deletes it" do
ENV.empty?.should == false
orig = ENV.to_hash
begin
pair = ENV.shift
ENV.has_key?(pair.first).should == false
ensure
ENV.replace orig
end
ENV.has_key?(pair.first).should == true
end
it "returns nil if ENV.empty?" do
orig = ENV.to_hash
begin
ENV.clear
ENV.shift.should == nil
ensure
ENV.replace orig
end
end
end
with_feature :encoding do
describe "ENV.shift" do
before :each do
@orig = ENV.to_hash
@external = Encoding.default_external
@internal = Encoding.default_internal
Encoding.default_external = Encoding::ASCII_8BIT
end
after :each do
Encoding.default_external = @external
Encoding.default_internal = @internal
ENV.replace @orig
end
it "uses the locale encoding if Encoding.default_internal is nil" do
Encoding.default_internal = nil
pair = ENV.shift
pair.first.encoding.should equal(Encoding.find("locale"))
pair.last.encoding.should equal(Encoding.find("locale"))
end
it "transcodes from the locale encoding to Encoding.default_internal if set" do
Encoding.default_internal = Encoding::IBM437
pair = ENV.shift
pair.first.encoding.should equal(Encoding::IBM437)
pair.last.encoding.should equal(Encoding::IBM437)
end
end
end

6
spec/ruby/core/env/size_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/length.rb', __FILE__)
describe "ENV.size" do
it_behaves_like(:env_length, :size)
end

6
spec/ruby/core/env/store_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/store.rb', __FILE__)
describe "ENV.store" do
it_behaves_like(:env_store, :store)
end

19
spec/ruby/core/env/to_a_spec.rb vendored Normal file
View file

@ -0,0 +1,19 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.to_a" do
it "returns the ENV as an array" do
ENV["foo"] = "bar"
a = ENV.to_a
a.is_a?(Array).should == true
a.find { |e| e.first == "foo" }.should == ["foo", "bar"]
ENV.delete "foo"
end
it "returns the entries in the locale encoding" do
ENV.to_a.each do |key, value|
key.encoding.should == Encoding.find('locale')
value.encoding.should == Encoding.find('locale')
end
end
end

6
spec/ruby/core/env/to_h_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_hash.rb', __FILE__)
describe "ENV.to_hash" do
it_behaves_like(:env_to_hash, :to_h)
end

6
spec/ruby/core/env/to_hash_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_hash.rb', __FILE__)
describe "ENV.to_hash" do
it_behaves_like(:env_to_hash, :to_hash)
end

7
spec/ruby/core/env/to_s_spec.rb vendored Normal file
View file

@ -0,0 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.to_s" do
it "returns \"ENV\"" do
ENV.to_s.should == "ENV"
end
end

25
spec/ruby/core/env/update_spec.rb vendored Normal file
View file

@ -0,0 +1,25 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.update" do
it "adds the parameter hash to ENV" do
ENV["foo"].should == nil
ENV.update "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.update "foo" => "bar"
ENV["foo"].should == "bar"
ENV.update("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

6
spec/ruby/core/env/value_spec.rb vendored Normal file
View file

@ -0,0 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/value.rb', __FILE__)
describe "ENV.value?" do
it_behaves_like(:env_value, :value?)
end

17
spec/ruby/core/env/values_at_spec.rb vendored Normal file
View file

@ -0,0 +1,17 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.values_at" do
it "returns an array of the values referenced by the parameters as keys" do
ENV["foo"] = "oof"
ENV["bar"] = "rab"
ENV.values_at.should == []
ENV.values_at("bar", "foo").should == ["rab", "oof"]
ENV.delete "foo"
ENV.delete "bar"
end
it "uses the locale encoding" do
ENV.values_at(ENV.keys.first).first.encoding.should == Encoding.find('locale')
end
end

21
spec/ruby/core/env/values_spec.rb vendored Normal file
View file

@ -0,0 +1,21 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "ENV.values" do
it "returns an array of the values" do
orig = ENV.to_hash
begin
ENV.replace "a" => "b", "c" => "d"
a = ENV.values
a.sort.should == ["b", "d"]
ensure
ENV.replace orig
end
end
it "uses the locale encoding" do
ENV.values.each do |value|
value.encoding.should == Encoding.find('locale')
end
end
end