Permalink
Browse files

Missing key should throw KeyError

It should not throw a NameError, but should throw a KeyError.

Fixes #26278
  • Loading branch information...
eileencodes committed Aug 26, 2016
1 parent f394f3b commit 1ec85cf9d8a6ad36c3c40cc08a0c7d8407e4b080
Showing with 7 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/http/headers.rb
  2. +6 −0 actionpack/test/dispatch/header_test.rb
@@ -86,7 +86,7 @@ def fetch(key, default = DEFAULT)
@req.fetch_header(env_name(key)) do
return default unless default == DEFAULT
return yield if block_given?
- raise NameError, key
+ raise KeyError, key
end
end
@@ -158,4 +158,10 @@ def make_headers(hash)
assert_equal({ "HTTP_REFERER"=>"http://example.com/",
"CONTENT_TYPE"=>"text/plain" }, env)
end
+
+ test "fetch exception" do
+ assert_raises KeyError do
+ @headers.fetch(:some_key_that_doesnt_exist)
+ end
+ end
end

0 comments on commit 1ec85cf

Please sign in to comment.