pork 1.5.0 → 2.1.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.
@@ -0,0 +1,64 @@
1
+
2
+ require 'pork/test'
3
+
4
+ describe 'using fibers to simulate around' do
5
+ def a
6
+ @a ||= []
7
+ end
8
+
9
+ def around_me i
10
+ a << "around before #{i}"
11
+ yield
12
+ a << "around after #{i}"
13
+ end
14
+
15
+ before do
16
+ a << :before
17
+ end
18
+
19
+ after do
20
+ expect(a).eq [:before, "around before 0", :nocall, "around before 1",
21
+ :would, :after, "around after 1", "around after 0"]
22
+ end
23
+
24
+ around do |test|
25
+ expect(a).eq [:before]
26
+
27
+ around_me(0) do
28
+ test.call
29
+
30
+ expect(a).eq [:before, "around before 0", :nocall, "around before 1",
31
+ :would, :after, "around after 1"]
32
+ end
33
+ end
34
+
35
+ around do
36
+ expect(a).eq [:before, "around before 0"]
37
+
38
+ a << :nocall
39
+ end
40
+
41
+ around do |test|
42
+ expect(a).eq [:before, "around before 0", :nocall]
43
+
44
+ around_me(1) do
45
+ test.call
46
+
47
+ expect(a).eq [:before, "around before 0", :nocall, "around before 1",
48
+ :would, :after]
49
+ end
50
+ end
51
+
52
+ after do
53
+ expect(a).eq [:before, "around before 0", :nocall, "around before 1",
54
+ :would]
55
+
56
+ a << :after
57
+ end
58
+
59
+ would 'wrap around around' do
60
+ expect(a).eq [:before, "around before 0", :nocall, "around before 1"]
61
+
62
+ a << :would
63
+ end
64
+ end
data/test/test_bacon.rb CHANGED
@@ -236,13 +236,14 @@ describe "before/after" do
236
236
  @a = 2
237
237
  end
238
238
 
239
+ # after should run in reverse order
239
240
  after do
240
- @a.should.eq 2
241
- @a = 3
241
+ @a.should.eq 3
242
242
  end
243
243
 
244
244
  after do
245
- @a.should.eq 3
245
+ @a.should.eq 2
246
+ @a = 3
246
247
  end
247
248
 
248
249
  would "run in the right order" do
@@ -343,7 +344,7 @@ end
343
344
 
344
345
  describe 'describe arguments' do
345
346
  check = lambda do |ctx, desc, name=nil|
346
- ctx.should.lt Pork::Executor
347
+ ctx.should.lt Pork::Suite
347
348
  ctx.description_for(name).should.eq "#{desc}: #{name}"
348
349
  end
349
350
 
@@ -372,8 +373,8 @@ describe 'describe arguments' do
372
373
  end
373
374
 
374
375
  would 'work with namespaced modules' do
375
- str = 'Pork::Executor'
376
- Pork::API.describe(Pork::Executor) do
376
+ str = 'Pork::Suite'
377
+ Pork::API.describe(Pork::Suite) do
377
378
  check[self, str]
378
379
  would 'd' do check[self.class, str, 'd'] end
379
380
  end
@@ -0,0 +1,29 @@
1
+
2
+ require 'pork/test'
3
+
4
+ describe Pork::Isolator do
5
+ before do
6
+ @suite = Class.new(Pork::Suite){init}
7
+ end
8
+
9
+ describe '.all_tests' do
10
+ would 'have the correct source order' do
11
+ @suite.copy :append do
12
+ would{}
13
+ end
14
+
15
+ @suite.describe do
16
+ describe do
17
+ would{}
18
+ end
19
+
20
+ paste :append
21
+ end
22
+
23
+ Pork::Isolator[@suite].
24
+ all_tests[:files].values.map(&:keys).each do |lines|
25
+ expect(lines).eq lines.sort
26
+ end
27
+ end
28
+ end
29
+ end
data/test/test_meta.rb ADDED
@@ -0,0 +1,40 @@
1
+
2
+ require 'pork/test'
3
+
4
+ describe 'meta' do
5
+ before do
6
+ @stat = Pork::Stat.new(Pork.report_class.new(StringIO.new))
7
+ @suite = Class.new(Pork::Suite){init}
8
+ end
9
+
10
+ def execute
11
+ Pork::Executor.execute(:suite => @suite, :stat => @stat)
12
+ end
13
+
14
+ would 'raise missing assertion' do
15
+ @suite.would{}
16
+ @suite.after{ok} # defined after would so no run for that
17
+ stat = execute
18
+ err, _, _ = stat.exceptions.first
19
+
20
+ expect(err).kind_of?(Pork::Error)
21
+ expect(err.message).eq 'Missing assertions'
22
+ end
23
+
24
+ would 'not raise missing assertion if there is one in after block' do
25
+ @suite.after{ok}
26
+ @suite.would{}
27
+ stat = execute
28
+
29
+ expect(stat.exceptions).empty?
30
+ end
31
+
32
+ would 'run after block even if there is an error in test' do
33
+ called = false
34
+ @suite.after{ called = true }
35
+ @suite.would{ flunk }
36
+ execute
37
+
38
+ expect(called).eq true
39
+ end
40
+ end
data/test/test_nested.rb CHANGED
@@ -14,7 +14,7 @@ describe 'A' do
14
14
 
