summaryrefslogtreecommitdiffhomepage
path: root/test/t/nomethoderror.rb
blob: 35cbdaee9c1afa97d3227ae07ad14640b2bc3d87 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
##
# NoMethodError ISO Test

assert('NoMethodError', '15.2.32') do
  NoMethodError.class == Class
  assert_raise NoMethodError do
    doesNotExistAsAMethodNameForVerySure("")
  end
end

assert('NoMethodError#args', '15.2.32.2.1') do
  a = NoMethodError.new 'test', :test, [1, 2]
  assert_equal [1, 2], a.args

  assert_nothing_raised do
    begin
      doesNotExistAsAMethodNameForVerySure 3, 1, 4
    rescue NoMethodError => e
      assert_equal [3, 1, 4], e.args
    end
  end
end

assert('Can still raise when Kernel#method_missing is removed') do
  assert_raise(NoMethodError) do
    begin
      Kernel.alias_method(:old_method_missing, :method_missing)
      Kernel.remove_method(:method_missing)
      1.__send__(:foo)
    ensure
      Kernel.alias_method(:method_missing, :old_method_missing)
      Kernel.remove_method(:old_method_missing)
    end
  end
end

assert('Can still call super when Kernel#method_missing is removed') do
  assert_raise(NoMethodError) do
    class A
      def foo
        super
      end
    end
    begin
      Kernel.alias_method(:old_method_missing, :method_missing)
      Kernel.remove_method(:method_missing)
      A.new.foo
    ensure
      Kernel.alias_method(:method_missing, :old_method_missing)
      Kernel.remove_method(:old_method_missing)
    end
  end
end

assert("NoMethodError#new does not return an exception") do
  begin
    class << NoMethodError
      def new(*)
        nil
      end
    end

    assert_raise(TypeError) do
      Object.q
    end
  ensure
    class << NoMethodError
      remove_method :new
    end
  end
end