oktest 1.4.0 → 1.5.0

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