15
15
  would 'f' do
16
16
  f.should.eq m
17
- f.should.kind_of? Fixnum
17
+ f.should.kind_of? Integer
18
18
  lambda{ f.should.eq '' }.should.raise Pork::Failure
19
19
  end
20
20
 
@@ -78,3 +78,26 @@ describe Pork::Context do
78
78
  expect(pork_description).eq desc
79
79
  end
80
80
  end
81
+
82
+ describe 'assertion in after block' do
83
+ after do
84
+ ok
85
+ end
86
+
87
+ would do
88
+ end
89
+ end
90
+
91
+ describe 'no before/after after would' do
92
+ would do
93
+ ok
94
+ end
95
+
96
+ before do
97
+ flunk
98
+ end
99
+
100
+ after do
101
+ flunk
102
+ end
103
+ end
@@ -2,21 +2,21 @@
2
2
  require 'pork/test'
3
3
 
4
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)
5
+ def verify line, suite, index
6
+ path = Pork::Isolator[suite][index].first
7
+ type, desc, block, opts = extract(path, suite)
8
8
  expect(type) .eq :would
9
9
  expect(desc) .eq 'find the corresponding test case'
10
10
  expect(block.source_location).eq [__FILE__, line]
11
11
  expect(opts) .eq :groups => [:a, :b]
12
12
  end
13
13
 
14
- def extract path, executor
15
- path.inject(executor.instance_variable_get(:@tests)) do |tests, idx|
14
+ def extract path, suite
15
+ path.inject(suite.tests) do |tests, idx|
16
16
  type, arg, = tests[idx]
17
17
  case type
18
18
  when :describe # we need to go deeper
19
- arg.instance_variable_get(:@tests)
19
+ arg.tests
20
20
  else
21
21
  tests[idx] # should end here
22
22
  end
@@ -25,11 +25,11 @@ describe 'PORK_TEST=a' do
25
25
 
26
26
  would 'find the corresponding test case', :groups => [:a, :b] do
27
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
28
+ [self.class, Pork::Suite].each do |suite|
29
+ verify(line, suite, "#{__FILE__}:#{__LINE__}") # line
30
+ verify(line, suite, 'a') # group
31
+ verify(line, suite, "#{__FILE__}:#{__LINE__}") # diff line
32
+ verify(line, suite, __FILE__) # file
33
33
  # for self.class, would is the 1st, for Pork::Executor, would is 2nd
34
34
  end
35
35
  end
@@ -37,16 +37,18 @@ describe 'PORK_TEST=a' do
37
37
  describe 'PORK_TEST=b' do
38
38
  would 'find both', :groups => [:b] do
39
39
  line = __LINE__ - 1
40
- woulds = Pork::Executor[__FILE__]
41
- woulds .size.should.eq 4
42
- Pork::Executor['a'] .size.should.eq 1
43
- Pork::Executor['b'] .size.should.eq 2
44
- Pork::Executor['b'] .should.eq woulds.first(2)
45
- Pork::Executor['a,b'] .should.eq woulds.first(2)
46
- self.class['a'] .should.nil?
47
- self.class['b'] .size.should.eq 1
40
+ top = Pork::Isolator[]
41
+ woulds = top[__FILE__]
42
+ woulds .size.should.eq 4
43
+ top['a'] .size.should.eq 1
44
+ top['b'] .size.should.eq 2
45
+ top['b'] .should.eq woulds.first(2)
46
+ top['a,b'] .should.eq woulds.first(2)
47
+ local = Pork::Isolator[self.class]
48
+ local['a'] .should.nil?
49
+ local['b'].size.should.eq 1
48
50
 
