-
Notifications
You must be signed in to change notification settings - Fork 111
/
test_hierarchy.rb
83 lines (67 loc) · 1.67 KB
/
test_hierarchy.rb
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
require 'test_helper'
require 'hierarchy'
class TestHierarchy < MiniTest::Test
def test_c1_ancestors
assert_equal [C1, M1], C1.ancestors.first(2)
end
def test_c1_name
assert_equal 'C1', C1.new.name
end
def test_c2_ancestors
assert_equal [M1, C2], C2.ancestors.first(2)
end
def test_c2_name
assert_equal 'M1', C2.new.name
end
def test_c3_ancestors
assert_equal [M1, C3, M2, M3, MySuperClass, M4], C3.ancestors.first(6)
end
def test_c3_name
assert_equal 'M1', C3.new.name
end
def test_c3_super_class
assert MySuperClass.kind_of?(Class)
end
def test_c4_increment
c4 = C4.new
assert_equal "1", c4.increment
assert_equal "2", c4.increment
assert_equal "3", c4.increment
end
def test_c4_value_called
c4 = C4.new
c4.singleton_class.class_eval do
private
def value=(x)
@called_setter = true
@value = x
end
def value
@called_getter = true
if defined?(@value)
@value
else
nil
end
end
end
c4.instance_variable_set(:"@called_setter", nil)
c4.instance_variable_set(:"@called_getter", nil)
assert_equal "1", c4.increment
assert c4.instance_variable_get(:"@called_setter")
assert c4.instance_variable_get(:"@called_getter")
end
def test_c4_value_methods
assert C4.private_instance_methods.include?(:value)
assert C4.private_instance_methods.include?(:value=)
end
def test_c5_another_name
assert_equal "M1", C5.new.another_name
end
def test_c5_other_name
assert_equal "Refined M1", C5.new.other_name
end
def test_c6_name
assert_equal "Refined M1", C6.new.name
end
end