Skip to content

Commit

Permalink
update rubyspec to 79484fbb65f9d1d225825aab85507b2ae0832caa
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jun 14, 2012
1 parent 7148357 commit ab260e8
Show file tree
Hide file tree
Showing 136 changed files with 3,077 additions and 1,231 deletions.
2 changes: 1 addition & 1 deletion spec/frozen/core/array/to_a_spec.rb
Expand Up @@ -10,7 +10,7 @@

it "does not return subclass instance on Array subclasses" do
e = ArraySpecs::MyArray.new(1, 2)
e.to_a.should be_kind_of(Array)
e.to_a.should be_an_instance_of(Array)
e.to_a.should == [1, 2]
end

Expand Down
115 changes: 115 additions & 0 deletions spec/frozen/core/encoding/converter/new_spec.rb
@@ -0,0 +1,115 @@
# -*- encoding: ascii-8bit -*-
require File.expand_path('../../../../spec_helper', __FILE__)

with_feature :encoding do
describe "Encoding::Converter.new" do
it "accepts a String for the source encoding" do
conv = Encoding::Converter.new("us-ascii", "utf-8")
conv.source_encoding.should == Encoding::US_ASCII
end

it "accepts a String for the destination encoding" do
conv = Encoding::Converter.new("us-ascii", "utf-8")
conv.destination_encoding.should == Encoding::UTF_8
end

it "accepts an Encoding object for the source encoding" do
conv = Encoding::Converter.new(Encoding::US_ASCII, "utf-8")
conv.source_encoding.should == Encoding::US_ASCII
end

it "accepts an Encoding object for the destination encoding" do
conv = Encoding::Converter.new("us-ascii", Encoding::UTF_8)
conv.destination_encoding.should == Encoding::UTF_8
end

it "calls #to_str to convert the source encoding argument to an encoding name" do
enc = mock("us-ascii")
enc.should_receive(:to_str).and_return("us-ascii")
conv = Encoding::Converter.new(enc, "utf-8")
conv.source_encoding.should == Encoding::US_ASCII
end

it "calls #to_str to convert the destination encoding argument to an encoding name" do
enc = mock("utf-8")
enc.should_receive(:to_str).and_return("utf-8")
conv = Encoding::Converter.new("us-ascii", enc)
conv.destination_encoding.should == Encoding::UTF_8
end

it "sets replacement from the options Hash" do
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => "fubar")
conv.replacement.should == "fubar"
end

it "calls #to_hash to convert the options argument to a Hash if not a Fixnum" do
opts = mock("encoding converter options")
opts.should_receive(:to_hash).and_return({ :replace => "fubar" })
conv = Encoding::Converter.new("us-ascii", "utf-8", opts)
conv.replacement.should == "fubar"
end

it "calls #to_str to convert the replacement object to a String" do
obj = mock("encoding converter replacement")
obj.should_receive(:to_str).and_return("fubar")
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => obj)
conv.replacement.should == "fubar"
end

it "raises a TypeError if #to_str does not return a String" do
obj = mock("encoding converter replacement")
obj.should_receive(:to_str).and_return(1)

lambda do
Encoding::Converter.new("us-ascii", "utf-8", :replace => obj)
end.should raise_error(TypeError)
end

it "raises a TypeError if passed true for the replacement object" do
lambda do
Encoding::Converter.new("us-ascii", "utf-8", :replace => true)
end.should raise_error(TypeError)
end

it "raises a TypeError if passed false for the replacement object" do
lambda do
Encoding::Converter.new("us-ascii", "utf-8", :replace => false)
end.should raise_error(TypeError)
end

it "raises a TypeError if passed a Fixnum for the replacement object" do
lambda do
Encoding::Converter.new("us-ascii", "utf-8", :replace => 1)
end.should raise_error(TypeError)
end

it "accepts an empty String for the replacement object" do
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => "")
conv.replacement.should == ""
end

describe "when passed nil for the replacement object" do
describe "when the destination encoding is not UTF-8" do
it "sets the replacement String to '?'" do
conv = Encoding::Converter.new("us-ascii", "ascii-8bit", :replace => nil)
conv.replacement.should == "?"
end

