-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathtest_class_definition_first_step.rb
More file actions
81 lines (66 loc) · 1.43 KB
/
test_class_definition_first_step.rb
File metadata and controls
81 lines (66 loc) · 1.43 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
require 'test_helper'
class Judgement
def self.call(e1, e2)
@e1 = e1
@e2 = e2
end
end
class Judgement2
def self.call(klass)
@klass = klass
end
end
class ExOver
attr_accessor :result
def initialize
self.result = ''
end
def before
result << 'before'
end
def hello
result << 'hello'
end
def after
result << 'after'
end
end
require '01_class_definition_first_step'
class TestClassDefinitionFirstStep < Minitest::Test
def test_judgement
e1 = Judgement.instance_variable_get(:@e1)
e2 = Judgement.instance_variable_get(:@e2)
assert e1.is_a?(ExClass)
assert e2.is_a?(ExClass)
refute e1.respond_to?(:hello)
assert e2.respond_to?(:hello)
end
def test_judgement2
klass = Judgement2.instance_variable_get(:@klass)
assert klass.name.nil?
assert klass.superclass == ExClass
end
def test_metaclass
MetaClass.class_eval do
meta_attr_accessor :hello
end
meta = MetaClass.new
meta.meta_hello = 'hello'
assert_equal 'meta hello', meta.meta_hello
end
def test_exconfig
ExConfig.config = 'hello'
assert_equal 'hello', ExConfig.config
ex = ExConfig.new
assert_equal 'hello', ex.config
ex.config = 'world'
assert_equal 'world', ExConfig.config
end
def test_exover
exover = ExOver.new
assert_equal 'beforehelloafter', exover.hello
end
def test_mygreeting
assert_equal 'hi', MyGreeting.new.say
end
end