-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_phocus.rb
124 lines (99 loc) · 2.29 KB
/
test_phocus.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require 'test/test_helper'
require 'nanotest'
require 'lib/phocus'
class TestCase
include Phocus
end
class TestA < TestCase; end
class TestB < TestCase; end
def reset
reset_phocused_classes(TestA, TestB)
reset_phocus
end
include NanoTest
# api
reset
assert { TestA.respond_to?(:focus ) }
assert { TestA.respond_to?(:focused) }
assert { TestA.respond_to?(:phocus ) }
# method pattern
reset
Phocus.method_pattern = /^test:/
class TestA
define_method(:'test:foo') {}
focus
define_method(:'test:bar') {}
define_method(:'test_baz') {}
end
assert { TestA.method_defined?(:'test_baz') }
assert { TestA.method_defined?(:'test:bar') }
assert { not TestA.method_defined?(:'test:foo') }
# only keeps focused method
reset
class TestA
focus
def test_foo() end
def test_bar() end
end
assert { TestA.method_defined?(:test_foo) }
assert { not TestA.method_defined?(:test_bar) }
# keeps more than one focused methods
reset
class TestA
focus
def test_foo() end
focus
def test_bar() end
def test_baz() end
end
assert { TestA.method_defined?(:test_foo) }
assert { TestA.method_defined?(:test_bar) }
assert { not TestA.method_defined?(:test_baz) }
# focuses across subclasses
reset
class TestA
focus
def test_foo() end
def test_bar() end
end
class TestB
def test_abc() end
end
assert { TestA.method_defined?(:test_foo) }
assert { not TestA.method_defined?(:test_bar) }
assert { not TestB.method_defined?(:test_abc) }
# focuses more than one methods across subclasses
reset
class TestA
focus
def test_foo() end
def test_bar() end
end
class TestB
def test_abc() end
focus
def test_def() end
end
assert { TestA.method_defined?(:test_foo) }
assert { TestB.method_defined?(:test_def) }
assert { not TestA.method_defined?(:test_bar) }
assert { not TestB.method_defined?(:test_abc) }
# non-test methods aren't touched
reset
class TestA
focus
def test_foo() end
def test_bar() end
def helper() end
end
assert { TestA.method_defined?(:helper) }
assert { TestA.method_defined?(:test_foo) }
assert { not TestA.method_defined?(:test_bar) }
# methods don't get removed if nothing is focused (control test)
reset
class TestA
def test_foo() end
def test_bar() end
end
assert { TestA.method_defined?(:test_foo) }
assert { TestA.method_defined?(:test_bar) }