49
- a, b = Pork::Executor['b'].map{ |path| extract(path, Pork::Executor) }
51
+ a, b = top['b'].map{ |path| extract(path, Pork::Suite) }
50
52
  expect(a[0]) .eq :would
51
53
  expect(a[1]) .eq 'find the corresponding test case'
52
54
  expect(a[3]) .eq :groups => [:a, :b]
@@ -60,12 +62,13 @@ describe 'PORK_TEST=a' do
60
62
  describe 'PORK_TEST=c', :groups => [:c] do
61
63
  would 'inherit groups from describe', :groups => [:d] do
62
64
  line = __LINE__ - 2
63
- c = Pork::Executor['c']
64
- d = Pork::Executor['d']
65
- expect(c.size) .eq 2
66
- expect(d.size) .eq 1
67
- expect(c.first) .eq d.first
68
- expect(Pork::Executor["#{__FILE__}:#{line}"]).eq c
65
+ isolator = Pork::Isolator[]
66
+ c = isolator['c']
67
+ d = isolator['d']
68
+ expect(c.size) .eq 2
69
+ expect(d.size) .eq 1
70
+ expect(c.first) .eq d.first
71
+ expect(isolator["#{__FILE__}:#{line}"]).eq c
69
72
  end
70
73
 
71
74
  would 'dummy' do
data/test/test_readme.rb CHANGED
@@ -1,13 +1,17 @@
1
1
 
2
2
  require 'pork/test'
3
- require 'uri'
4
3
 
5
4
  describe 'README.md' do
6
5
  File.read("#{File.dirname(File.expand_path(__FILE__))}/../README.md").
7
6
  scan(%r{``` ruby\nrequire 'pork/auto'\n(.+?)\n```}m).
8
7
  each.with_index do |(code), index|
9
8
  would 'pass from README.md #%02d' % index do
10
- Module.new{ extend Pork::API; instance_eval(code) }
9
+ suite = Class.new(Pork::Suite) do
10
+ init
11
+ instance_eval(code)
12
+ end
13
+
14
+ Pork::Executor.execute(:suite => suite)
11
15
  ok
12
16
  end
13
17
  end
data/test/test_stat.rb CHANGED
@@ -4,7 +4,7 @@ require 'stringio'
4
4
 
5
5
  describe Pork::Stat do
6
6
  before do
7
- @executor = Class.new(Pork::Executor){init}
7
+ @suite = Class.new(Pork::Suite){init}
8
8
  end
9
9
 
10
10
  def skip_if_backtrace_is_wrong
@@ -23,7 +23,7 @@ describe Pork::Stat do
23
23
  def run check=:expect_one_error
24
24
  stat = Pork::Stat.new(Pork.report_class.new(StringIO.new))
25
25
  stat.protected_exceptions = pork_stat.protected_exceptions
26
- @stat = @executor.execute(Pork.execute_mode, stat)
26
+ @stat = Pork::Executor.execute(:suite => @suite, :stat => stat)
27
27
  send(check)
28
28
  end
29
29
 
@@ -42,17 +42,19 @@ describe Pork::Stat do
42
42
  end
43
43
 
44
44
  would 'rescue custom errors' do
45
- @executor.would{ raise WebMockError }
45
+ @suite.would{ raise WebMockError }
46
46
  run
47
47
  end
48
48
 
49
49
  would 'always have backtrace' do
50
- @executor.would
50
+ @suite.would{}
51
51
  run
52
52
 
53
53
  err, _, test = @stat.exceptions.first
54
54
  err.set_backtrace([])
55
55
 
56
+ expect(err).kind_of?(Pork::Error)
57
+ expect(err.message).eq 'Missing assertions'
56
58
  expect(@stat.reporter.send(:show_backtrace, test, err)).not.empty?
57
59
  end
58
60
 
@@ -65,28 +67,28 @@ describe Pork::Stat do
65
67
  end
66
68
 
67
69
  would 'one line' do
68
- @executor.would{ flunk }
69
- verify('=> @executor.would{ flunk }')
70
+ @suite.would{ flunk }
71
+ verify('=> @suite.would{ flunk }')
70
72
  end
71
73
 
72
74
  would 'more lines' do
73
- @executor.would do
75
+ @suite.would do
74
76
  flunk
75
77
  end
76
78
  verify(<<-SOURCE.chomp)
