1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_key_error.rb
nobu ba4aba0d6c error.c: KeyError missing keyword arguments
* error.c (key_err_initialize): leave attributes for missing
  keyword arguments unset, so accessors can tell if it is missing
  or explicit nil.  [Feature #14313]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-26 06:41:13 +00:00

42 lines
1 KiB
Ruby

require 'test/unit'
class TestKeyError < Test::Unit::TestCase
def test_default
error = KeyError.new
assert_equal("KeyError", error.message)
end
def test_message
error = KeyError.new("Message")
assert_equal("Message", error.message)
end
def test_receiver
receiver = Object.new
error = KeyError.new(receiver: receiver)
assert_equal(receiver, error.receiver)
error = KeyError.new
assert_raise(ArgumentError) {error.receiver}
end
def test_key
error = KeyError.new(key: :key)
assert_equal(:key, error.key)
error = KeyError.new
assert_raise(ArgumentError) {error.key}
end
def test_receiver_and_key
receiver = Object.new
error = KeyError.new(receiver: receiver, key: :key)
assert_equal([receiver, :key],
[error.receiver, error.key])
end
def test_all
receiver = Object.new
error = KeyError.new("Message", receiver: receiver, key: :key)
assert_equal(["Message", receiver, :key],
[error.message, error.receiver, error.key])
end
end