2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
describe "ENV.delete" do
|
2019-10-26 20:53:01 +02:00
|
|
|
before :each do
|
|
|
|
@saved_foo = ENV["foo"]
|
|
|
|
end
|
2017-05-07 12:04:49 +00:00
|
|
|
after :each do
|
2019-10-26 20:53:01 +02:00
|
|
|
ENV["foo"] = @saved_foo
|
2017-05-07 12:04:49 +00:00
|
|
|
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
|
|
|
|
|
2019-10-26 20:53:01 +02:00
|
|
|
it "returns nil if the named environment variable does not exist and no block given" do
|
|
|
|
ENV.delete("foo")
|
|
|
|
ENV.delete("foo").should == nil
|
|
|
|
end
|
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
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
|
2019-10-26 20:53:01 +02:00
|
|
|
|
2019-11-30 21:26:52 +01:00
|
|
|
it "does not evaluate the block if the envirionment variable exists" do
|
|
|
|
ENV["foo"] = "bar"
|
|
|
|
ENV.delete("foo") { |name| fail "Should not happen" }
|
|
|
|
ENV["foo"].should == nil
|
|
|
|
end
|
|
|
|
|
2019-10-26 20:53:01 +02:00
|
|
|
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
|
|
|
|
-> { ENV.delete(Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
|
|
|
|
end
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|