oktest 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/README.md +114 -13
- data/Rakefile.rb +1 -1
- data/benchmark/run_all.rb +1 -0
- data/bin/oktest +3 -0
- data/lib/oktest.rb +223 -136
- data/oktest.gemspec +3 -2
- data/test/assertion_test.rb +19 -6
- data/test/filter_test.rb +2 -1
- data/test/fixture_test.rb +2 -1
- data/test/generator_test.rb +7 -4
- data/test/helper_test.rb +180 -8
- data/test/initialize.rb +2 -1
- data/test/mainapp_test.rb +85 -39
- data/test/matcher_test.rb +2 -1
- data/test/misc_test.rb +2 -1
- data/test/node_test.rb +36 -1
- data/test/reporter_test.rb +2 -1
- data/test/run_all.rb +1 -0
- data/test/runner_test.rb +2 -1
- data/test/tc.rb +1 -0
- data/test/util_test.rb +3 -2
- data/test/utilhelper_test.rb +2 -1
- data/test/visitor_test.rb +2 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c4df474c029dfbb1e598274d8959e742fab20f1e158d53ac8c4d6a1bb815ce
|
4
|
+
data.tar.gz: 4e9b1c680b335a2ae4fcc8b4e698ace15ab5df9f42a143e998c7b2556b5f8f15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c35a5ede9c4b9ce53c458bb18f4871782078ff933f6133b369b1058bd122a2f4d0e0f823b0e2f8e6a81fb42560d3c4a6710cead958db4ae1d9c0a53c97131255
|
7
|
+
data.tar.gz: b739cc6de446f83a92e87119c29c53022376b18495e211c555c03d2f16e82d03f465b343709b93c320f0718c3df585cca5f33d189770d37f84ad77840d5aeca3
|
data/README.md
CHANGED
@@ -77,7 +77,12 @@ Oktest.rb requires Ruby 2.4 or later.
|
|
77
77
|
* <a href="#fixture-keyword-argument"><code>fixture:</code> keyword argument</a>
|
78
78
|
* <a href="#global-scope">Global Scope</a>
|
79
79
|
* <a href="#helpers">Helpers</a>
|
80
|
+
* <a href="#capture_stdio"><code>capture_stdio()</code></a>
|
80
81
|
* <a href="#capture_sio"><code>capture_sio()</code></a>
|
82
|
+
* <a href="#capture_stdout"><code>capture_stdout()</code></a>
|
83
|
+
* <a href="#capture_stderr"><code>capture_stderr()</code></a>
|
84
|
+
* <a href="#capture_command"><code>capture_command()</code></a>
|
85
|
+
* <a href="#capture_command-1"><code>capture_command!()</code></a>
|
81
86
|
* <a href="#dummy_file"><code>dummy_file()</code></a>
|
82
87
|
* <a href="#dummy_dir"><code>dummy_dir()</code></a>
|
83
88
|
* <a href="#dummy_values"><code>dummy_values()</code></a>
|
@@ -823,7 +828,7 @@ ok {exc.class} == NoMethodError
|
|
823
828
|
ok {exc.message} == "undefined method `len' for \"abc\":String"
|
824
829
|
|
825
830
|
## assert that procedure does NOT raise any exception
|
826
|
-
ok {pr}.raise_nothing? # (>=
|
831
|
+
ok {pr}.raise_nothing? # (Oktest >= 1.4)
|
827
832
|
ok {pr}.NOT.raise? # no exception class nor error message
|
828
833
|
not_ok {pr}.raise? # same as above
|
829
834
|
|
@@ -1303,9 +1308,9 @@ end
|
|
1303
1308
|
## Helpers
|
1304
1309
|
|
1305
1310
|
|
1306
|
-
### `
|
1311
|
+
### `capture_stdio()`
|
1307
1312
|
|
1308
|
-
`
|
1313
|
+
`capture_stdio()` captures standard I/O.
|
1309
1314
|
|
1310
1315
|
test/example31_test.rb:
|
1311
1316
|
|
@@ -1318,7 +1323,7 @@ Oktest.scope do
|
|
1318
1323
|
|
1319
1324
|
spec "example spec" do
|
1320
1325
|
data = nil
|
1321
|
-
sout, serr =
|
1326
|
+
sout, serr = capture_stdio("blabla") do # !!!!!
|
1322
1327
|
data = $stdin.read() # read from stdin
|
1323
1328
|
puts "fooo" # write into stdout
|
1324
1329
|
$stderr.puts "baaa" # write into stderr
|
@@ -1333,17 +1338,113 @@ Oktest.scope do
|
|
1333
1338
|
end
|
1334
1339
|
```
|
1335
1340
|
|
1336
|
-
* The first argument of `
|
1337
|
-
If it is not necessary, you can omit it like `
|
1341
|
+
* The first argument of `capture_stdio()` represents data from `$stdin`.
|
1342
|
+
If it is not necessary, you can omit it like `caputre_stdio() do ... end`.
|
1338
1343
|
* If you need `$stdin.tty? == true` and `$stdout.tty? == true`,
|
1339
|
-
call `
|
1344
|
+
call `capture_stdio(tty: true) do ... end`.
|
1345
|
+
* Available on Oktest >= 1.4.
|
1346
|
+
|
1347
|
+
|
1348
|
+
### `capture_sio()`
|
1349
|
+
|
1350
|
+
`capture_sio()` is an alias of `capture_stdio()`.
|
1351
|
+
This is provided for backward compatibility.
|
1352
|
+
|
1353
|
+
(`capture_stdio()` is provided as `capture_sio()` on Oktest < 1.4,
|
1354
|
+
and `capture_sio()` is renamed to `capture_stdio()` since Oktest 1.4.)
|
1355
|
+
|
1356
|
+
|
1357
|
+
### `capture_stdout()`
|
1358
|
+
|
1359
|
+
`capture_stdout()` captures output of $stdout.
|
1360
|
+
If output of $stderr is not empty, assertion error will be raised.
|
1361
|
+
|
1362
|
+
`capture_stdout()` is almost same as the following.
|
1363
|
+
|
1364
|
+
```ruby
|
1365
|
+
def capture_stdout(*args, **kwargs, &b)
|
1366
|
+
sout, serr = capture_stdio(*args, **kwargs, &b)
|
1367
|
+
ok {serr} == ""
|
1368
|
+
return sout
|
1369
|
+
end
|
1370
|
+
```
|
1371
|
+
|
1372
|
+
* Available on Oktest >= 1.4.
|
1373
|
+
|
1374
|
+
|
1375
|
+
### `capture_stderr()`
|
1376
|
+
|
1377
|
+
`capture_stderr()` captures output of $stderr.
|
1378
|
+
If output of $stdout is not empty, assertion error will be raised.
|
1379
|
+
|
1380
|
+
`capture_stderr()` is almost same as the following.
|
1381
|
+
|
1382
|
+
```ruby
|
1383
|
+
def capture_stderr(*args, **kwargs, &b)
|
1384
|
+
sout, serr = capture_stdio(*args, **kwargs, &b)
|
1385
|
+
ok {sout} == ""
|
1386
|
+
return serr
|
1387
|
+
end
|
1388
|
+
```
|
1389
|
+
|
1390
|
+
* Available on Oktest >= 1.4.
|
1391
|
+
|
1392
|
+
|
1393
|
+
### `capture_command()`
|
1394
|
+
|
1395
|
+
`capture_command()` executes a command and returns output of stdout and stderr.
|
1396
|
+
|
1397
|
+
test/example32_test.rb:
|
1398
|
+
|
1399
|
+
```ruby
|
1400
|
+
require 'oktest'
|
1401
|
+
|
1402
|
+
Oktest.scope do
|
1403
|
+
|
1404
|
+
topic "Capturing" do
|
1405
|
+
|
1406
|
+
spec "example spec" do
|
1407
|
+
input = "AAA\nBBB\n"
|
1408
|
+
sout, serr = capture_command("cat -n", input) # !!!!!
|
1409
|
+
ok {sout} == " 1\tAAA\n 2\tBBB\n"
|
1410
|
+
ok {serr} == ""
|
1411
|
+
end
|
1412
|
+
|
1413
|
+
spec "skip if command not installed" do
|
1414
|
+
begin
|
1415
|
+
sout, serr = capture_command "foobar"
|
1416
|
+
rescue Errno::ENOENT
|
1417
|
+
skip_when true, "command `foobar` not installed."
|
1418
|
+
end
|
1419
|
+
end
|
1420
|
+
|
1421
|
+
end
|
1422
|
+
|
1423
|
+
end
|
1424
|
+
```
|
1425
|
+
|
1426
|
+
* The second argument of `capture_command()` represents `$stdin` data.
|
1427
|
+
It is optional.
|
1428
|
+
* `capture_command()` raises RuntimeError if command failed.
|
1429
|
+
* `capture_command()` accepts error handler block. The block will be called only when command failed. If error handler block is specified, `capture_command()` doesn't raise RuntimeError even if command failed.
|
1430
|
+
* `capture_command()` raises `Errno::ENOENT` exception if command not found. This exception will not be handled by error handler block.
|
1431
|
+
* Keyword parameter `tty: true` is not available.
|
1432
|
+
* Available on Oktest >= 1.4.
|
1433
|
+
|
1434
|
+
|
1435
|
+
### `capture_command!()`
|
1436
|
+
|
1437
|
+
`capture_command!()` is similar to `capture_command()` but not raise error
|
1438
|
+
when command failed.
|
1439
|
+
|
1440
|
+
* Available on Oktest >= 1.4.
|
1340
1441
|
|
1341
1442
|
|
1342
1443
|
### `dummy_file()`
|
1343
1444
|
|
1344
1445
|
`dummy_file()` creates a dummy file temporarily.
|
1345
1446
|
|
1346
|
-
test/
|
1447
|
+
test/example33_test.rb:
|
1347
1448
|
|
1348
1449
|
```ruby
|
1349
1450
|
require 'oktest'
|
@@ -1383,7 +1484,7 @@ end
|
|
1383
1484
|
|
1384
1485
|
`dummy_dir()` creates a dummy directory temporarily.
|
1385
1486
|
|
1386
|
-
test/
|
1487
|
+
test/example34_test.rb:
|
1387
1488
|
|
1388
1489
|
```ruby
|
1389
1490
|
require 'oktest'
|
@@ -1425,7 +1526,7 @@ end
|
|
1425
1526
|
|
1426
1527
|
`dummy_values()` changes hash values temporarily.
|
1427
1528
|
|
1428
|
-
test/
|
1529
|
+
test/example35_test.rb:
|
1429
1530
|
|
1430
1531
|
```ruby
|
1431
1532
|
require 'oktest'
|
@@ -1477,7 +1578,7 @@ end
|
|
1477
1578
|
|
1478
1579
|
`dummy_attrs()` changes object attribute values temporarily.
|
1479
1580
|
|
1480
|
-
test/
|
1581
|
+
test/example36_test.rb:
|
1481
1582
|
|
1482
1583
|
```ruby
|
1483
1584
|
require 'oktest'
|
@@ -1532,7 +1633,7 @@ end
|
|
1532
1633
|
|
1533
1634
|
`dummy_ivars()` changes instance variables in object with dummy values temporarily.
|
1534
1635
|
|
1535
|
-
test/
|
1636
|
+
test/example37_test.rb:
|
1536
1637
|
|
1537
1638
|
```ruby
|
1538
1639
|
require 'oktest'
|
@@ -1589,7 +1690,7 @@ end
|
|
1589
1690
|
See [Benry::Recorder README](https://github.com/kwatch/benry-ruby/blob/ruby/benry-recorder/README.md)
|
1590
1691
|
for detals.
|
1591
1692
|
|
1592
|
-
test/
|
1693
|
+
test/example38_test.rb:
|
1593
1694
|
|
1594
1695
|
```ruby
|
1595
1696
|
require 'oktest'
|
data/Rakefile.rb
CHANGED
data/benchmark/run_all.rb
CHANGED