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

43 lines
1 KiB
Ruby
Raw Normal View History

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