pork 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGES.md +19 -0
- data/README.md +14 -12
- data/lib/pork.rb +14 -7
- data/lib/pork/extra/show_source.rb +2 -0
- data/lib/pork/imp.rb +3 -3
- data/lib/pork/mode/shuffled.rb +18 -13
- data/lib/pork/test.rb +2 -2
- data/lib/pork/version.rb +1 -1
- data/pork.gemspec +4 -4
- data/test/test_pork_test.rb +23 -7
- data/test/test_stat.rb +42 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e51ae61ad2d2b0d608bdb753560c3cc2294cd1d
|
4
|
+
data.tar.gz: ca7c3abfecf2f801008cd1b9583abd4dcb8eaed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f03bec4e90ae00a3da243db950cf9874990c80fd0bdafc83f97e7e5f1770db8e1b4c3a80af77f70822214e88fadff79c11e056d521ef03c2dddf41222c9ae89
|
7
|
+
data.tar.gz: c79774e3e1d78c1ccc8f0ca5f5765b8ee632ab929d260f36353cafaffdb4289955e3bc81fec7e77b9fc7e2513091772612166d79787cc33743d8f8d409c83cf6
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Pork 1.3.0 -- 2015-05-24
|
4
|
+
|
5
|
+
### Incompatible changes
|
6
|
+
|
7
|
+
* `Pork.run` is renamed to `Pork.execute`,
|
8
|
+
and `Pork.run` would now do a full run.
|
9
|
+
|
10
|
+
* `Pork::Executor.all_tests` would also include paths to describe blocks.
|
11
|
+
|
12
|
+
### Enhancement
|
13
|
+
|
14
|
+
* Now `describe` could also take a second argument to specify groups.
|
15
|
+
* `PORK_TEST` could also accept a file path and line number pointing to a
|
16
|
+
describe block. Previously only would block would work.
|
17
|
+
|
18
|
+
### Bugs fixed
|
19
|
+
|
20
|
+
* `Pork.show_source` would never raise SyntaxError anymore.
|
21
|
+
|
3
22
|
## Pork 1.2.4 -- 2015-04-25
|
4
23
|
|
5
24
|
### Enhancement
|
data/README.md
CHANGED
@@ -801,28 +801,30 @@ run.
|
|
801
801
|
#### `env PORK_TEST=` with `:groups`
|
802
802
|
|
803
803
|
`PORK_TEST` could also take a list of groups. Groups are defined in the tests,
|
804
|
-
as the second argument to `would`. Take this as an example:
|
804
|
+
as the second argument to `describe` and `would`. Take this as an example:
|
805
805
|
|
806
806
|
|
807
807
|
``` ruby
|
808
|
-
|
809
|
-
|
810
|
-
|
808
|
+
describe 'all', :groups => [:all] do
|
809
|
+
would 'pass', :groups => [:core, :more] do
|
810
|
+
ok
|
811
|
+
end
|
811
812
|
|
812
|
-
would 'also pass', :groups => [:more] do
|
813
|
-
|
813
|
+
would 'also pass', :groups => [:more] do
|
814
|
+
ok
|
815
|
+
end
|
814
816
|
end
|
815
817
|
```
|
816
818
|
|
817
|
-
Then if specifying `PORK_TEST=more`, then both tests
|
818
|
-
`PORK_TEST=core`, then only the first would run.
|
819
|
-
multiple groups, separated with commas (,), like
|
820
|
-
then of course both tests would run.
|
819
|
+
Then if specifying `PORK_TEST=all`, or `PORK_TEST=more`, then both tests
|
820
|
+
would run. If specifying `PORK_TEST=core`, then only the first would run.
|
821
|
+
We could also specifying multiple groups, separated with commas (,), like
|
822
|
+
`PORK_TEST=core,more`, then of course both tests would run.
|
821
823
|
|
822
824
|
This would be very useful when you want to run a specific test case without
|
823
825
|
typing the whole file path and finding the line number. Just edit your test
|
824
|
-
source by adding some temporary group like `:groups => [:
|
825
|
-
run the test command prefixed by `env PORK_TEST=
|
826
|
+
source by adding some temporary group like `:groups => [:only]` and then
|
827
|
+
run the test command prefixed by `env PORK_TEST=only` then you're done.
|
826
828
|
You could just remove the group after debugging. This must be much easier to
|
827
829
|
do then commenting out a bunch of random codes in the tests.
|
828
830
|
|
data/lib/pork.rb
CHANGED
@@ -47,30 +47,37 @@ module Pork
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.
|
50
|
+
def self.execute
|
51
51
|
Random.srand(ENV['PORK_SEED'].to_i) if ENV['PORK_SEED']
|
52
52
|
seed
|
53
53
|
if ENV['PORK_TEST']
|
54
54
|
require 'pork/mode/shuffled'
|
55
|
-
if
|
56
|
-
|
55
|
+
if tests = Executor[ENV['PORK_TEST']]
|
56
|
+
paths, imps =
|
57
|
+
tests.group_by{ |p| p.kind_of?(Array) }.values_at(true, false)
|
58
|
+
@stat = Executor.execute(execute_mode, stat, paths) if paths
|
59
|
+
@stat = imps.inject(stat){ |s, i| i.execute(execute_mode, s) } if imps
|
57
60
|
else
|
58
61
|
puts "Cannot find test: #{ENV['PORK_TEST']}"
|
59
62
|
exit 254
|
60
63
|
end
|
61
64
|
else
|
62
|
-
@stat = Executor.execute(
|
65
|
+
@stat = Executor.execute(execute_mode, stat)
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
69
|
+
def self.run
|
70
|
+
execute_mode(ENV['PORK_MODE'])
|
71
|
+
trap
|
72
|
+
execute
|
73
|
+
stat.report
|
74
|
+
end
|
75
|
+
|
66
76
|
def self.autorun auto=true
|
67
77
|
@auto = auto
|
68
78
|
@autorun ||= at_exit do
|
69
79
|
next unless @auto
|
70
|
-
execute_mode(ENV['PORK_MODE'])
|
71
|
-
trap
|
72
80
|
run
|
73
|
-
stat.report
|
74
81
|
exit stat.failures + stat.errors + ($! && 1).to_i
|
75
82
|
end
|
76
83
|
end
|
data/lib/pork/imp.rb
CHANGED
@@ -18,14 +18,14 @@ module Pork
|
|
18
18
|
module_exec(*args, &search_stash(desc))
|
19
19
|
end
|
20
20
|
|
21
|
-
def describe desc=:default, &suite
|
21
|
+
def describe desc=:default, opts={}, &suite
|
22
22
|
executor = Class.new(self){ init("#{desc}: ") }
|
23
23
|
executor.module_eval(&suite)
|
24
|
-
@tests << [:describe, executor]
|
24
|
+
@tests << [:describe, executor, suite || lambda{}, opts]
|
25
25
|
end
|
26
26
|
|
27
27
|
def would desc=:default, opts={}, &test
|
28
|
-
@tests << [:would, desc, test
|
28
|
+
@tests << [:would , desc , test || lambda{}, opts]
|
29
29
|
end
|
30
30
|
|
31
31
|
def execute mode, *args
|
data/lib/pork/mode/shuffled.rb
CHANGED
@@ -8,7 +8,8 @@ module Pork
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def all_paths
|
11
|
-
(all_tests[:files] || {}).values.flat_map(&:values).flatten(1)
|
11
|
+
(all_tests[:files] || {}).values.flat_map(&:values).flatten(1).
|
12
|
+
select{ |path| path.kind_of?(Array) }
|
12
13
|
end
|
13
14
|
|
14
15
|
def [] index
|
@@ -69,28 +70,32 @@ module Pork
|
|
69
70
|
((type, imp, test, opts),
|
70
71
|
index)|
|
71
72
|
current = path + [index]
|
72
|
-
case type
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
path_or_imp = case type
|
74
|
+
when :describe
|
75
|
+
imp
|
76
|
+
when :would
|
77
|
+
current
|
78
|
+
else
|
79
|
+
next r
|
80
|
+
end
|
81
|
+
groups = opts[:groups]
|
82
|
+
store_for_groups(r, path_or_imp, groups) if groups
|
83
|
+
store_for_source(r, path_or_imp, *test.source_location)
|
84
|
+
imp.build_all_tests(r, current) if type == :describe
|
80
85
|
r
|
81
86
|
end
|
82
87
|
end
|
83
88
|
|
84
|
-
def store_for_groups tests,
|
89
|
+
def store_for_groups tests, path_or_imp, groups
|
85
90
|
r = tests[:groups] ||= {}
|
86
91
|
groups.each do |g|
|
87
|
-
(r[g.to_s] ||= []) <<
|
92
|
+
(r[g.to_s] ||= []) << path_or_imp
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
|
-
def store_for_source tests,
|
96
|
+
def store_for_source tests, path_or_imp, file, line
|
92
97
|
r = tests[:files] ||= {}
|
93
|
-
((r[File.expand_path(file)] ||= {})[line] ||= []) <<
|
98
|
+
((r[File.expand_path(file)] ||= {})[line] ||= []) << path_or_imp
|
94
99
|
end
|
95
100
|
end
|
96
101
|
|
data/lib/pork/test.rb
CHANGED
@@ -8,10 +8,10 @@ at_exit do
|
|
8
8
|
Pork.module_eval do
|
9
9
|
execute_mode(ENV['PORK_MODE'])
|
10
10
|
trap
|
11
|
-
|
11
|
+
execute
|
12
12
|
%w[sequential shuffled parallel].each do |mode|
|
13
13
|
execute_mode(mode)
|
14
|
-
|
14
|
+
execute
|
15
15
|
end
|
16
16
|
stat.report
|
17
17
|
exit stat.failures + stat.errors + ($! && 1).to_i
|
data/lib/pork/version.rb
CHANGED
data/pork.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: pork 1.
|
2
|
+
# stub: pork 1.3.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "pork"
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.3.0"
|
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-05-24"
|
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 = [
|
@@ -54,7 +54,7 @@ Gem::Specification.new do |s|
|
|
54
54
|
"test/test_stat.rb"]
|
55
55
|
s.homepage = "https://github.com/godfat/pork"
|
56
56
|
s.licenses = ["Apache License 2.0"]
|
57
|
-
s.rubygems_version = "2.4.
|
57
|
+
s.rubygems_version = "2.4.7"
|
58
58
|
s.summary = "Pork -- Simple and clean and modular testing library."
|
59
59
|
s.test_files = [
|
60
60
|
"test/test_bacon.rb",
|
data/test/test_pork_test.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require 'pork/test'
|
3
3
|
|
4
4
|
describe 'PORK_TEST=a' do
|
5
|
-
def verify line, executor, index
|
6
|
-
path = executor[index]
|
5
|
+
def verify line, executor, index, offset=0
|
6
|
+
path = executor[index][offset]
|
7
7
|
type, desc, block, opts = extract(path, executor)
|
8
8
|
expect(type) .eq :would
|
9
9
|
expect(desc) .eq 'find the corresponding test case'
|
@@ -23,24 +23,30 @@ describe 'PORK_TEST=a' do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def woulds
|
27
|
+
@woulds ||= Pork::Executor[__FILE__].select{ |p| p.kind_of?(Array) }
|
28
|
+
end
|
29
|
+
|
26
30
|
would 'find the corresponding test case', :groups => [:a, :b] do
|
27
31
|
line = __LINE__ - 1
|
28
|
-
[self.class, Pork::Executor].each do |executor|
|
32
|
+
[self.class, Pork::Executor].each.with_index do |executor, index|
|
29
33
|
verify(line, executor, "#{__FILE__}:#{__LINE__}") # line
|
30
34
|
verify(line, executor, 'a') # group
|
31
35
|
verify(line, executor, "#{__FILE__}:#{__LINE__}") # diff line
|
32
|
-
verify(line, executor, __FILE__)
|
36
|
+
verify(line, executor, __FILE__, index) # file
|
37
|
+
# for self.class, would is the 1st, for Pork::Executor, would is 2nd
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
describe 'PORK_TEST=b' do
|
37
42
|
would 'find both', :groups => [:b] do
|
38
43
|
line = __LINE__ - 1
|
39
|
-
Pork::Executor[__FILE__].size.should.eq
|
44
|
+
Pork::Executor[__FILE__].size.should.eq 6 # 3 describe
|
45
|
+
woulds .size.should.eq 3
|
40
46
|
Pork::Executor['a'] .size.should.eq 1
|
41
47
|
Pork::Executor['b'] .size.should.eq 2
|
42
|
-
Pork::Executor['b'] .should.eq
|
43
|
-
Pork::Executor['a,b'] .should.eq
|
48
|
+
Pork::Executor['b'] .should.eq woulds.first(2)
|
49
|
+
Pork::Executor['a,b'] .should.eq woulds.first(2)
|
44
50
|
self.class['a'] .should.nil?
|
45
51
|
self.class['b'] .size.should.eq 1
|
46
52
|
|
@@ -54,4 +60,14 @@ describe 'PORK_TEST=a' do
|
|
54
60
|
expect(b[3]) .eq :groups => [:b]
|
55
61
|
end
|
56
62
|
end
|
63
|
+
|
64
|
+
describe 'PORK_TEST=c', :groups => [:c] do
|
65
|
+
would 'inherit groups from describe', :groups => [:d] do
|
66
|
+
line = __LINE__ - 2
|
67
|
+
c = Pork::Executor['c']
|
68
|
+
expect(c.size ) .eq 1
|
69
|
+
expect(c.first) .eq self.class
|
70
|
+
expect(Pork::Executor["#{__FILE__}:#{line}"]).eq [self.class]
|
71
|
+
end
|
72
|
+
end
|
57
73
|
end
|
data/test/test_stat.rb
CHANGED
@@ -7,9 +7,22 @@ describe Pork::Stat do
|
|
7
7
|
@executor = Class.new(Pork::Executor){init}
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def skip_if_backtrace_is_wrong
|
11
|
+
0.should == {
|
12
|
+
}
|
13
|
+
rescue Pork::Failure => e
|
14
|
+
skip unless e.respond_to?(:backtrace_locations)
|
15
|
+
File.open(__FILE__) do |f|
|
16
|
+
line = e.backtrace_locations.find{ |l|
|
17
|
+
l.label.include?('skip_if_backtrace_is_wrong')
|
18
|
+
}.lineno.times.inject(''){ f.readline }
|
19
|
+
skip if line.include?('}')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run check=:expect_one_error
|
11
24
|
@stat = @executor.execute(Pork.execute_mode, Pork::Stat.new(StringIO.new))
|
12
|
-
|
25
|
+
send(check)
|
13
26
|
end
|
14
27
|
|
15
28
|
def expect_one_error
|
@@ -19,6 +32,13 @@ describe Pork::Stat do
|
|
19
32
|
expect(@stat.errors) .eq 1
|
20
33
|
end
|
21
34
|
|
35
|
+
def expect_one_failure
|
36
|
+
expect(@stat.io.string) .eq "\e[35mF\e[0m"
|
37
|
+
expect(@stat.tests) .eq 1
|
38
|
+
expect(@stat.assertions).eq 0
|
39
|
+
expect(@stat.failures) .eq 1
|
40
|
+
end
|
41
|
+
|
22
42
|
would 'always have backtrace' do
|
23
43
|
@executor.would
|
24
44
|
run
|
@@ -30,8 +50,8 @@ describe Pork::Stat do
|
|
30
50
|
end
|
31
51
|
|
32
52
|
describe 'Pork::Stat#show_source' do
|
33
|
-
def verify source
|
34
|
-
run
|
53
|
+
def verify source, check=:expect_one_error
|
54
|
+
run(check)
|
35
55
|
err, _, test = @stat.exceptions.first
|
36
56
|
yield(err) if block_given?
|
37
57
|
expect(@stat.send(:show_source, test, err)).include?(source)
|
@@ -66,6 +86,24 @@ describe Pork::Stat do
|
|
66
86
|
SOURCE
|
67
87
|
end
|
68
88
|
|
89
|
+
would 'multiple lines with == {}' do
|
90
|
+
skip_if_backtrace_is_wrong
|
91
|
+
@executor.would do
|
92
|
+
0.should == {
|
93
|
+
|
94
|
+
|
95
|
+
}
|
96
|
+
end
|
97
|
+
verify(<<-SOURCE.chomp, :expect_one_failure)
|
98
|
+
@executor.would do
|
99
|
+
\e[41m => 0.should == {\e[0m
|
100
|
+
\e[41m => \e[0m
|
101
|
+
\e[41m => \e[0m
|
102
|
+
\e[41m => }\e[0m
|
103
|
+
end
|
104
|
+
SOURCE
|
105
|
+
end
|
106
|
+
|
69
107
|
would 'show the line in the test, not other methods' do
|
70
108
|
@executor.send(:define_method, :f){ flunk }
|
71
109
|
@executor.would do
|
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.
|
4
|
+
version: 1.3.0
|
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-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: method_source
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.4.
|
99
|
+
rubygems_version: 2.4.7
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Pork -- Simple and clean and modular testing library.
|