1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/core/env/shared/key.rb

32 lines
730 B
Ruby
Raw Normal View History

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
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"
}
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")
end
end