oktest 1.3.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +156 -18
- data/Rakefile.rb +1 -1
- data/benchmark/run_all.rb +1 -0
- data/bin/oktest +3 -0
- data/lib/oktest.rb +253 -143
- data/oktest.gemspec +4 -3
- data/test/{run_all.rb → all.rb} +1 -0
- data/test/assertion_test.rb +244 -229
- data/test/filter_test.rb +123 -120
- data/test/fixture_test.rb +34 -32
- data/test/generator_test.rb +26 -22
- data/test/helper_test.rb +382 -204
- data/test/init.rb +44 -0
- data/test/mainapp_test.rb +249 -199
- data/test/matcher_test.rb +157 -126
- data/test/misc_test.rb +32 -30
- data/test/nanot.rb +307 -0
- data/test/node_test.rb +321 -242
- data/test/reporter_test.rb +250 -208
- data/test/runner_test.rb +102 -100
- data/test/util_test.rb +197 -193
- data/test/utilhelper_test.rb +36 -38
- data/test/visitor_test.rb +55 -50
- metadata +21 -7
- data/test/initialize.rb +0 -21
- data/test/tc.rb +0 -127
data/test/reporter_test.rb
CHANGED
@@ -1,16 +1,91 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
###
|
4
|
-
### $Release: 1.
|
5
|
+
### $Release: 1.5.0 $
|
5
6
|
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
6
7
|
### $License: MIT License $
|
7
8
|
###
|
8
9
|
|
9
|
-
require_relative './
|
10
|
+
require_relative './init'
|
10
11
|
|
11
12
|
|
12
13
|
module ReporterTestHelper
|
13
14
|
|
15
|
+
INPUT_7 = <<'END'
|
16
|
+
require 'oktest'
|
17
|
+
|
18
|
+
Oktest.scope do
|
19
|
+
|
20
|
+
topic "Parent" do
|
21
|
+
|
22
|
+
topic "Child1" do
|
23
|
+
spec "1+1 should be 2" do
|
24
|
+
ok {1+1} == 2
|
25
|
+
end
|
26
|
+
spec "1-1 should be 0" do
|
27
|
+
ok {1-1} == 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
topic "Child2" do
|
32
|
+
spec "1*1 should be 1" do
|
33
|
+
ok {1*1} == 2
|
34
|
+
end
|
35
|
+
spec "1/1 should be 1" do
|
36
|
+
ok {1/0} == 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
topic "Child3" do
|
41
|
+
spec "skip example" do
|
42
|
+
skip_when true, "a certain condition"
|
43
|
+
end
|
44
|
+
spec "todo example"
|
45
|
+
end
|
46
|
+
|
47
|
+
case_when "x is negative" do
|
48
|
+
spec "x*x is positive." do
|
49
|
+
x = -2
|
50
|
+
ok {x*x} > 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
case_else do
|
55
|
+
spec "x*x is also positive." do
|
56
|
+
x = 2
|
57
|
+
ok {x*x} > 0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
spec "last spec" do
|
62
|
+
ok {1+1} == 2
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
END
|
70
|
+
|
71
|
+
def default_test
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_subject(desc, &b)
|
75
|
+
@filename = "_test.tmp"
|
76
|
+
File.write(@filename, INPUT_7)
|
77
|
+
color_enabled = Oktest::Config.color_enabled
|
78
|
+
Oktest::Config.color_enabled = true
|
79
|
+
super
|
80
|
+
ensure
|
81
|
+
Oktest::Config.color_enabled = color_enabled
|
82
|
+
File.unlink(@filename) if @filename && File.exist?(@filename)
|
83
|
+
end
|
84
|
+
|
85
|
+
def run(*opts)
|
86
|
+
return capture_output! { Oktest::MainApp.main(opts) }
|
87
|
+
end
|
88
|
+
|
14
89
|
def edit_actual(output)
|
15
90
|
bkup = output.dup
|
16
91
|
output = output.gsub(/^.*\r/, '')
|
@@ -29,10 +104,11 @@ module ReporterTestHelper
|
|
29
104
|
end
|
30
105
|
|
31
106
|
|
32
|
-
class
|
33
|
-
|
107
|
+
class BaseReporter__Test
|
108
|
+
extend NanoTest
|
109
|
+
extend ReporterTestHelper
|
34
110
|
|
35
|
-
def new_topic_and_spec()
|
111
|
+
def self.new_topic_and_spec()
|
36
112
|
sc = Oktest::ScopeNode.new(nil, "foo.rb")
|
37
113
|
t1 = Oktest::TopicNode.new(sc, 'Example')
|
38
114
|
t2 = Oktest::TopicNode.new(t1, Array)
|
@@ -41,33 +117,33 @@ class BaseReporter_TC < TC
|
|
41
117
|
return t3, spec
|
42
118
|
end
|
43
119
|
|
44
|
-
|
45
|
-
|
120
|
+
test_target 'Oktest::BaseReporter#enter_all()' do
|
121
|
+
test_subject "[!pq3ia] initalizes counter by zero." do
|
46
122
|
r = Oktest::BaseReporter.new
|
47
123
|
c = r.instance_eval { @counts }
|
48
|
-
|
124
|
+
test_eq? c, {}
|
49
125
|
#
|
50
126
|
r.enter_all(nil)
|
51
127
|
c = r.instance_eval { @counts }
|
52
|
-
|
128
|
+
test_eq? c, {:PASS=>0, :FAIL=>0, :ERROR=>0, :SKIP=>0, :TODO=>0}
|
53
129
|
end
|
54
130
|
end
|
55
131
|
|
56
|
-
|
57
|
-
|
132
|
+
test_target 'Oktest::BaseReporter#exit_all()' do
|
133
|
+
test_subject "[!wjp7u] prints footer with elapsed time." do
|
58
134
|
r = Oktest::BaseReporter.new
|
59
135
|
r.enter_all(nil)
|
60
136
|
r.instance_eval { @start_at = Time.now - 7.0 }
|
61
|
-
sout, serr =
|
137
|
+
sout, serr = capture_output! do
|
62
138
|
r.exit_all(nil)
|
63
139
|
end
|
64
|
-
|
65
|
-
|
140
|
+
test_eq? sout, "## total:0 (pass:0, fail:0, error:0, skip:0, todo:0) in 7.00s\n"
|
141
|
+
test_eq? serr, ""
|
66
142
|
end
|
67
143
|
end
|
68
144
|
|
69
|
-
|
70
|
-
|
145
|
+
test_target 'Oktest::BaseReporter#exit_spec()' do
|
146
|
+
test_subject "[!r6yge] increments counter according to status." do
|
71
147
|
begin; 1/0
|
72
148
|
rescue => exc
|
73
149
|
end
|
@@ -76,21 +152,21 @@ class BaseReporter_TC < TC
|
|
76
152
|
topic1, spec1 = new_topic_and_spec()
|
77
153
|
#
|
78
154
|
r.exit_spec(spec1, 1, :PASS, nil, topic1)
|
79
|
-
|
155
|
+
test_eq? r.counts, {:PASS=>1, :FAIL=>0, :ERROR=>0, :SKIP=>0, :TODO=>0}
|
80
156
|
#
|
81
157
|
r.exit_spec(spec1, 1, :FAIL, exc, topic1)
|
82
|
-
|
158
|
+
test_eq? r.counts, {:PASS=>1, :FAIL=>1, :ERROR=>0, :SKIP=>0, :TODO=>0}
|
83
159
|
#
|
84
160
|
r.exit_spec(spec1, 1, :ERROR, exc, topic1)
|
85
|
-
|
161
|
+
test_eq? r.counts, {:PASS=>1, :FAIL=>1, :ERROR=>1, :SKIP=>0, :TODO=>0}
|
86
162
|
#
|
87
163
|
r.exit_spec(spec1, 1, :SKIP, nil, topic1)
|
88
|
-
|
164
|
+
test_eq? r.counts, {:PASS=>1, :FAIL=>1, :ERROR=>1, :SKIP=>1, :TODO=>0}
|
89
165
|
#
|
90
166
|
r.exit_spec(spec1, 1, :TODO, nil, topic1)
|
91
|
-
|
167
|
+
test_eq? r.counts, {:PASS=>1, :FAIL=>1, :ERROR=>1, :SKIP=>1, :TODO=>1}
|
92
168
|
end
|
93
|
-
|
169
|
+
test_subject "[!nupb4] keeps exception info when status is FAIL or ERROR." do
|
94
170
|
begin; 1/0
|
95
171
|
rescue => exc
|
96
172
|
end
|
@@ -106,61 +182,61 @@ class BaseReporter_TC < TC
|
|
106
182
|
r.exit_spec(spec1, 1, :TODO, nil, topic1)
|
107
183
|
#
|
108
184
|
exceptions = r.instance_variable_get('@exceptions')
|
109
|
-
|
110
|
-
|
111
|
-
|
185
|
+
test_eq? exceptions.length, 2
|
186
|
+
test_eq? exceptions[0][1], :FAIL
|
187
|
+
test_eq? exceptions[1][1], :ERROR
|
112
188
|
end
|
113
189
|
end
|
114
190
|
|
115
|
-
|
116
|
-
|
191
|
+
test_target 'Oktest::BaseReporter#reset_counts()' do
|
192
|
+
test_subject "[!oc29s] clears counters to zero." do
|
117
193
|
r = Oktest::BaseReporter.new
|
118
194
|
r.instance_eval do
|
119
195
|
@counts = {:PASS=>5, :FAIL=>4, :ERROR=>3, :SKIP=>2, :TODO=>1}
|
120
196
|
end
|
121
197
|
r.__send__(:reset_counts)
|
122
|
-
|
198
|
+
test_eq? r.instance_variable_get('@counts'), {:PASS=>0, :FAIL=>0, :ERROR=>0, :SKIP=>0, :TODO=>0}
|
123
199
|
end
|
124
200
|
end
|
125
201
|
|
126
|
-
|
127
|
-
def error_msg()
|
202
|
+
test_target 'Oktest::BaseReporter#print_exc_message()' do
|
203
|
+
def self.error_msg()
|
128
204
|
return ("something failed\n"\
|
129
205
|
" expect: foo\n"\
|
130
206
|
" actual: bar\n")
|
131
207
|
end
|
132
|
-
|
208
|
+
test_subject "[!hr7jn] prints detail of assertion failed." do
|
133
209
|
errmsg = error_msg()
|
134
210
|
exc = Oktest::AssertionFailed.new(errmsg)
|
135
211
|
r = Oktest::BaseReporter.new
|
136
|
-
sout, serr =
|
212
|
+
sout, serr = capture_output! do
|
137
213
|
r.__send__(:print_exc_message, exc, :FAIL)
|
138
214
|
end
|
139
|
-
|
215
|
+
test_eq? sout, plain2colored(<<END)
|
140
216
|
<R>something failed</R>
|
141
217
|
expect: foo
|
142
218
|
actual: bar
|
143
219
|
END
|
144
|
-
|
220
|
+
test_eq? serr, ""
|
145
221
|
end
|
146
|
-
|
222
|
+
test_subject "[!pd41p] prints detail of exception." do
|
147
223
|
errmsg = error_msg()
|
148
224
|
exc = Oktest::AssertionFailed.new(errmsg)
|
149
225
|
r = Oktest::BaseReporter.new
|
150
|
-
sout, serr =
|
226
|
+
sout, serr = capture_output! do
|
151
227
|
r.__send__(:print_exc_message, exc, :ERROR)
|
152
228
|
end
|
153
|
-
|
229
|
+
test_eq? sout, plain2colored(<<END)
|
154
230
|
<R>Oktest::AssertionFailed: something failed</R>
|
155
231
|
expect: foo
|
156
232
|
actual: bar
|
157
233
|
END
|
158
|
-
|
234
|
+
test_eq? serr, ""
|
159
235
|
end
|
160
236
|
end
|
161
237
|
|
162
|
-
|
163
|
-
|
238
|
+
test_target 'Oktest::BaseReporter#print_exc_backtrace()' do
|
239
|
+
test_subject "[!ocxy6] prints backtrace info and lines in file." do
|
164
240
|
begin
|
165
241
|
if true
|
166
242
|
if true
|
@@ -172,47 +248,46 @@ END
|
|
172
248
|
end
|
173
249
|
#
|
174
250
|
expected = <<END
|
175
|
-
test/reporter_test.rb:#{lineno}:in `block (2 levels) in <
|
251
|
+
test/reporter_test.rb:#{lineno}:in `block (2 levels) in <main>'
|
176
252
|
raise Oktest::AssertionFailed, "something failed."
|
177
253
|
END
|
178
254
|
#
|
179
255
|
r = Oktest::BaseReporter.new
|
180
|
-
sout, serr =
|
256
|
+
sout, serr = capture_output! do
|
181
257
|
r.__send__(:print_exc_backtrace, exc, :FAIL)
|
182
258
|
end
|
183
|
-
|
184
|
-
|
259
|
+
sout = sout.sub(/ in <.*?>/, " in <main>")
|
260
|
+
test_ok? sout.start_with?(expected), msg: "traceback not matched"
|
261
|
+
test_eq? serr, ""
|
185
262
|
end
|
186
|
-
|
187
|
-
|
263
|
+
test_subject "[!jbped] skips backtrace of oktest.rb when assertion failure." do
|
264
|
+
exc = test_exception? Oktest::AssertionFailed do
|
188
265
|
eval "raise Oktest::AssertionFailed, 'dummie'", binding(), "lib/oktest.rb", 100
|
189
|
-
rescue Oktest::AssertionFailed => exc
|
190
266
|
end
|
191
267
|
#
|
192
268
|
status = :FAIL
|
193
|
-
sout, serr =
|
269
|
+
sout, serr = capture_output! do
|
194
270
|
Oktest::BaseReporter.new.__send__(:print_exc_backtrace, exc, status)
|
195
271
|
end
|
196
|
-
|
197
|
-
|
272
|
+
test_ok? sout !~ /lib\/oktest\.rb:/, msg: "should skip but not"
|
273
|
+
test_eq? serr, ""
|
198
274
|
end
|
199
|
-
|
200
|
-
|
275
|
+
test_subject "[!cfkzg] don't skip first backtrace entry when error." do
|
276
|
+
exc = test_exception? Oktest::AssertionFailed do
|
201
277
|
eval "raise Oktest::AssertionFailed, 'dummie'", binding(), "lib/oktest.rb", 100
|
202
|
-
rescue Oktest::AssertionFailed => exc
|
203
278
|
end
|
204
279
|
#
|
205
280
|
status = :ERROR
|
206
|
-
sout, serr =
|
281
|
+
sout, serr = capture_output! do
|
207
282
|
Oktest::BaseReporter.new.__send__(:print_exc_backtrace, exc, status)
|
208
283
|
end
|
209
|
-
|
210
|
-
|
284
|
+
test_match? sout, /lib\/oktest\.rb:100/, msg: "should not skip but does"
|
285
|
+
test_eq? serr, ""
|
211
286
|
end
|
212
287
|
end
|
213
288
|
|
214
|
-
|
215
|
-
|
289
|
+
test_target 'Oktest::BaseReporter#print_exc()' do
|
290
|
+
test_subject "[!5ara3] prints exception info of assertion failure." do
|
216
291
|
begin
|
217
292
|
if true
|
218
293
|
lineno = __LINE__ + 1
|
@@ -223,19 +298,20 @@ END
|
|
223
298
|
#
|
224
299
|
expected = <<END
|
225
300
|
[<R>Fail</R>] <b>Example > Array > When some condition > 1+1 shoould be 2.</b>
|
226
|
-
#{__FILE__}:#{lineno}:in `block (2 levels) in <
|
301
|
+
#{__FILE__}:#{lineno}:in `block (2 levels) in <main>'
|
227
302
|
raise Oktest::AssertionFailed, 'dummie:43201'
|
228
303
|
END
|
229
304
|
#
|
230
305
|
topic1, spec1 = new_topic_and_spec()
|
231
306
|
status = :FAIL
|
232
|
-
sout, serr =
|
307
|
+
sout, serr = capture_output! do
|
233
308
|
Oktest::BaseReporter.new.__send__(:print_exc, spec1, status, exc, topic1)
|
234
309
|
end
|
235
|
-
|
236
|
-
|
310
|
+
sout = sout.gsub(/ in <.*?>/, " in <main>")
|
311
|
+
test_ok? sout.start_with?(plain2colored(expected)), msg: "not matched"
|
312
|
+
test_eq? serr, ""
|
237
313
|
end
|
238
|
-
|
314
|
+
test_subject "[!pcpy4] prints exception info of error." do
|
239
315
|
begin
|
240
316
|
if true
|
241
317
|
lineno = __LINE__ + 1
|
@@ -252,16 +328,16 @@ END
|
|
252
328
|
#
|
253
329
|
topic1, spec1 = new_topic_and_spec()
|
254
330
|
status = :ERROR
|
255
|
-
sout, serr =
|
331
|
+
sout, serr = capture_output! do
|
256
332
|
Oktest::BaseReporter.new.__send__(:print_exc, spec1, status, exc, topic1)
|
257
333
|
end
|
258
|
-
|
259
|
-
|
334
|
+
test_ok? sout.start_with?(plain2colored(expected)), msg: "not matched"
|
335
|
+
test_eq? serr, ""
|
260
336
|
end
|
261
337
|
end
|
262
338
|
|
263
|
-
|
264
|
-
def new_reporter_with_exceptions(exc)
|
339
|
+
test_target 'Oktest::BaseReporter#print_exception()' do
|
340
|
+
def self.new_reporter_with_exceptions(exc)
|
265
341
|
topic1, spec1 = new_topic_and_spec()
|
266
342
|
r = Oktest::BaseReporter.new
|
267
343
|
r.instance_eval do
|
@@ -274,7 +350,7 @@ END
|
|
274
350
|
end
|
275
351
|
return r
|
276
352
|
end
|
277
|
-
|
353
|
+
test_subject "[!fbr16] prints assertion failures and excerptions with separator." do
|
278
354
|
begin
|
279
355
|
raise Oktest::AssertionFailed, 'dummie'
|
280
356
|
rescue Oktest::AssertionFailed => exc
|
@@ -284,31 +360,31 @@ END
|
|
284
360
|
expected1 = "[<R>Fail</R>] <b>Example > Array > When some condition > 1+1 shoould be 2.</b>\n"
|
285
361
|
expected2 = "[<E>ERROR</E>] <b>Example > Array > When some condition > 1+1 shoould be 2.</b>\n"
|
286
362
|
#
|
287
|
-
sout, serr =
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
363
|
+
sout, serr = capture_output! { r.__send__(:print_exceptions) }
|
364
|
+
test_ok? sout.start_with?(sep + plain2colored(expected1)), msg: "not matched"
|
365
|
+
test_ok? sout.include?(sep + plain2colored(expected2)), msg: "not matched"
|
366
|
+
test_ok? sout.end_with?(sep), msg: "not matched"
|
367
|
+
test_eq? serr, ""
|
292
368
|
end
|
293
|
-
|
369
|
+
test_subject "[!2s9r2] prints nothing when no fails nor errors." do
|
294
370
|
r = new_reporter_with_exceptions(nil)
|
295
|
-
sout, serr =
|
296
|
-
|
297
|
-
|
371
|
+
sout, serr = capture_output! { r.__send__(:print_exceptions) }
|
372
|
+
test_eq? sout, ""
|
373
|
+
test_eq? serr, ""
|
298
374
|
end
|
299
|
-
|
375
|
+
test_subject "[!ueeih] clears exceptions." do
|
300
376
|
begin 1/0
|
301
377
|
rescue => exc
|
302
378
|
end
|
303
379
|
r = new_reporter_with_exceptions(exc)
|
304
|
-
|
305
|
-
sout, serr =
|
306
|
-
|
380
|
+
test_ok? ! r.instance_variable_get('@exceptions').empty?
|
381
|
+
sout, serr = capture_output! { r.__send__(:print_exceptions) }
|
382
|
+
test_ok? r.instance_variable_get('@exceptions').empty?
|
307
383
|
end
|
308
384
|
end
|
309
385
|
|
310
|
-
|
311
|
-
def new_footer(elapsed=0.5)
|
386
|
+
test_target 'Oktest::BaseReporter#footer()' do
|
387
|
+
def self.new_footer(elapsed=0.5)
|
312
388
|
r = Oktest::BaseReporter.new
|
313
389
|
r.enter_all(nil)
|
314
390
|
r.instance_eval do
|
@@ -317,115 +393,58 @@ END
|
|
317
393
|
return r.__send__(:footer, elapsed)
|
318
394
|
end
|
319
395
|
|
320
|
-
|
396
|
+
test_subject "[!iy4uo] calculates total count of specs." do
|
321
397
|
ft = new_footer()
|
322
|
-
|
398
|
+
test_match? ft, /total:15 /, msg: "failed to calculate total counts."
|
323
399
|
end
|
324
400
|
|
325
|
-
|
401
|
+
test_subject "[!2nnma] includes count of each status." do
|
326
402
|
ft = new_footer()
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
403
|
+
test_match? ft, /pass:5\b/ , msg: "failed to count passed status."
|
404
|
+
test_match? ft, /fail:4\b/ , msg: "failed to count failed status."
|
405
|
+
test_match? ft, /error:3\b/ , msg: "failed to count error status."
|
406
|
+
test_match? ft, /skip:2\b/ , msg: "failed to count skipped status."
|
407
|
+
test_match? ft, /todo:1\b/ , msg: "failed to count todo status."
|
332
408
|
end
|
333
409
|
|
334
|
-
|
410
|
+
test_subject "[!fp57l] includes elapsed time." do
|
335
411
|
ft = new_footer()
|
336
|
-
|
412
|
+
test_match? ft, / in 0.500s$/, msg: "failed to embed elapsed time."
|
337
413
|
end
|
338
414
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
415
|
+
test_subject "[!r5y02] elapsed time format is adjusted along to time length." do
|
416
|
+
test_match? new_footer( 0.5), / in 0.500s$/ , msg: "failed to embed elapsed time."
|
417
|
+
test_match? new_footer( 6.5), / in 6.50s$/ , msg: "failed to embed elapsed time."
|
418
|
+
test_match? new_footer( 17.5), / in 17.5s$/ , msg: "failed to embed elapsed time."
|
419
|
+
test_match? new_footer( 61.5), / in 1:01.5s$/ , msg: "failed to embed elapsed time."
|
420
|
+
test_match? new_footer( 610.5), / in 10:10.5s$/ , msg: "failed to embed elapsed time."
|
421
|
+
test_match? new_footer( 3600.5), / in 1:00:00.5s$/ , msg: "failed to embed elapsed time."
|
422
|
+
test_match? new_footer( 36000.5), / in 10:00:00.5s$/ , msg: "failed to embed elapsed time."
|
423
|
+
test_match? new_footer(360000.5), / in 100:00:00.5s$/ , msg: "failed to embed elapsed time."
|
348
424
|
end
|
349
425
|
|
350
|
-
|
426
|
+
test_subject "[!gx0n2] builds footer line." do
|
351
427
|
expected = "## total:15 (<C>pass:5</C>, <R>fail:4</R>, <E>error:3</E>, <Y>skip:2</Y>, <Y>todo:1</Y>) in 0.500s"
|
352
|
-
|
428
|
+
test_eq? new_footer(), plain2colored(expected)
|
353
429
|
end
|
354
430
|
end
|
355
431
|
|
356
|
-
|
357
|
-
|
432
|
+
test_target 'Oktest::BaseReporter#spec_path()' do
|
433
|
+
test_subject "[!dv6fu] returns path string from top topic to current spec." do
|
358
434
|
sc = Oktest::ScopeNode.new(nil, "foo.rb")
|
359
435
|
t1 = Oktest::TopicNode.new(sc, 'Example')
|
360
436
|
t2 = Oktest::TopicNode.new(t1, Array)
|
361
437
|
t3 = Oktest::TopicNode.new(t2, 'When some condition')
|
362
438
|
s1 = Oktest::SpecLeaf.new(t3, "1+1 shoould be 2.") { nil }
|
363
439
|
path = Oktest::BaseReporter.new.__send__(:spec_path, s1, t3)
|
364
|
-
|
440
|
+
test_eq? path, "Example > Array > When some condition > 1+1 shoould be 2."
|
365
441
|
end
|
366
442
|
end
|
367
443
|
|
368
444
|
end
|
369
445
|
|
370
446
|
|
371
|
-
|
372
|
-
include ReporterTestHelper
|
373
|
-
|
374
|
-
INPUT = <<'END'
|
375
|
-
require 'oktest'
|
376
|
-
|
377
|
-
Oktest.scope do
|
378
|
-
|
379
|
-
topic "Parent" do
|
380
|
-
|
381
|
-
topic "Child1" do
|
382
|
-
spec "1+1 should be 2" do
|
383
|
-
ok {1+1} == 2
|
384
|
-
end
|
385
|
-
spec "1-1 should be 0" do
|
386
|
-
ok {1-1} == 0
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
topic "Child2" do
|
391
|
-
spec "1*1 should be 1" do
|
392
|
-
ok {1*1} == 2
|
393
|
-
end
|
394
|
-
spec "1/1 should be 1" do
|
395
|
-
ok {1/0} == 1
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
topic "Child3" do
|
400
|
-
spec "skip example" do
|
401
|
-
skip_when true, "a certain condition"
|
402
|
-
end
|
403
|
-
spec "todo example"
|
404
|
-
end
|
405
|
-
|
406
|
-
case_when "x is negative" do
|
407
|
-
spec "x*x is positive." do
|
408
|
-
x = -2
|
409
|
-
ok {x*x} > 0
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
case_else do
|
414
|
-
spec "x*x is also positive." do
|
415
|
-
x = 2
|
416
|
-
ok {x*x} > 0
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
spec "last spec" do
|
421
|
-
ok {1+1} == 2
|
422
|
-
end
|
423
|
-
|
424
|
-
end
|
425
|
-
|
426
|
-
end
|
427
|
-
|
428
|
-
END
|
447
|
+
module ReporterOutput
|
429
448
|
|
430
449
|
ERROR_PART = <<'END'
|
431
450
|
----------------------------------------------------------------------
|
@@ -497,37 +516,22 @@ END
|
|
497
516
|
END
|
498
517
|
QUIET_OUTPUT = QUIET_PART + ERROR_PART + FOOTER
|
499
518
|
|
500
|
-
def default_test
|
501
|
-
end
|
502
|
-
|
503
|
-
def setup
|
504
|
-
@filename = "_test.tmp"
|
505
|
-
File.write(@filename, INPUT)
|
506
|
-
@_color_enabled = Oktest::Config.color_enabled
|
507
|
-
Oktest::Config.color_enabled = true
|
508
|
-
end
|
509
|
-
|
510
|
-
def teardown
|
511
|
-
Oktest::Config.color_enabled = @_color_enabled
|
512
|
-
File.unlink(@filename) if @filename && File.exist?(@filename)
|
513
|
-
end
|
514
|
-
|
515
|
-
def run(*opts)
|
516
|
-
return capture { Oktest::MainApp.main(opts) }
|
517
|
-
end
|
518
|
-
|
519
519
|
end
|
520
520
|
|
521
|
+
include ReporterOutput
|
522
|
+
|
521
523
|
|
522
|
-
class
|
524
|
+
class VerboseReporter__Test
|
525
|
+
extend NanoTest
|
526
|
+
extend ReporterTestHelper
|
523
527
|
|
524
|
-
|
528
|
+
test_subject "[!6o9nw] reports topic name and spec desc." do
|
525
529
|
sout, serr = run("-sv", @filename)
|
526
|
-
|
527
|
-
|
530
|
+
test_eq? edit_actual(sout), edit_expected(VERBOSE_OUTPUT)
|
531
|
+
test_eq? serr, ""
|
528
532
|
end
|
529
533
|
|
530
|
-
|
534
|
+
test_subject "[!ibdu7] reports errors even when no topics." do
|
531
535
|
input = <<'END'
|
532
536
|
require 'oktest'
|
533
537
|
Oktest.scope do
|
@@ -554,52 +558,90 @@ END
|
|
554
558
|
END
|
555
559
|
#
|
556
560
|
sout, serr = run("-sv", @filename)
|
557
|
-
|
558
|
-
|
561
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
562
|
+
test_eq? serr, ""
|
559
563
|
end
|
560
564
|
|
561
565
|
end
|
562
566
|
|
563
567
|
|
564
|
-
class
|
568
|
+
class SimpleReporter__Test
|
569
|
+
extend NanoTest
|
570
|
+
extend ReporterTestHelper
|
571
|
+
extend ReporterOutput
|
565
572
|
|
566
|
-
|
573
|
+
test_subject "[!jxa1b] reports topics and progress." do
|
567
574
|
sout, serr = run("-ss", @filename)
|
568
|
-
|
569
|
-
|
575
|
+
test_eq? edit_actual(sout), edit_expected(SIMPLE_OUTPUT)
|
576
|
+
test_eq? serr, ""
|
570
577
|
end
|
571
578
|
|
572
579
|
end
|
573
580
|
|
574
581
|
|
575
|
-
class
|
582
|
+
class CompactReporter__Test
|
583
|
+
extend NanoTest
|
584
|
+
extend ReporterTestHelper
|
585
|
+
extend ReporterOutput
|
576
586
|
|
577
|
-
|
587
|
+
test_subject "[!xfd5o] reports filename." do
|
578
588
|
sout, serr = run("-sc", @filename)
|
579
|
-
|
580
|
-
|
589
|
+
test_eq? edit_actual(sout), edit_expected(COMPACT_OUTPUT)
|
590
|
+
test_eq? serr, ""
|
581
591
|
end
|
582
592
|
|
583
593
|
end
|
584
594
|
|
585
595
|
|
586
|
-
class
|
596
|
+
class PlainReporter__Test
|
597
|
+
extend NanoTest
|
598
|
+
extend ReporterTestHelper
|
599
|
+
extend ReporterOutput
|
587
600
|
|
588
|
-
|
601
|
+
test_subject "[!w842j] reports progress." do
|
589
602
|
sout, serr = run("-sp", @filename)
|
590
|
-
|
591
|
-
|
603
|
+
test_eq? edit_actual(sout), edit_expected(PLAIN_OUTPUT)
|
604
|
+
test_eq? serr, ""
|
592
605
|
end
|
593
606
|
|
594
607
|
end
|
595
608
|
|
596
609
|
|
597
|
-
class
|
610
|
+
class QuietReporter__Test
|
611
|
+
extend NanoTest
|
612
|
+
extend ReporterTestHelper
|
613
|
+
extend ReporterOutput
|
598
614
|
|
599
|
-
|
615
|
+
test_subject "[!0z4im] reports all statuses except PASS status." do
|
600
616
|
sout, serr = run("-sq", @filename)
|
601
|
-
|
602
|
-
|
617
|
+
test_eq? edit_actual(sout), edit_expected(QUIET_OUTPUT)
|
618
|
+
test_eq? serr, ""
|
619
|
+
end
|
620
|
+
|
621
|
+
end
|
622
|
+
|
623
|
+
|
624
|
+
class DefaultReprotingStyle__Test
|
625
|
+
extend NanoTest
|
626
|
+
extend ReporterTestHelper
|
627
|
+
extend ReporterOutput
|
628
|
+
|
629
|
+
test_target 'Oktest.DEFAULT_REPORTING_STYLE=()' do
|
630
|
+
test_subject "[!lbufd] raises error if unknown style specified." do
|
631
|
+
exc = test_exception? ArgumentError do
|
632
|
+
Oktest.DEFAULT_REPORTING_STYLE = "foo"
|
633
|
+
end
|
634
|
+
test_eq? exc.message, "foo: Unknown reporting style."
|
635
|
+
end
|
636
|
+
test_subject "[!dsbmo] changes value of default reporting style." do
|
637
|
+
test_eq? Oktest::DEFAULT_REPORTING_STYLE, "verbose"
|
638
|
+
begin
|
639
|
+
Oktest.DEFAULT_REPORTING_STYLE = "plain"
|
640
|
+
test_eq? Oktest::DEFAULT_REPORTING_STYLE, "plain"
|
641
|
+
ensure
|
642
|
+
Oktest.DEFAULT_REPORTING_STYLE = "verbose"
|
643
|
+
end
|
644
|
+
end
|
603
645
|
end
|
604
646
|
|
605
647
|
end
|