Repository navigation
Expand file tree
/
Copy pathtest_include.rb
More file actions
84 lines (63 loc) · 1.37 KB
/
Copy pathtest_include.rb
File metadata and controls
84 lines (63 loc) · 1.37 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'test/unit'
class TestInclude < Test::Unit::TestCase
module X ; end
class Q
def foo arg = []
arg << :Q
end
end
class Y < Q ; include X end
module A
def foo arg = []
arg << :A ; super
end
end
module X ; include A end
module Z
def foo arg = []
arg << :Z ; super
end
end
class Y ; include Z end
class Y ; include X end
def test_include_order
pend '[:A, :Z, :Q] on JRuby GH-1938' if defined? JRUBY_VERSION
assert_equal [:Z, :A, :Q], Y.new.foo
end
module M1 ; V = 123 end
module M2 ; V = 456 end
class Foo
include M1
def self.get; return V end
end
def test_including_module_busts_constant_caches
assert_equal 123, Foo.get
Foo.send(:include, M2)
assert_equal 456, Foo.get
end
class Bar
include M1, M2
end
def test_multi_include
assert_equal 123, Bar::V
assert_equal Bar, Bar.send(:include)
assert_equal Bar, Bar.send(:include, Comparable, Enumerable)
assert_equal Object, Object.include
assert_equal Object, Object.include(*[])
end
# JRUBY-3036
def test_included_does_not_hit_each_class
ObjectSpace.each_object(Class) do |cls|
if cls < Top
assert cls.top
end
end
end
end
module IncludedTestCaseModule; end
class Top
def self.top; true; end
end
class Next < Top
include IncludedTestCaseModule
end