2018-01-25 23:51:14 -05:00
|
|
|
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)
|
2018-01-26 01:41:13 -05:00
|
|
|
error = KeyError.new
|
|
|
|
assert_raise(ArgumentError) {error.receiver}
|
2018-01-25 23:51:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_key
|
|
|
|
error = KeyError.new(key: :key)
|
|
|
|
assert_equal(:key, error.key)
|
2018-01-26 01:41:13 -05:00
|
|
|
error = KeyError.new
|
|
|
|
assert_raise(ArgumentError) {error.key}
|
2018-01-25 23:51:14 -05:00
|
|
|
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
|