pork 1.2.2 → 1.2.3
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/CHANGES.md +10 -0
- data/README.md +86 -21
- data/lib/pork/imp.rb +2 -2
- data/lib/pork/mode/shuffled.rb +42 -10
- data/lib/pork/version.rb +1 -1
- data/pork.gemspec +5 -3
- data/test/test_pork_test.rb +57 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 095bec1d9b0e5589ead858fce38929b381210569
|
4
|
+
data.tar.gz: a311efe4b88dd95d9d3121092ebd716227d6e207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d580f3bb350761f874bfa061d554cb0d7c2f8a4fd74ac6fe90465c9c06100f89fba3186d452751f8a28bd72ebc4a7727ec0862b0523727cdf463f701531378d1
|
7
|
+
data.tar.gz: af26e6604565d1b9041b30f0a993cae03c58ac4bcf515f376eb0bdaa187c3d5b3da0b6e683b49a82daae58d8a64fe36b5edb646cf366e618744a0715af17f402
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Pork 1.2.3 -- 2015-04-16
|
4
|
+
|
5
|
+
### Enhancement
|
6
|
+
|
7
|
+
* Now `would` could take a second argument with `:group => [:name]`,
|
8
|
+
and you could also specifying the groups to run in `PORK_TEST`.
|
9
|
+
Checkout README for more information. Input from @mz026
|
10
|
+
|
11
|
+
* `PORK_TEST` could also accept a file path without a line number now.
|
12
|
+
|
3
13
|
## Pork 1.2.2 -- 2015-03-19
|
4
14
|
|
5
15
|
### Enhancement
|
data/README.md
CHANGED
@@ -361,16 +361,6 @@ run `rake test` to run all the tests.
|
|
361
361
|
[Fish shell]: http://fishshell.com/
|
362
362
|
[gemgem]: https://github.com/godfat/gemgem
|
363
363
|
|
364
|
-
## Mutant integration
|
365
|
-
|
366
|
-
Pork also ships with [mutant][] integration. Here's an example to run it:
|
367
|
-
|
368
|
-
mutant -Ilib -rjellyfish --use pork Jellyfish
|
369
|
-
|
370
|
-
for [jellyfish][].
|
371
|
-
|
372
|
-
[jellyfish]: https://github.com/godfat/jellyfish
|
373
|
-
|
374
364
|
## The API
|
375
365
|
|
376
366
|
### Kernel#should
|
@@ -764,23 +754,80 @@ describe do
|
|
764
754
|
end
|
765
755
|
```
|
766
756
|
|
767
|
-
|
757
|
+
## The Options
|
768
758
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
759
|
+
### `env PORK_TEST=`
|
760
|
+
|
761
|
+
As the code base grows, at some point running the whole test suites could be
|
762
|
+
very slow and frustrating while doing agile development. In this case, we
|
763
|
+
might want to run only a subset of the whole test suites. Granted that we
|
764
|
+
could already divide the tests into files, and only load one file and run
|
765
|
+
tests inside the file. But if the tests are just slow, we might still want to
|
766
|
+
run only a specific test case. This is where `env PORK_TEST=` shines.
|
767
|
+
|
768
|
+
Suppose you run the tests via:
|
769
|
+
|
770
|
+
``` shell
|
771
|
+
ruby -Ilib test/test_pork.rb
|
772
|
+
```
|
773
|
+
|
774
|
+
Then you could do:
|
775
|
+
|
776
|
+
``` shell
|
777
|
+
env PORK_TEST=test/test_pork.rb:123 ruby -Ilib test/test_pork.rb
|
778
|
+
```
|
779
|
+
|
780
|
+
So that it would only run the test case around test_pork.rb line 123.
|
781
|
+
If you run the tests via:
|
782
|
+
|
783
|
+
``` shell
|
784
|
+
rake test
|
785
|
+
```
|
786
|
+
|
787
|
+
Then you could do:
|
788
|
+
|
789
|
+
``` shell
|
790
|
+
env PORK_TEST=test/test_pork.rb:123 rake test
|
791
|
+
```
|
792
|
+
|
793
|
+
It's the same thing just that `rake test` might load more tests which would
|
794
|
+
never run. Note that if you omit the line number, then the whole file would
|
795
|
+
run.
|
796
|
+
|
797
|
+
#### `env PORK_TEST=` with `:groups`
|
798
|
+
|
799
|
+
`PORK_TEST` could also take a list of groups. Groups are defined in the tests,
|
800
|
+
as the second argument to `would`. Take this as an example:
|
774
801
|
|
775
|
-
It would also exit with 0 if no error occurs or N for N errors and failures.
|
776
802
|
|
777
803
|
``` ruby
|
778
|
-
|
779
|
-
|
780
|
-
|
804
|
+
would 'pass', :groups => [:core, :more] do
|
805
|
+
ok
|
806
|
+
end
|
807
|
+
|
808
|
+
would 'also pass', :groups => [:more] do
|
809
|
+
ok
|
810
|
+
end
|
781
811
|
```
|
782
812
|
|
783
|
-
|
813
|
+
Then if specifying `PORK_TEST=more`, then both tests would run. If specifying
|
814
|
+
`PORK_TEST=core`, then only the first would run. We could also specifying
|
815
|
+
multiple groups, separated with commas (,), like `PORK_TEST=core,more`,
|
816
|
+
then of course both tests would run.
|
817
|
+
|
818
|
+
This would be very useful when you want to run a specific test case without
|
819
|
+
typing the whole file path and finding the line number. Just edit your test
|
820
|
+
source by adding some temporary group like `:groups => [:test]` and then
|
821
|
+
run the test command prefixed by `env PORK_TEST=test` then you're done.
|
822
|
+
You could just remove the group after debugging. This must be much easier to
|
823
|
+
do then commenting out a bunch of random codes in the tests.
|
824
|
+
|
825
|
+
Summary by examples:
|
826
|
+
|
827
|
+
* `env PORK_TEST='test/test_pork.rb:123' rake test`
|
828
|
+
* `env PORK_TEST='test/test_pork.rb' rake test`
|
829
|
+
* `env PORK_TEST='group0' rake test`
|
830
|
+
* `env PORK_TEST='group0,group1' rake test`
|
784
831
|
|
785
832
|
### Pork.execute_mode
|
786
833
|
|
@@ -866,6 +913,24 @@ Pork.inspect_failure_mode :newline
|
|
866
913
|
|
867
914
|
Then it would always use the mode we specified.
|
868
915
|
|
916
|
+
### Pork.autorun
|
917
|
+
|
918
|
+
Calling this would register an `at_exit` hook to run tests at exit.
|
919
|
+
This also accepts an argument to turn on and off autorun. Calling this
|
920
|
+
multiple times is ok. (It's not thread safe though, don't call this twice
|
921
|
+
from different threads at the same time. If you really want to do this,
|
922
|
+
let's add a mutex for this)
|
923
|
+
|
924
|
+
It would also exit with 0 if no error occurs or N for N errors and failures.
|
925
|
+
|
926
|
+
``` ruby
|
927
|
+
Pork.autorun # enable
|
928
|
+
Pork.autorun(false) # disable
|
929
|
+
Pork.autorun(true) # enable
|
930
|
+
```
|
931
|
+
|
932
|
+
`require 'pork/auto'` would call `Pork.autorun`
|
933
|
+
|
869
934
|
### Pork.Rainbows!
|
870
935
|
|
871
936
|
Have you seen Rainbows!?
|
data/lib/pork/imp.rb
CHANGED
data/lib/pork/mode/shuffled.rb
CHANGED
@@ -8,15 +8,32 @@ module Pork
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def all_paths
|
11
|
-
all_tests.values.flat_map(&:values).flatten(1)
|
11
|
+
(all_tests[:files] || {}).values.flat_map(&:values).flatten(1)
|
12
12
|
end
|
13
13
|
|
14
|
-
def []
|
15
|
-
|
14
|
+
def [] index
|
15
|
+
by_groups(index) || by_source(index)
|
16
|
+
end
|
17
|
+
|
18
|
+
def by_groups groups
|
19
|
+
return unless tests = all_tests[:groups]
|
20
|
+
paths = groups.split(',').flat_map do |g|
|
21
|
+
tests[g.strip] || []
|
22
|
+
end.uniq
|
23
|
+
paths unless paths.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def by_source source
|
27
|
+
return unless tests = all_tests[:files]
|
28
|
+
file_str, line_str = source.split(':')
|
16
29
|
file, line = File.expand_path(file_str), line_str.to_i
|
17
|
-
return unless
|
18
|
-
|
19
|
-
|
30
|
+
return unless cases = tests[file]
|
31
|
+
if line.zero?
|
32
|
+
cases.values.flatten(1)
|
33
|
+
else
|
34
|
+
_, paths = cases.reverse_each.find{ |(l, _)| l <= line }
|
35
|
+
paths
|
36
|
+
end
|
20
37
|
end
|
21
38
|
|
22
39
|
def shuffled stat=Stat.new, paths=all_paths
|
@@ -48,18 +65,33 @@ module Pork
|
|
48
65
|
end
|
49
66
|
|
50
67
|
def build_all_tests result={}, path=[]
|
51
|
-
@tests.each_with_index.inject(result) do |r,
|
68
|
+
@tests.each_with_index.inject(result) do |r,
|
69
|
+
((type, imp, test, opts),
|
70
|
+
index)|
|
52
71
|
current = path + [index]
|
53
72
|
case type
|
54
73
|
when :describe
|
55
|
-
|
74
|
+
imp.build_all_tests(r, current)
|
56
75
|
when :would
|
57
|
-
|
58
|
-
(
|
76
|
+
groups = opts[:groups]
|
77
|
+
store_for_groups(r, current, groups) if groups
|
78
|
+
store_for_source(r, current, *test.source_location)
|
59
79
|
end
|
60
80
|
r
|
61
81
|
end
|
62
82
|
end
|
83
|
+
|
84
|
+
def store_for_groups tests, path, groups
|
85
|
+
r = tests[:groups] ||= {}
|
86
|
+
groups.each do |g|
|
87
|
+
(r[g.to_s] ||= []) << path
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def store_for_source tests, path, file, line
|
92
|
+
r = tests[:files] ||= {}
|
93
|
+
((r[File.expand_path(file)] ||= {})[line] ||= []) << path
|
94
|
+
end
|
63
95
|
end
|
64
96
|
|
65
97
|
Executor.extend(Shuffled)
|
data/lib/pork/version.rb
CHANGED
data/pork.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: pork 1.2.
|
2
|
+
# stub: pork 1.2.3 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "pork"
|
6
|
-
s.version = "1.2.
|
6
|
+
s.version = "1.2.3"
|
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 = "2015-
|
11
|
+
s.date = "2015-04-16"
|
12
12
|
s.description = "Pork -- Simple and clean and modular testing library.\n\nInspired by [Bacon][].\n\n[Bacon]: https://github.com/chneukirchen/bacon"
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.files = [
|
@@ -47,6 +47,7 @@ Gem::Specification.new do |s|
|
|
47
47
|
"test/test_bacon.rb",
|
48
48
|
"test/test_inspect.rb",
|
49
49
|
"test/test_nested.rb",
|
50
|
+
"test/test_pork_test.rb",
|
50
51
|
"test/test_readme.rb",
|
51
52
|
"test/test_should.rb"]
|
52
53
|
s.homepage = "https://github.com/godfat/pork"
|
@@ -57,6 +58,7 @@ Gem::Specification.new do |s|
|
|
57
58
|
"test/test_bacon.rb",
|
58
59
|
"test/test_inspect.rb",
|
59
60
|
"test/test_nested.rb",
|
61
|
+
"test/test_pork_test.rb",
|
60
62
|
"test/test_readme.rb",
|
61
63
|
"test/test_should.rb"]
|
62
64
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
require 'pork/test'
|
3
|
+
|
4
|
+
describe 'PORK_TEST=a' do
|
5
|
+
def verify line, executor, index
|
6
|
+
path = executor[index].first
|
7
|
+
type, desc, block, opts = extract(path, executor)
|
8
|
+
expect(type) .eq :would
|
9
|
+
expect(desc) .eq 'find the corresponding test case'
|
10
|
+
expect(block.source_location).eq [__FILE__, line]
|
11
|
+
expect(opts) .eq :groups => [:a, :b]
|
12
|
+
end
|
13
|
+
|
14
|
+
def extract path, executor
|
15
|
+
path.inject(executor.instance_variable_get(:@tests)) do |tests, idx|
|
16
|
+
type, arg, = tests[idx]
|
17
|
+
case type
|
18
|
+
when :describe # we need to go deeper
|
19
|
+
arg.instance_variable_get(:@tests)
|
20
|
+
else
|
21
|
+
tests[idx] # should end here
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
would 'find the corresponding test case', :groups => [:a, :b] do
|
27
|
+
line = __LINE__ - 1
|
28
|
+
[self.class, Pork::Executor].each do |executor|
|
29
|
+
verify(line, executor, "#{__FILE__}:#{__LINE__}") # line
|
30
|
+
verify(line, executor, 'a') # group
|
31
|
+
verify(line, executor, "#{__FILE__}:#{__LINE__}") # diff line
|
32
|
+
verify(line, executor, __FILE__) # file
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'PORK_TEST=b' do
|
37
|
+
would 'find both', :groups => [:b] do
|
38
|
+
line = __LINE__ - 1
|
39
|
+
Pork::Executor[__FILE__].size.should.eq 2
|
40
|
+
Pork::Executor['a'] .size.should.eq 1
|
41
|
+
Pork::Executor['b'] .size.should.eq 2
|
42
|
+
Pork::Executor['b'] .should.eq Pork::Executor[__FILE__]
|
43
|
+
Pork::Executor['a,b'] .should.eq Pork::Executor[__FILE__]
|
44
|
+
self.class['a'] .should.nil?
|
45
|
+
self.class['b'] .size.should.eq 1
|
46
|
+
|
47
|
+
a, b = Pork::Executor['b'].map{ |path| extract(path, Pork::Executor) }
|
48
|
+
expect(a[0]) .eq :would
|
49
|
+
expect(a[1]) .eq 'find the corresponding test case'
|
50
|
+
expect(a[3]) .eq :groups => [:a, :b]
|
51
|
+
expect(b[0]) .eq :would
|
52
|
+
expect(b[1]) .eq 'find both'
|
53
|
+
expect(b[2].source_location).eq [__FILE__, line]
|
54
|
+
expect(b[3]) .eq :groups => [:b]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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: 1.2.
|
4
|
+
version: 1.2.3
|
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: 2015-
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: muack
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- test/test_bacon.rb
|
72
72
|
- test/test_inspect.rb
|
73
73
|
- test/test_nested.rb
|
74
|
+
- test/test_pork_test.rb
|
74
75
|
- test/test_readme.rb
|
75
76
|
- test/test_should.rb
|
76
77
|
homepage: https://github.com/godfat/pork
|
@@ -101,5 +102,6 @@ test_files:
|
|
101
102
|
- test/test_bacon.rb
|
102
103
|
- test/test_inspect.rb
|
103
104
|
- test/test_nested.rb
|
105
|
+
- test/test_pork_test.rb
|
104
106
|
- test/test_readme.rb
|
105
107
|
- test/test_should.rb
|