mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
hash.c: key name in error message
* hash.c (env_fetch): Add key name to message on ENV.fetch KeyError, as well as Hash#fetch. [ruby-core:56062] [Feature #8649] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
caa14925cc
commit
c9118e2a86
3 changed files with 10 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jul 17 17:12:23 2013 Matthew M. Boedicker <matthewm@boedicker.org>
|
||||
|
||||
* hash.c (env_fetch): Add key name to message on ENV.fetch KeyError,
|
||||
as well as Hash#fetch. [ruby-core:56062] [Feature #8649]
|
||||
|
||||
Wed Jul 17 15:59:33 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* gc.c: catch up last changes for debugging/checking mode.
|
||||
|
|
2
hash.c
2
hash.c
|
@ -2411,7 +2411,7 @@ env_fetch(int argc, VALUE *argv)
|
|||
if (!env) {
|
||||
if (block_given) return rb_yield(key);
|
||||
if (argc == 1) {
|
||||
rb_raise(rb_eKeyError, "key not found");
|
||||
rb_raise(rb_eKeyError, "key not found: \"%"PRIsVALUE"\"", key);
|
||||
}
|
||||
return if_none;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,10 @@ class TestEnv < Test::Unit::TestCase
|
|||
ENV["test"] = "foo"
|
||||
assert_equal("foo", ENV.fetch("test"))
|
||||
ENV.delete("test")
|
||||
assert_raise(KeyError) { ENV.fetch("test") }
|
||||
feature8649 = '[ruby-core:56062] [Feature #8649]'
|
||||
assert_raise_with_message(KeyError, 'key not found: "test"', feature8649) do
|
||||
ENV.fetch("test")
|
||||
end
|
||||
assert_equal("foo", ENV.fetch("test", "foo"))
|
||||
assert_equal("bar", ENV.fetch("test") { "bar" })
|
||||
assert_equal("bar", ENV.fetch("test", "foo") { "bar" })
|
||||
|
|
Loading…
Reference in a new issue