2017-05-07 12:04:49 +00:00
|
|
|
describe :env_key, shared: true do
|
2019-10-26 20:53:01 +02:00
|
|
|
before :each do
|
|
|
|
@saved_foo = ENV["foo"]
|
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
|
|
|
ENV["foo"] = @saved_foo
|
|
|
|
end
|
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
it "returns the index associated with the passed value" do
|
|
|
|
ENV["foo"] = "bar"
|
2020-10-24 15:52:37 +02:00
|
|
|
suppress_warning {
|
|
|
|
ENV.send(@method, "bar").should == "foo"
|
|
|
|
}
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil if the passed value is not found" do
|
2019-10-26 20:53:01 +02:00
|
|
|
ENV.delete("foo")
|
2020-10-24 15:52:37 +02:00
|
|
|
suppress_warning {
|
|
|
|
ENV.send(@method, "foo").should be_nil
|
|
|
|
}
|
2019-10-26 20:53:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
|
2020-10-24 15:52:37 +02:00
|
|
|
-> {
|
|
|
|
suppress_warning {
|
|
|
|
ENV.send(@method, Object.new)
|
|
|
|
}
|
|
|
|
}.should raise_error(TypeError, "no implicit conversion of Object into String")
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
end
|