File: test-method-owner-finder.rb

package info (click to toggle)
ruby-test-unit 3.7.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,348 kB
  • sloc: ruby: 16,403; makefile: 9
file content (38 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (11)
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
require 'test/unit'

require 'test/unit/util/method-owner-finder'

class TestUnitMethodOwnerFinder < Test::Unit::TestCase
  def test_find
    assert_equal(Exception, find(RuntimeError.new, :inspect))
    assert_equal(Exception, find(Exception.new, :inspect))

    anonymous_class = Class.new do
    end
    assert_equal(Kernel, find(anonymous_class.new, :inspect))

    anonymous_parent_class = Class.new do
      def inspect
        super + " by anonymous parent class"
      end
    end
    anonymous_sub_class = Class.new(anonymous_parent_class) do
    end
    assert_equal(anonymous_parent_class, find(anonymous_sub_class.new, :inspect))

    anonymous_module = Module.new do
      def inspect
        super + " by anonymous module"
      end
    end
    anonymous_include_class = Class.new do
      include anonymous_module
    end
    assert_equal(anonymous_module, find(anonymous_include_class.new, :inspect))
  end

  private
  def find(object, method_name)
    Test::Unit::Util::MethodOwnerFinder.find(object, method_name)
  end
end