spec-unit 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,283 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/spec-unit'
3
-
4
- class TestSpecUnit < Test::Unit::TestCase
5
- def setup
6
- @test_class = Class.new do
7
- include SpecUnit
8
- attr_reader :test_val
9
- end
10
- end
11
-
12
- def test_should_accept_tests
13
- @test_object = build_test_object(@test_class) do
14
- def test_there_is_a_test
15
- @test_val = 1
16
- end
17
- end
18
-
19
- assert_method_sets_test_val(@test_object, :test_there_is_a_test, 1)
20
- end
21
-
22
- def test_should_have_contexts
23
- @test_object = build_test_object(@test_class) do
24
- context 'a new context' do
25
- def specify_has_tests
26
- @test_val = 1
27
- end
28
- end
29
- end
30
-
31
- assert_method_sets_test_val(@test_object, :test_a_new_context_has_tests, 1)
32
- end
33
-
34
- def test_context_specification_should_be_removed
35
- @test_object = build_test_object(@test_class) do
36
- context 'a new context' do
37
- def specify_has_tests
38
- @test_val = 1
39
- end
40
- end
41
- end
42
-
43
- assert !@test_object.respond_to?(:specify_has_tests)
44
- end
45
-
46
- def test_should_have_nested_contexts
47
- @test_object = build_test_object(@test_class) do
48
- context 'a new context' do
49
- context 'with a subcontext' do
50
- def specify_has_tests
51
- @test_val = 1
52
- end
53
- end
54
- end
55
- end
56
-
57
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_subcontext_has_tests, 1)
58
- end
59
-
60
- def test_two_specifications_should_exist_in_peace
61
- @test_object = build_test_object(@test_class) do
62
- context 'a new context' do
63
- def specify_has_tests
64
- @test_val = 1
65
- end
66
- end
67
-
68
- context 'another context' do
69
- def specify_has_tests
70
- @test_val = 2
71
- end
72
- end
73
- end
74
-
75
- assert_method_sets_test_val(@test_object, :test_a_new_context_has_tests, 1)
76
- assert_method_sets_test_val(@test_object, :test_another_context_has_tests, 2)
77
- end
78
-
79
- def test_two_nested_contexts_should_exist_in_peace
80
- @test_object = build_test_object(@test_class) do
81
- context 'a new context' do
82
- context 'with a sub context' do
83
- def specify_has_tests
84
- @test_val = 1
85
- end
86
- end
87
- end
88
-
89
- context 'another context' do
90
- context 'with a sub context' do
91
- def specify_has_tests
92
- @test_val = 2
93
- end
94
- end
95
- end
96
- end
97
-
98
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 1)
99
- assert_method_sets_test_val(@test_object, :test_another_context_with_a_sub_context_has_tests, 2)
100
- end
101
-
102
- def test_context_has_setup
103
- @test_object = build_test_object(@test_class) do
104
- context 'a new context' do
105
- def setup
106
- @test_val = 1
107
- end
108
-
109
- def specify_has_tests
110
- end
111
- end
112
- end
113
-
114
- assert_method_sets_test_val(@test_object, :test_a_new_context_has_tests, 1)
115
- end
116
-
117
- def test_nested_setups_work
118
- @test_object = build_test_object(@test_class) do
119
- context 'a new context' do
120
- def setup
121
- @test_val = 1
122
- end
123
-
124
- context 'with a sub context' do
125
- def setup
126
- @test_val += 1
127
- end
128
-
129
- def specify_has_tests
130
- end
131
- end
132
- end
133
- end
134
-
135
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 2)
136
- end
137
-
138
- def test_nested_setup_is_only_called_once
139
- @test_object = build_test_object(@test_class) do
140
- context 'a new context' do
141
- context 'with a sub context' do
142
- def setup
143
- @test_val ||= 0
144
- @test_val += 1
145
- end
146
-
147
- def specify_has_tests
148
- end
149
- end
150
- end
151
- end
152
-
153
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 1)
154
- end
155
-
156
- def test_two_nested_setups_do_not_conflict
157
- @test_object = build_test_object(@test_class) do
158
- context 'a new context' do
159
- context 'with a sub context' do
160
- def setup
161
- @test_val = 1
162
- end
163
-
164
- def specify_has_tests
165
- end
166
- end
167
- end
168
-
169
- context 'another context' do
170
- context 'with a sub context' do
171
- def setup
172
- @test_val = 2
173
- end
174
-
175
- def specify_has_tests
176
- end
177
- end
178
- end
179
- end
180
-
181
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 1)
182
- assert_method_sets_test_val(@test_object, :test_another_context_with_a_sub_context_has_tests, 2)
183
- end
184
-
185
-
186
- def test_context_has_teardown
187
- @test_object = build_test_object(@test_class) do
188
- context 'a new context' do
189
- def teardown
190
- @test_val -= 1
191
- end
192
-
193
- def specify_has_tests
194
- @test_val = 2
195
- end
196
- end
197
- end
198
-
199
- assert_method_sets_test_val(@test_object, :test_a_new_context_has_tests, 1)
200
- end
201
-
202
- def test_nested_teardowns_work
203
- @test_object = build_test_object(@test_class) do
204
- context 'a new context' do
205
- def teardown
206
- @test_val -= 1
207
- end
208
-
209
- context 'with a sub context' do
210
- def teardown
211
- @test_val -= 1
212
- end
213
-
214
- def specify_has_tests
215
- @test_val = 5
216
- end
217
- end
218
- end
219
- end
220
-
221
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 3)
222
- end
223
-
224
- def test_nested_teardown_is_only_called_once
225
- @test_object = build_test_object(@test_class) do
226
- context 'a new context' do
227
- context 'with a sub context' do
228
- def teardown
229
- @test_val -= 1
230
- end
231
-
232
- def specify_has_tests
233
- @test_val = 1
234
- end
235
- end
236
- end
237
- end
238
-
239
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 0)
240
- end
241
-
242
- def test_nested_teardowns_dont_clash_namespaces
243
- @test_object = build_test_object(@test_class) do
244
- context 'a new context' do
245
- context 'with a sub context' do
246
- def teardown
247
- @test_val -= 1
248
- end
249
-
250
- def specify_has_tests
251
- @test_val = 1
252
- end
253
- end
254
- end
255
-
256
- context 'another context' do
257
- context 'with a sub context' do
258
- def teardown
259
- @test_val -= 2
260
- end
261
-
262
- def specify_has_tests
263
- @test_val = 1
264
- end
265
- end
266
- end
267
- end
268
-
269
- assert_method_sets_test_val(@test_object, :test_a_new_context_with_a_sub_context_has_tests, 0)
270
- assert_method_sets_test_val(@test_object, :test_another_context_with_a_sub_context_has_tests, -1)
271
- end
272
-
273
-
274
- def build_test_object(klass, &block)
275
- klass.module_eval(&block)
276
- klass.new
277
- end
278
-
279
- def assert_method_sets_test_val(object, method, return_value)
280
- object.send(method)
281
- assert_equal return_value, object.test_val
282
- end
283
- end