Permalink
Browse files

TypeError in Kernel#Hash() like other Kernel meths

  • Loading branch information...
1 parent f3b872a commit 411578d03108443a222256233680bd9c77c5ef64 @sunaku committed Sep 27, 2011
Showing with 7 additions and 0 deletions.
  1. +2 −0 lib/equal_rights_for_hash.rb
  2. +5 −0 test/kernel_hash_test.rb
@@ -1,6 +1,8 @@
module Kernel
def Hash(value)
value.to_h
+ rescue
+ raise TypeError, "invalid value for Hash: #{value}"
end
end
@@ -26,4 +26,9 @@ def fake_hash.to_hash
def test_converts_empty_array_into_hash
assert_equal({}, Hash([]))
end
+
+ def test_raises_TypeError_on_failure
+ error = assert_raise(TypeError) { Hash("bogus") }
+ assert_equal("invalid value for Hash: bogus", error.message)
+ end
end

0 comments on commit 411578d

Please sign in to comment.