Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Spec ENV.{assoc,rassoc}

  • Loading branch information...
commit d09bcdf56123c1992be984a52a0d3986c1e89251 1 parent a85b73f
@jfirebaugh jfirebaugh authored brixen committed
Showing with 50 additions and 0 deletions.
  1. +25 −0 core/env/assoc_spec.rb
  2. +25 −0 core/env/rassoc_spec.rb
View
25 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
View
25 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
Please sign in to comment.
Something went wrong with that request. Please try again.