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:
nobu 2013-07-17 08:12:25 +00:00
Родитель caa14925cc
Коммит c9118e2a86
3 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -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
Просмотреть файл

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