pork 0.9.0 → 0.9.1
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/.travis.yml +4 -2
- data/CHANGES.md +16 -0
- data/README.md +219 -125
- data/lib/pork.rb +69 -63
- data/lib/pork/version.rb +1 -1
- data/pork.gemspec +3 -3
- data/test/test_bacon.rb +1 -1
- data/test/test_nested.rb +38 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 885c569da2496923eeac8a765bb713a38d882e79
|
4
|
+
data.tar.gz: 0e9fb16d8d4b9de93177ea86da953639c7500e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66d37601b58be4a81c6c1e41fa4bde8c55d8a7ac827d43acf18ffae90babac1894dc0cb90c21d3edafb6c042a4c20bd81d1a992267b6655a9e8d92376ca9d819
|
7
|
+
data.tar.gz: 68ecfbbf3939cf7adeb1662dbcb826c5845a6e147d1dea0bcc348f1582593c8e01e43bda5fd20423446b47865b3a6720d21b21a1c549f5cf8b91fe534ddb2c75
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Pork 0.9.1 -- 2014-07-14
|
4
|
+
|
5
|
+
### Bugs fixed
|
6
|
+
|
7
|
+
* It would now properly `exit(1)` when there's an error.
|
8
|
+
* It would now properly search the stashes chain upon `paste`.
|
9
|
+
|
10
|
+
|
11
|
+
### Enhancement
|
12
|
+
|
13
|
+
* `Kernel#should` now accepts a second argument for building messages lazily.
|
14
|
+
* `Should#satisfy` now accepts a second argument for building messages lazily.
|
15
|
+
* Introduced `Pork.inspect_failure_mode` to switch failure display mode.
|
16
|
+
* Default `Pork.inspect_failure_mode` to `:auto`, which would display failures
|
17
|
+
accordingly.
|
18
|
+
|
3
19
|
## Pork 0.9.0 -- 2014-07-11
|
4
20
|
|
5
21
|
* First serious release! Bunch of updates. Nearly complete.
|
data/README.md
CHANGED
@@ -274,6 +274,196 @@ end
|
|
274
274
|
|
275
275
|
## The API
|
276
276
|
|
277
|
+
### Kernel#should
|
278
|
+
|
279
|
+
All the assertions begin with `should`. Whenever we called `should` on an
|
280
|
+
object, it would create an `Pork::Should` object which would verify the
|
281
|
+
assertion we make. For the simplest case, this verifies if `1 == 1`:
|
282
|
+
|
283
|
+
``` ruby
|
284
|
+
require 'pork/auto'
|
285
|
+
|
286
|
+
would{ 1.should.eq 1 }
|
287
|
+
```
|
288
|
+
|
289
|
+
Sometimes we would also want to have a customized message if the assertion
|
290
|
+
failed, as in `assert_equal 1, 1, 'the message'`, we pass the message as the
|
291
|
+
first argument to should.
|
292
|
+
|
293
|
+
``` ruby
|
294
|
+
require 'pork/auto'
|
295
|
+
|
296
|
+
would{ 1.should('verify one equals to one').eq 1 }
|
297
|
+
```
|
298
|
+
|
299
|
+
In a rare case, constructing the message could be expensive, so we might not
|
300
|
+
want to build the message if the assertion passed. Then we pass the second
|
301
|
+
argument as the constructor of the message.
|
302
|
+
|
303
|
+
``` ruby
|
304
|
+
require 'pork/auto'
|
305
|
+
|
306
|
+
would{ 1.should(nil, lambda{'verify one equals to one'}).eq 1 }
|
307
|
+
```
|
308
|
+
|
309
|
+
Other than built in assertions such as `eq`, all methods in the questioning
|
310
|
+
object are available. For example, for arrays we could use `empty?`,
|
311
|
+
`include?` and `[]`.
|
312
|
+
|
313
|
+
``` ruby
|
314
|
+
describe Array do
|
315
|
+
would 'have array methods as verifiers' do
|
316
|
+
[ ].should.empty?
|
317
|
+
[1].should.include? 1
|
318
|
+
[1].should[0]
|
319
|
+
end
|
320
|
+
end
|
321
|
+
```
|
322
|
+
|
323
|
+
The assertions would only fail whenever the result was `false` or `nil`,
|
324
|
+
otherwise pass.
|
325
|
+
|
326
|
+
### Pork::Should#satisfy
|
327
|
+
|
328
|
+
If we want to have custom verifier other than the methods from questioning
|
329
|
+
object, this is it.
|
330
|
+
|
331
|
+
``` ruby
|
332
|
+
require 'pork/auto'
|
333
|
+
|
334
|
+
describe do
|
335
|
+
divided_by_2 = lambda{ |n| n % 2 == 0 }
|
336
|
+
|
337
|
+
would do
|
338
|
+
2.should.satisfy(÷d_by_2)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
```
|
342
|
+
|
343
|
+
The message argument applies to `should` also applies to `satisfy`.
|
344
|
+
|
345
|
+
``` ruby
|
346
|
+
require 'pork/auto'
|
347
|
+
|
348
|
+
describe do
|
349
|
+
divided_by_2 = lambda{ |n| n % 2 == 0 }
|
350
|
+
|
351
|
+
would do
|
352
|
+
2.should.satisfy('be divided by two', ÷d_by_2)
|
353
|
+
2.should.satisfy(nil, lambda{'be divided by two'}, ÷d_by_2)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
```
|
357
|
+
|
358
|
+
### Pork::Should#not
|
359
|
+
|
360
|
+
An easy way to negate the expectation.
|
361
|
+
|
362
|
+
``` ruby
|
363
|
+
require 'pork/auto'
|
364
|
+
|
365
|
+
would{ 1.should.not.eq 2 }
|
366
|
+
```
|
367
|
+
|
368
|
+
### Pork::Should#eq
|
369
|
+
|
370
|
+
To avoid warnings from Ruby, using `eq` instead of `==`. It's fine if you
|
371
|
+
still prefer using `==` if you don't care about warnings.
|
372
|
+
|
373
|
+
``` ruby
|
374
|
+
require 'pork/auto'
|
375
|
+
|
376
|
+
would{ 1.should.eq 1 }
|
377
|
+
```
|
378
|
+
|
379
|
+
### Pork::Should#lt
|
380
|
+
|
381
|
+
To avoid warnings from Ruby, using `lt` instead of `<`. It's fine if you
|
382
|
+
still prefer using `<` if you don't care about warnings.
|
383
|
+
|
384
|
+
``` ruby
|
385
|
+
require 'pork/auto'
|
386
|
+
|
387
|
+
would{ 1.should.lt 2 }
|
388
|
+
```
|
389
|
+
|
390
|
+
### Pork::Should#gt
|
391
|
+
|
392
|
+
To avoid warnings from Ruby, using `gt` instead of `>`. It's fine if you
|
393
|
+
still prefer using `>` if you don't care about warnings.
|
394
|
+
|
395
|
+
``` ruby
|
396
|
+
require 'pork/auto'
|
397
|
+
|
398
|
+
would{ 1.should.gt 0 }
|
399
|
+
```
|
400
|
+
|
401
|
+
### Pork::Should#lte
|
402
|
+
|
403
|
+
To avoid warnings from Ruby, using `lte` instead of `<=`. It's fine if you
|
404
|
+
still prefer using `<=` if you don't care about warnings.
|
405
|
+
|
406
|
+
``` ruby
|
407
|
+
require 'pork/auto'
|
408
|
+
|
409
|
+
would{ 1.should.lte 1 }
|
410
|
+
```
|
411
|
+
|
412
|
+
### Pork::Should#gte
|
413
|
+
|
414
|
+
To avoid warnings from Ruby, using `gte` instead of `>=`. It's fine if you
|
415
|
+
still prefer using `>=` if you don't care about warnings.
|
416
|
+
|
417
|
+
``` ruby
|
418
|
+
require 'pork/auto'
|
419
|
+
|
420
|
+
would{ 1.should.gte 1 }
|
421
|
+
```
|
422
|
+
|
423
|
+
### Pork::Should#raise
|
424
|
+
|
425
|
+
Expect for exceptions! There are two ways to call it. Either you could use
|
426
|
+
lambda to wrap the questioning expression, or you could simply pass a block
|
427
|
+
as the questioning expression.
|
428
|
+
|
429
|
+
``` ruby
|
430
|
+
require 'pork/auto'
|
431
|
+
|
432
|
+
describe 'Pork::Should#raise' do
|
433
|
+
would 'check with a block' do
|
434
|
+
e = should.raise(RuntimeError){ raise "nnf" }
|
435
|
+
e.should.message.include?("nnf")
|
436
|
+
end
|
437
|
+
|
438
|
+
would 'check with a lambda' do
|
439
|
+
e = lambda{ raise "nnf" }.should.raise(RuntimeError)
|
440
|
+
e.should.message.include?("nnf")
|
441
|
+
end
|
442
|
+
end
|
443
|
+
```
|
444
|
+
|
445
|
+
### Pork::Should#throw
|
446
|
+
|
447
|
+
Expect for something to be thrown. There are two ways to call it. Either
|
448
|
+
you could use lambda to wrap the questioning expression, or you could
|
449
|
+
simply pass a block as the questioning expression.
|
450
|
+
|
451
|
+
``` ruby
|
452
|
+
require 'pork/auto'
|
453
|
+
|
454
|
+
describe 'Pork::Should#throw' do
|
455
|
+
would 'check with a block' do
|
456
|
+
e = should.throw(:nnf){ throw :nnf, 0 }
|
457
|
+
e.should.eq [:nnf, 0]
|
458
|
+
end
|
459
|
+
|
460
|
+
would 'check with a lambda' do
|
461
|
+
e = lambda{ throw :nnf, 1 }.should.throw(:nnf)
|
462
|
+
e.should.eq [:nnf, 1]
|
463
|
+
end
|
464
|
+
end
|
465
|
+
```
|
466
|
+
|
277
467
|
### Pork::API.describe
|
278
468
|
|
279
469
|
So this creates a test suite which should be containing various test cases
|
@@ -457,131 +647,6 @@ describe do
|
|
457
647
|
end
|
458
648
|
```
|
459
649
|
|
460
|
-
### Pork::Should#satisfy
|
461
|
-
|
462
|
-
If we want to have custom verifier, that is it.
|
463
|
-
|
464
|
-
``` ruby
|
465
|
-
require 'pork/auto'
|
466
|
-
|
467
|
-
describe do
|
468
|
-
divided_by_2 = lambda{ |n| n % 2 == 0 }
|
469
|
-
|
470
|
-
would do
|
471
|
-
2.should.satisfy(÷d_by_2)
|
472
|
-
end
|
473
|
-
end
|
474
|
-
```
|
475
|
-
|
476
|
-
### Pork::Should#not
|
477
|
-
|
478
|
-
An easy way to negate the expectation.
|
479
|
-
|
480
|
-
``` ruby
|
481
|
-
require 'pork/auto'
|
482
|
-
|
483
|
-
would{ 1.should.not.eq 2 }
|
484
|
-
```
|
485
|
-
|
486
|
-
### Pork::Should#eq
|
487
|
-
|
488
|
-
To avoid warnings from Ruby, using `eq` instead of `==`. It's fine if you
|
489
|
-
still prefer using `==` if you don't care about warnings.
|
490
|
-
|
491
|
-
``` ruby
|
492
|
-
require 'pork/auto'
|
493
|
-
|
494
|
-
would{ 1.should.eq 1 }
|
495
|
-
```
|
496
|
-
|
497
|
-
### Pork::Should#lt
|
498
|
-
|
499
|
-
To avoid warnings from Ruby, using `lt` instead of `<`. It's fine if you
|
500
|
-
still prefer using `<` if you don't care about warnings.
|
501
|
-
|
502
|
-
``` ruby
|
503
|
-
require 'pork/auto'
|
504
|
-
|
505
|
-
would{ 1.should.lt 2 }
|
506
|
-
```
|
507
|
-
|
508
|
-
### Pork::Should#gt
|
509
|
-
|
510
|
-
To avoid warnings from Ruby, using `gt` instead of `>`. It's fine if you
|
511
|
-
still prefer using `>` if you don't care about warnings.
|
512
|
-
|
513
|
-
``` ruby
|
514
|
-
require 'pork/auto'
|
515
|
-
|
516
|
-
would{ 1.should.gt 0 }
|
517
|
-
```
|
518
|
-
|
519
|
-
### Pork::Should#lte
|
520
|
-
|
521
|
-
To avoid warnings from Ruby, using `lte` instead of `<=`. It's fine if you
|
522
|
-
still prefer using `<=` if you don't care about warnings.
|
523
|
-
|
524
|
-
``` ruby
|
525
|
-
require 'pork/auto'
|
526
|
-
|
527
|
-
would{ 1.should.lte 1 }
|
528
|
-
```
|
529
|
-
|
530
|
-
### Pork::Should#gte
|
531
|
-
|
532
|
-
To avoid warnings from Ruby, using `gte` instead of `>=`. It's fine if you
|
533
|
-
still prefer using `>=` if you don't care about warnings.
|
534
|
-
|
535
|
-
``` ruby
|
536
|
-
require 'pork/auto'
|
537
|
-
|
538
|
-
would{ 1.should.gte 1 }
|
539
|
-
```
|
540
|
-
|
541
|
-
### Pork::Should#raise
|
542
|
-
|
543
|
-
Expect for exceptions! There are two ways to call it. Either you could use
|
544
|
-
lambda to wrap the questioning expression, or you could simply pass a block
|
545
|
-
as the questioning expression.
|
546
|
-
|
547
|
-
``` ruby
|
548
|
-
require 'pork/auto'
|
549
|
-
|
550
|
-
describe 'Pork::Should#raise' do
|
551
|
-
would 'check with a block' do
|
552
|
-
e = should.raise(RuntimeError){ raise "nnf" }
|
553
|
-
e.should.message.include?("nnf")
|
554
|
-
end
|
555
|
-
|
556
|
-
would 'check with a lambda' do
|
557
|
-
e = lambda{ raise "nnf" }.should.raise(RuntimeError)
|
558
|
-
e.should.message.include?("nnf")
|
559
|
-
end
|
560
|
-
end
|
561
|
-
```
|
562
|
-
|
563
|
-
### Pork::Should#throw
|
564
|
-
|
565
|
-
Expect for something to be thrown. There are two ways to call it. Either
|
566
|
-
you could use lambda to wrap the questioning expression, or you could
|
567
|
-
simply pass a block as the questioning expression.
|
568
|
-
|
569
|
-
``` ruby
|
570
|
-
require 'pork/auto'
|
571
|
-
|
572
|
-
describe 'Pork::Should#throw' do
|
573
|
-
would 'check with a block' do
|
574
|
-
e = should.throw(:nnf){ throw :nnf, 0 }
|
575
|
-
e.should.eq [:nnf, 0]
|
576
|
-
end
|
577
|
-
|
578
|
-
would 'check with a lambda' do
|
579
|
-
e = lambda{ throw :nnf, 1 }.should.throw(:nnf)
|
580
|
-
e.should.eq [:nnf, 1]
|
581
|
-
end
|
582
|
-
end
|
583
|
-
```
|
584
|
-
|
585
650
|
### Pork.report
|
586
651
|
|
587
652
|
Report the summary from the tests. Usually you would want to call this at
|
@@ -606,9 +671,38 @@ extend Pork::API
|
|
606
671
|
Pork.report_at_exit
|
607
672
|
```
|
608
673
|
|
674
|
+
### Pork.inspect_failure_mode
|
675
|
+
|
676
|
+
By default, `Pork.inspect_failure_mode` is set to `:auto`, which would
|
677
|
+
display failures accordingly. For example, if the message is short, it would
|
678
|
+
simply show the message. But if the message is long, it would try to insert
|
679
|
+
a newline between actual result and expected result, since it would be much
|
680
|
+
easier for human to distinguish the difference this way. If the message is
|
681
|
+
really long, it would even use `diff` to show the difference.
|
682
|
+
|
683
|
+
This is because if the actual string is long, it would be quite painful to
|
684
|
+
find the actual difference for human without assistance.
|
685
|
+
|
686
|
+
However, this might not really be desired at times. So we should be able to
|
687
|
+
switch between each mode. For now, we have the following modes:
|
688
|
+
|
689
|
+
* :auto (default)
|
690
|
+
* :inline
|
691
|
+
* :newline
|
692
|
+
* :diff
|
693
|
+
|
694
|
+
If we want to force to a specific mode, here's how we would do:
|
695
|
+
|
696
|
+
``` ruby
|
697
|
+
Pork.inspect_failure_mode :newline
|
698
|
+
```
|
699
|
+
|
700
|
+
Then it would always use the mode we specified.
|
701
|
+
|
609
702
|
## CONTRIBUTORS:
|
610
703
|
|
611
704
|
* Lin Jen-Shin (@godfat)
|
705
|
+
* Josh Kalderimis (@joshk)
|
612
706
|
|
613
707
|
## LICENSE:
|
614
708
|
|
data/lib/pork.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require 'thread'
|
3
3
|
|
4
4
|
module Kernel
|
5
|
-
def should message=nil, &checker
|
6
|
-
Pork::Should.new(self, message, &checker)
|
5
|
+
def should message=nil, message_lazy=nil, &checker
|
6
|
+
Pork::Should.new(self, message, message_lazy, &checker)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -19,7 +19,55 @@ module Pork
|
|
19
19
|
Pork.stats.start
|
20
20
|
@report_at_exit ||= at_exit do
|
21
21
|
stats.report
|
22
|
-
exit stats.failures.size + stats.errors.size
|
22
|
+
exit stats.failures.size + stats.errors.size + ($! && 1).to_i
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# default to :auto while eliminating warnings for uninitialized ivar
|
26
|
+
def self.inspect_failure_mode mode=nil; @mode = mode || @mode ||= :auto; end
|
27
|
+
def self.inspect_failure *args
|
28
|
+
lambda{ public_send("inspect_failure_#{inspect_failure_mode}", *args) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.inspect_failure_auto object, msg, args, negate
|
32
|
+
if args.size > 1
|
33
|
+
inspect_failure_inline(object, msg, args, negate)
|
34
|
+
elsif object.kind_of?(Hash) && args.first.kind_of?(Hash)
|
35
|
+
inspect_failure_inline(Hash[object.sort], msg,
|
36
|
+
[Hash[args.first.sort]], negate)
|
37
|
+
elsif object.kind_of?(String) && object.size > 400 &&
|
38
|
+
object.count("\n") > 4 && !`which diff`.empty?
|
39
|
+
inspect_failure_diff(object, msg, args, negate)
|
40
|
+
else
|
41
|
+
ins = object.inspect
|
42
|
+
if ins.size > 78
|
43
|
+
inspect_failure_newline(object, msg, args, negate)
|
44
|
+
else
|
45
|
+
inspect_failure_inline( object, msg, args, negate)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.inspect_failure_inline object, msg, args, negate
|
51
|
+
a = args.map(&:inspect).join(', ')
|
52
|
+
"#{object.inspect}.#{msg}(#{a}) to return #{!negate}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.inspect_failure_newline object, msg, args, negate
|
56
|
+
a = args.map(&:inspect).join(",\n")
|
57
|
+
"\n#{object.inspect}.#{msg}(\n#{a}) to return #{!negate}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.inspect_failure_diff object, msg, args, negate
|
61
|
+
require 'tempfile'
|
62
|
+
Tempfile.open('pork-expect') do |expect|
|
63
|
+
Tempfile.open('pork-was') do |was|
|
64
|
+
expect.puts(object.to_s)
|
65
|
+
expect.close
|
66
|
+
was.puts(args.map(&:to_s).join(",\n"))
|
67
|
+
was.close
|
68
|
+
name = "#{object.class}##{msg}(\n"
|
69
|
+
"#{name}#{`diff #{expect.path} #{was.path}`}) to return #{!negate}"
|
70
|
+
end
|
23
71
|
end
|
24
72
|
end
|
25
73
|
|
@@ -46,8 +94,7 @@ module Pork
|
|
46
94
|
end
|
47
95
|
def copy desc=:default, &suite; stash[desc] = suite; end
|
48
96
|
def paste desc=:default, *args
|
49
|
-
|
50
|
-
module_exec(*args, &stashes.find{ |s| s[desc] }[desc])
|
97
|
+
module_exec(*args, &search_stash(desc))
|
51
98
|
end
|
52
99
|
def would desc=:default, &test
|
53
100
|
assertions = Pork.stats.assertions
|
@@ -74,21 +121,22 @@ module Pork
|
|
74
121
|
end
|
75
122
|
|
76
123
|
protected
|
77
|
-
def init desc=''
|
78
|
-
@desc, @before, @after, @stash = desc, [], [], {}
|
79
|
-
end
|
124
|
+
def init desc=''; @desc, @before, @after, @stash = desc, [], [], {}; end
|
80
125
|
def super_executor
|
81
126
|
@super_executor ||= ancestors[1..-1].find{ |a| a <= Executor }
|
82
127
|
end
|
128
|
+
def search_stash desc
|
129
|
+
stash[desc] or super_executor && super_executor.search_stash(desc)
|
130
|
+
end
|
83
131
|
def description_for name=''
|
84
132
|
"#{desc}#{super_executor && super_executor.description_for}#{name}"
|
85
133
|
end
|
86
134
|
def run_before context
|
87
|
-
super_executor.run_before(context)
|
135
|
+
super_executor && super_executor.run_before(context)
|
88
136
|
before.each{ |b| context.instance_eval(&b) }
|
89
137
|
end
|
90
138
|
def run_after context
|
91
|
-
super_executor.run_after(context)
|
139
|
+
super_executor && super_executor.run_after(context)
|
92
140
|
after.each{ |b| context.instance_eval(&b) }
|
93
141
|
end
|
94
142
|
end
|
@@ -101,58 +149,26 @@ module Pork
|
|
101
149
|
def ok ; Pork.stats.incr_assertions ; end
|
102
150
|
end
|
103
151
|
|
104
|
-
module InspectInlineError
|
105
|
-
def inspect_error object, msg, args, negate
|
106
|
-
a = args.map(&:inspect).join(', ')
|
107
|
-
"#{object.inspect}.#{msg}(#{a}) to return #{!negate}"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
module InspectNewlineError
|
112
|
-
def inspect_error object, msg, args, negate
|
113
|
-
a = args.map(&:inspect).join(', ')
|
114
|
-
"\n#{object.inspect}.#{msg}(\n#{a}) to return #{!negate}"
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
module InspectDiffError
|
119
|
-
def inspect_error object, msg, args, negate
|
120
|
-
::Kernel.require 'tempfile'
|
121
|
-
::Tempfile.open('pork-expect') do |expect|
|
122
|
-
::Tempfile.open('pork-was') do |was|
|
123
|
-
expect.puts(object.to_s)
|
124
|
-
expect.close
|
125
|
-
was.puts(args.map(&:to_s).join(",\n"))
|
126
|
-
was.close
|
127
|
-
name = "#{object.class}##{msg}(\n"
|
128
|
-
diff = ::Kernel.__send__(:`, "diff #{expect.path} #{was.path}")
|
129
|
-
"#{name}#{diff}) to return #{!negate}"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
152
|
class Should < BasicObject
|
136
153
|
instance_methods.each{ |m| undef_method(m) unless m =~ /^__|^object_id$/ }
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
@object = object
|
141
|
-
@negate = false
|
142
|
-
@message = message
|
154
|
+
def initialize object, message=nil, message_lazy=nil, &checker
|
155
|
+
@object, @negate = object, false
|
156
|
+
@message, @message_lazy = message, message_lazy
|
143
157
|
satisfy(&checker) if checker
|
144
158
|
end
|
145
159
|
|
146
160
|
def method_missing msg, *args, &block
|
147
|
-
satisfy(
|
161
|
+
satisfy(nil, ::Pork.inspect_failure(@object, msg, args, @negate)) do
|
148
162
|
@object.public_send(msg, *args, &block)
|
149
163
|
end
|
150
164
|
end
|
151
165
|
|
152
|
-
def satisfy desc=@object
|
166
|
+
def satisfy desc=@object, desc_lazy=nil
|
153
167
|
result = yield(@object)
|
154
168
|
if !!result == @negate
|
155
|
-
|
169
|
+
d = desc_lazy && desc_lazy.call || desc
|
170
|
+
m = @message_lazy && @message_lazy.call || @message
|
171
|
+
::Kernel.raise Failure.new("Expect #{d}\n#{m}".chomp)
|
156
172
|
else
|
157
173
|
::Pork.stats.incr_assertions
|
158
174
|
end
|
@@ -195,13 +211,7 @@ module Pork
|
|
195
211
|
end
|
196
212
|
|
197
213
|
private
|
198
|
-
def __not__
|
199
|
-
if @negate == true
|
200
|
-
'not '
|
201
|
-
else
|
202
|
-
''
|
203
|
-
end
|
204
|
-
end
|
214
|
+
def __not__; if @negate == true then 'not ' else '' end; end
|
205
215
|
end
|
206
216
|
|
207
217
|
class Stats < Struct.new(:tests, :assertions, :skips, :failures, :errors)
|
@@ -214,12 +224,8 @@ module Pork
|
|
214
224
|
def incr_skips ; @mutex.synchronize{ self.skips += 1; print('s')}; end
|
215
225
|
def add_failure *e ; @mutex.synchronize{ failures << e; print('F')}; end
|
216
226
|
def add_error *e ; @mutex.synchronize{ errors << e; print('E')}; end
|
217
|
-
def numbers
|
218
|
-
|
219
|
-
end
|
220
|
-
def start
|
221
|
-
@start ||= Time.now
|
222
|
-
end
|
227
|
+
def numbers; [tests, assertions, failures.size, errors.size, skips]; end
|
228
|
+
def start ; @start ||= Time.now ; end
|
223
229
|
def report
|
224
230
|
puts
|
225
231
|
puts (failures + errors).map{ |(e, m)|
|
data/lib/pork/version.rb
CHANGED
data/pork.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: pork 0.9.
|
2
|
+
# stub: pork 0.9.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "pork"
|
6
|
-
s.version = "0.9.
|
6
|
+
s.version = "0.9.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2014-07-
|
11
|
+
s.date = "2014-07-14"
|
12
12
|
s.description = "Pork -- Simple and clean and modular testing library.\n\n[Bacon][] reimplemented around 250 lines of code.\n\n[Bacon]: https://github.com/chneukirchen/bacon"
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.files = [
|
data/test/test_bacon.rb
CHANGED
data/test/test_nested.rb
CHANGED
@@ -44,6 +44,10 @@ describe 'A' do
|
|
44
44
|
would do
|
45
45
|
t.should.eq true
|
46
46
|
end
|
47
|
+
|
48
|
+
describe 'C' do
|
49
|
+
paste
|
50
|
+
end
|
47
51
|
end
|
48
52
|
|
49
53
|
would 'skip' do
|
@@ -55,3 +59,37 @@ end
|
|
55
59
|
would 'also work on top-level' do
|
56
60
|
true.should.eq true
|
57
61
|
end
|
62
|
+
|
63
|
+
describe 'Pork.inspect_failure' do
|
64
|
+
would 'hash' do
|
65
|
+
Pork.inspect_failure_auto(
|
66
|
+
{:b => 1, :a => 0}, :==, [{:a => 1, :b => 0}], false).
|
67
|
+
should.eq '{:a=>0, :b=>1}.==({:a=>1, :b=>0}) to return true'
|
68
|
+
end
|
69
|
+
|
70
|
+
would 'newline' do
|
71
|
+
obj, arg = 'a'*80, 'b'*80
|
72
|
+
Pork.inspect_failure_auto(obj, :==, [arg], true).
|
73
|
+
should.eq "\n#{obj.inspect}.==(\n#{arg.inspect}) to return false"
|
74
|
+
end
|
75
|
+
|
76
|
+
would 'diff' do
|
77
|
+
s = File.read(__FILE__)
|
78
|
+
n = s.count("\n")
|
79
|
+
Pork.inspect_failure_auto(s, :==, ["#{s}b\n"], true).
|
80
|
+
should.eq "String#==(\n#{n}a#{n+1}\n> b\n) to return false"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'should(message)' do
|
85
|
+
would 'show message' do
|
86
|
+
should.raise(Pork::Failure){ should('nnf').satisfy('qoo'){ false } }.
|
87
|
+
message.should.eq "Expect qoo\nnnf"
|
88
|
+
end
|
89
|
+
|
90
|
+
would 'show lazy message' do
|
91
|
+
should.raise(Pork::Failure) do
|
92
|
+
should(nil, lambda{'nnf'}).satisfy(nil, lambda{'qoo'}){ false }
|
93
|
+
end.message.should.eq "Expect qoo\nnnf"
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Pork -- Simple and clean and modular testing library.
|