it "sets the replacement String encoding to US-ASCII" do
conv = Encoding::Converter.new("us-ascii", "ascii-8bit", :replace => nil)
conv.replacement.encoding.should == Encoding::US_ASCII
end

it "sets the replacement String to '\\uFFFD'" do
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => nil)
conv.replacement.should == "\u{fffd}".force_encoding("utf-8")
end

it "sets the replacement String encoding to UTF-8" do
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => nil)
conv.replacement.encoding.should == Encoding::UTF_8
end
end
end
end
end
25 changes: 25 additions & 0 deletions spec/frozen/core/env/assoc_spec.rb
@@ -0,0 +1,25 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.9" do
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
end
7 changes: 7 additions & 0 deletions spec/frozen/core/env/delete_if_spec.rb
Expand Up @@ -22,6 +22,13 @@
it "returns an Enumerator if no block given" do
ENV.delete_if.should be_an_instance_of(enumerator_class)
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
end

end
18 changes: 16 additions & 2 deletions spec/frozen/core/env/delete_spec.rb
@@ -1,9 +1,23 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "ENV.delete" do
it "removes the variable and return its value" do
after(:each) do
ENV.delete("foo")
end

it "removes the variable from the environment" do
ENV["foo"] = "bar"
ENV.delete("foo").should == "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") { |name| ScratchPad.record name }
ScratchPad.recorded.should == "foo"
end
end
26 changes: 26 additions & 0 deletions spec/frozen/core/env/keep_if_spec.rb
@@ -0,0 +1,26 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.9" do
describe "ENV.keep_if" do
it "deletes pairs if the block returns false" do
ENV["foo"] = "bar"
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_class)
end

it "deletes pairs through enumerator" do
ENV["foo"] = "bar"
enum = ENV.keep_if
enum.each { |k, v| k != "foo" }
ENV["foo"].should == nil
end
end
end
25 changes: 25 additions & 0 deletions spec/frozen/core/env/rassoc_spec.rb
@@ -0,0 +1,25 @@
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.9" do
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
end
28 changes: 25 additions & 3 deletions spec/frozen/core/env/select_spec.rb
@@ -1,17 +1,39 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "ENV.select" do
ruby_version_is "1.9" do
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_class)
end
end
end

describe "ENV.select" do
ruby_version_is ""..."1.9" do
it "returns the Hash for which block return true" do
it "returns an Array of names and value for which block returns true" do
ENV["foo"] = "bar"
ENV.select { |k, v| k == "foo" }.should == [["foo", "bar"]]
ENV.delete "foo"
end
end

ruby_version_is "1.9" do
it "returns the Hash for which block return true" 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"
Expand Down
75 changes: 62 additions & 13 deletions spec/frozen/core/env/shared/store.rb
@@ -1,21 +1,70 @@
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.key?("foo").should be_true
env.value?("bar").should be_true
ENV.delete "foo"
ENV["foo"].should be_nil
ENV.store "foo", "bar"
env.key?("foo").should be_true
env.value?("bar").should be_true
ENV.delete "foo"
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 "deletes key if value is nil" do
ENV.send(@method, 'foo', 'bar')
ENV.has_key?('foo').should be_true
ENV.send(@method, 'foo', nil)
ENV.has_key?('foo').should be_false
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

ruby_version_is ""..."1.9" do
it "fails silently when the key contains the '=' character" do
ENV.send(@method, "foo=", "bar")
ENV.key?("foo=").should be_false
end

it "fails silently when the key is an empty string" do
ENV.send(@method, "", "bar")
ENV.key?("").should be_false
end
end

ruby_version_is "1.9" do
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
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
19 changes: 19 additions & 0 deletions spec/frozen/core/env/shared/to_hash.rb
@@ -0,0 +1,19 @@
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

ruby_version_is "1.9" do
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
end
end
8 changes: 8 additions & 0 deletions spec/frozen/core/env/to_h_spec.rb
@@ -0,0 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_hash.rb', __FILE__)

ruby_version_is "2.0" do
describe "ENV.to_hash" do
it_behaves_like(:env_to_hash, :to_h)
end
end

0 comments on commit ab260e8

Please sign in to comment.