77
- @executor.would do
79
+ @suite.would do
78
80
  \e[41m => flunk\e[0m
79
81
  end
80
82
  SOURCE
81
83
  end
82
84
 
83
85
  would 'multiple lines' do
84
- @executor.would do
86
+ @suite.would do
85
87
  raise \
86
88
  'error'
87
89
  end
88
90
  verify(<<-SOURCE.chomp)
89
- @executor.would do
91
+ @suite.would do
90
92
  \e[41m => raise \\\e[0m
91
93
  \e[41m => 'error'\e[0m
92
94
  end
@@ -95,14 +97,14 @@ describe Pork::Stat do
95
97
 
96
98
  would 'multiple lines with == {}' do
97
99
  skip_if_backtrace_is_wrong
98
- @executor.would do
100
+ @suite.would do
99
101
  0.should == {
100
102
 
101
103
 
102
104
  }
103
105
  end
104
106
  verify(<<-SOURCE.chomp, :expect_one_failure)
105
- @executor.would do
107
+ @suite.would do
106
108
  \e[41m => 0.should == {\e[0m
107
109
  \e[41m => \e[0m
108
110
  \e[41m => \e[0m
@@ -112,20 +114,20 @@ describe Pork::Stat do
112
114
  end
113
115
 
114
116
  would 'show the line in the test, not other methods' do
115
- @executor.send(:define_method, :f){ flunk }
116
- @executor.would do
117
+ @suite.send(:define_method, :f){ flunk }
118
+ @suite.would do
117
119
  f
118
120
  end
119
121
  verify(<<-SOURCE.chomp)
120
- @executor.would do
122
+ @suite.would do
121
123
  \e[41m => f\e[0m
122
124
  end
123
125
  SOURCE
124
126
  end
125
127
 
126
128
  would 'show the line in the test, even if it is from 3rd party' do
127
- @executor.would{ flunk }
128
- verify("=> @executor.would{ flunk }") do |err|
129
+ @suite.would{ flunk }
130
+ verify("=> @suite.would{ flunk }") do |err|
129
131
  err.set_backtrace(err.backtrace.unshift("bad.rb:#{__LINE__}"))
130
132
  end
131
133
  end
@@ -0,0 +1,10 @@
1
+
2
+ require 'pork/test'
3
+
4
+ describe Pork::Suite do
5
+ def self.suite_method
6
+ would{ ok }
7
+ end
8
+
9
+ suite_method
10
+ 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.5.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-10 00:00:00.000000000 Z
11
+ date: 2022-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -51,8 +51,8 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - ".gitignore"
54
+ - ".gitlab-ci.yml"
54
55
  - ".gitmodules"
55
- - ".travis.yml"
56
56
  - CHANGES.md
57
57
  - Gemfile
58
58
  - LICENSE
@@ -60,6 +60,7 @@ files:
60
60
  - Rakefile
61
61
  - TODO.md
62
62
  - lib/pork.rb
63
+ - lib/pork/api.rb
63
64
  - lib/pork/auto.rb
64
65
  - lib/pork/context.rb
65
66
  - lib/pork/env.rb
@@ -68,9 +69,8 @@ files:
68
69
  - lib/pork/expect.rb
69
70
  - lib/pork/extra/rainbows.rb
70
71
  - lib/pork/extra/show_source.rb
71
- - lib/pork/imp.rb
72
72
  - lib/pork/inspect.rb
73
- - lib/pork/isolate.rb
73
+ - lib/pork/isolator.rb
74
74
  - lib/pork/mode/parallel.rb
75
75
  - lib/pork/mode/sequential.rb
76
76
  - lib/pork/mode/shuffled.rb
@@ -82,25 +82,31 @@ files:
82
82
  - lib/pork/report/description.rb
83
83
  - lib/pork/report/dot.rb
84
84
  - lib/pork/report/progressbar.rb
85
+ - lib/pork/runner.rb
85
86
  - lib/pork/stat.rb
87
+ - lib/pork/suite.rb
86
88
  - lib/pork/test.rb
87
89
  - lib/pork/version.rb
88
90
  - pork.gemspec
89
91
  - task/README.md
90
92
  - task/gemgem.rb
93
+ - test/test_around.rb
91
94
  - test/test_bacon.rb
92
95
  - test/test_expect.rb
93
96
  - test/test_inspect.rb
97
+ - test/test_isolator.rb
98
+ - test/test_meta.rb
94
99
  - test/test_nested.rb
95
100
  - test/test_pork_test.rb
96
101
  - test/test_readme.rb
97
102
  - test/test_should.rb
98
103
  - test/test_stat.rb
104
+ - test/test_suite.rb
99
105
  homepage: https://github.com/godfat/pork
100
106
  licenses:
101
- - Apache License 2.0
107
+ - Apache-2.0
102
108
  metadata: {}
103
- post_install_message:
109
+ post_install_message:
104
110
  rdoc_options: []
105
111
  require_paths:
106
112
  - lib
@@ -115,17 +121,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
121
  - !ruby/object:Gem::Version
116
122
  version: '0'
117
123
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.6.1
120
- signing_key:
124
+ rubygems_version: 3.4.1
125
+ signing_key:
121
126
  specification_version: 4
122
127
  summary: Pork -- Simple and clean and modular testing library.
123
128
  test_files:
129
+ - test/test_around.rb
124
130
  - test/test_bacon.rb
125
131
  - test/test_expect.rb
126
132
  - test/test_inspect.rb
133
+ - test/test_isolator.rb
134
+ - test/test_meta.rb
127
135
  - test/test_nested.rb
128
136
  - test/test_pork_test.rb
129
137
  - test/test_readme.rb
130
138
  - test/test_should.rb
131
139
  - test/test_stat.rb
140
+ - test/test_suite.rb
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.1
5
- - 2.2
6
- - 2.3.0
7
- - rbx
8
- - jruby-9
9
-
10
- before_install:
11
- - rvm get head
12
- - rvm reload
13
- - rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
14
- install: 'gem install bundler; bundle install --retry=3'
15
- script: 'ruby -r bundler/setup -S rake test'
data/lib/pork/imp.rb DELETED
@@ -1,88 +0,0 @@
1
-
2
- require 'pork/env'
3
- require 'pork/stat'
4
- require 'pork/error'
5
- require 'pork/expect'
6
-
7
- module Pork
8
- module Imp
9
- attr_reader :desc, :tests
10
-
11
- def before &block; @tests << [:before, block]; end
12
- def after &block; @tests << [:after , block]; end
13
-
14
- def copy desc=:default, &suite
15
- @stash[desc] = suite
16
- end
17
- def paste desc=:default, *args
18
- module_exec(*args, &search_stash(desc))
19
- end
20
-
21
- def describe desc=:default, opts={}, &suite
22
- executor = Class.new(self){ init("#{desc}: ") }
23
- executor.module_eval(&suite)
24
- @tests << [:describe, executor, suite || lambda{}, opts]
25
- end
26
-
27
- def would desc=:default, opts={}, &test
28
- @tests << [:would , desc , test || lambda{}, opts]
29
- end
30
-
31
- def execute mode, *args
32
- require "pork/mode/#{mode}"
33
- public_send(mode, *args)
34
- end
35
-
36
- private
37
- def init desc=''
38
- @desc, @tests, @stash = desc, [], {}
39
- @super_executor = ancestors[1..-1].find{ |a| a <= Executor }
40
- end
41
-
42
- def run stat, desc, test, env
43
- assertions = stat.assertions
44
- context = new(stat, desc)
45
- seed = Pork.reseed
46
- stat.reporter.case_start(context)
47
- run_protected(stat, desc, test, seed) do
48
- env.run_before(context)
49
- context.instance_eval(&test)
50
- raise Error.new('Missing assertions') if assertions == stat.assertions
51
- stat.reporter.case_pass
52
- end
53
- ensure
54
- stat.incr_tests
55
- run_protected(stat, desc, test, seed){ env.run_after(context) }
56
- stat.reporter.case_end
57
- end
58
-
59
- def run_protected stat, desc, test, seed
60
- yield
61
- rescue *stat.protected_exceptions => e
62
- case e
63
- when Skip
64
- stat.incr_skips
65
- stat.reporter.case_skip
66
- else
67
- err = [e, description_for("would #{desc}"), test, seed]
68
- case e
69
- when Failure
70
- stat.add_failure(err)
71
- stat.reporter.case_failed
72
- else
73
- stat.add_error(err)
74
- stat.reporter.case_errored
75
- end
76
- end
77
- end
78
-
79
- protected
80
- def search_stash desc
81
- @stash[desc] or @super_executor && @super_executor.search_stash(desc)
82
- end
83
-
84
- def description_for name=''
85
- "#{@super_executor && @super_executor.description_for}#{@desc}#{name}"
86
- end
87
- end
88
- end