summaryrefslogtreecommitdiff
path: root/test/ruby/test_key_error.rb
blob: fe1d5bb5abf6ba0ed9094e8053185f9bedca6e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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