pork 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 66af2258263479b7c9b46d32d87dab94300c86c7
4
- data.tar.gz: dd01950d9a7026886e35b48054c97c5f69f6e6fa
2
+ SHA256:
3
+ metadata.gz: 6ef62f89f8c80fddee9ebd8e670cfa8de340a312531d022a3e49510dc7dd218f
4
+ data.tar.gz: 1f3af07cdc623ec24ba294fc41409f958a7fb8c89961388d98915bc648dfb142
5
5
  SHA512:
6
- metadata.gz: '0584b1e173a3d0190b28ebfddba0475ff9e47e85d51081a8f5401f789f8ee1e7aa3cd1680efd58d0fd44d4e444fecc567fcec86ca13fa66eb6525baeeb29dd58'
7
- data.tar.gz: 5705b43ac037712e230b6249f41f1ff12a1347e23a1bdf84632603878910ecf6f9d9a2e9c9e1c0400ea953453a232874caadb5694c8577b6b3a9220b3f45ee16
6
+ metadata.gz: e8c95acab07773aa0fd2f629c41c7a08d50b747c44649a3981021c5f64d0bc08f58a1b2de3ac78c317c3519c692dff2c6f473f32fcf37d806f367e65bb5fac28
7
+ data.tar.gz: 7b24bb5ec0792941b51ed0b2f69b90f17465fd68401db9835b42ac17b8719ed3c2936a683c6aa22f6165f9d9b01c94d5f5e90329c55c83868d051f4883004910
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,40 @@
1
+
2
+ stages:
3
+ - test
4
+
5
+ .test:
6
+ stage: test
7
+ image: ruby:${RUBY_VERSION}-bullseye
8
+ variables:
9
+ GIT_DEPTH: "1"
10
+ GIT_SUBMODULE_STRATEGY: recursive
11
+ GIT_SUBMODULE_PATHS: task
12
+ RUBYOPT: --enable-frozen-string-literal
13
+ before_script:
14
+ - bundle install --retry=3
15
+ - unset CI # Coverage doesn't work well with frozen literal
16
+ script:
17
+ - ruby -vr bundler/setup -S rake test
18
+
19
+ ruby:3.0:
20
+ extends:
21
+ - .test
22
+ variables:
23
+ RUBY_VERSION: '3.0'
24
+
25
+ ruby:3.1:
26
+ extends:
27
+ - .test
28
+ variables:
29
+ RUBY_VERSION: '3.1'
30
+
31
+ ruby:3.2:
32
+ extends:
33
+ - .test
34
+ variables:
35
+ RUBY_VERSION: '3.2'
36
+
37
+ jruby:latest:
38
+ extends:
39
+ - .test
40
+ image: jruby:latest
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "task"]
2
2
  path = task
3
- url = git://github.com/godfat/gemgem.git
3
+ url = https://github.com/godfat/gemgem.git
data/CHANGES.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # CHANGES
2
2
 
3
+ ## Pork 2.1.0 -- 2022-12-28
4
+
5
+ ### Bugs fixed
6
+
7
+ * `Pork.show_source` can work under frozen literal string mode now.
8
+ * Fix picking the right test for the file line number from `ENV['PORK_TEST']`
9
+ (I totally forgot the details for this from 2017, but I think it should
10
+ make it more accurate anyway)
11
+ * Ruby 3.2 compatibility fix. (Removed the use of `Random::DEFAULT`)
12
+
13
+ ### Enhancement
14
+
15
+ * Introduced `Pork::API.around` which will pass the test object to the block,
16
+ and whenever the object is called with `call` it'll run the test. Note that
17
+ if `call` was never called, it'll act like `Pork::API.before` and the test
18
+ will still run unlike RSpec. To skip the test, call `skip` directly.
19
+
3
20
  ## Pork 2.0.0 -- 2016-09-10
4
21
 
5
22
  ### Incompatible changes
data/Gemfile CHANGED
@@ -7,7 +7,3 @@ gem 'rake'
7
7
 
8
8
  gem 'simplecov', :require => false if ENV['COV']
9
9
  gem 'coveralls', :require => false if ENV['CI']
10
-
11
- platform :rbx do
12
- gem 'rubysl-singleton' # used in rake
13
- end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Pork [![Build Status](https://secure.travis-ci.org/godfat/pork.png?branch=master)](http://travis-ci.org/godfat/pork) [![Coverage Status](https://coveralls.io/repos/godfat/pork/badge.png)](https://coveralls.io/r/godfat/pork) [![Join the chat at https://gitter.im/godfat/pork](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/pork)
1
+ # Pork [![Pipeline status](https://gitlab.com/godfat/pork/badges/master/pipeline.svg)](https://gitlab.com/godfat/pork/-/pipelines)
2
2
 
3
3
  by Lin Jen-Shin ([godfat](http://godfat.org))
4
4
 
@@ -7,6 +7,7 @@ by Lin Jen-Shin ([godfat](http://godfat.org))
7
7
  * [github](https://github.com/godfat/pork)
8
8
  * [rubygems](https://rubygems.org/gems/pork)
9
9
  * [rdoc](http://rdoc.info/github/godfat/pork)
10
+ * [issues](https://github.com/godfat/pork/issues) (feel free to ask for support)
10
11
 
11
12
  ## DESCRIPTION:
12
13
 
@@ -147,7 +148,7 @@ end
147
148
 
148
149
  ## REQUIREMENTS:
149
150
 
150
- * Tested with MRI (official CRuby), Rubinius and JRuby.
151
+ * Tested with MRI (official CRuby) and JRuby.
151
152
  * (Optional) [method_source][] if you would like to print the source for the
152
153
  failing tests.
153
154
  * (Optional) [ruby-progressbar][] if you like porgressbar for showing
@@ -662,6 +663,49 @@ describe do
662
663
  end
663
664
  ```
664
665
 
666
+ ### Pork::API.around
667
+
668
+ Each `around` block would be called before each `would` block (test case),
669
+ and whenever it's called, it can take an argument representing the `would`
670
+ block (test case). Whenever `call` is called on the test case, it will run.
671
+ Essentially it's wrapping around the `would` block.
672
+
673
+ Note that each nested `describe` would also run parents' `around` block,
674
+ following the same order of `before` (in order) and `after` (reverse order).
675
+
676
+ ``` ruby
677
+ require 'pork/auto'
678
+
679
+ describe do
680
+ around do |test|
681
+ @a = 0
682
+
683
+ test.call
684
+
685
+ @a.should.eq 2
686
+ end
687
+
688
+ describe do
689
+ around do |test|
690
+ @a.should.eq 0
691
+ @a += 1
692
+
693
+ test.call
694
+
695
+ @a.should.eq 1
696
+ @a += 1
697
+ end
698
+
699
+ would do
700
+ @a.should.eq 1
701
+ end
702
+ end
703
+ end
704
+ ```
705
+
706
+ Note that if `test.call` was never called, it'll just act like a `before`
707
+ block. All the tests will still run unlike RSpec.
708
+
665
709
  ### Pork::API.copy and Pork::API.paste
666
710
 
667
711
  It could be a bit confusing at first, but just think of `copy` as a way to
@@ -1068,9 +1112,9 @@ Have you seen Rainbows!?
1068
1112
 
1069
1113
  ## LICENSE:
1070
1114
 
1071
- Apache License 2.0
1115
+ Apache License 2.0 (Apache-2.0)
1072
1116
 
1073
- Copyright (c) 2014-2016, Lin Jen-Shin (godfat)
1117
+ Copyright (c) 2014-2022, Lin Jen-Shin (godfat)
1074
1118
 
1075
1119
  Licensed under the Apache License, Version 2.0 (the "License");
1076
1120
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,16 +1,17 @@
1
1
 
2
2
  begin
3
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
3
+ require "#{__dir__}/task/gemgem"
4
4
  rescue LoadError
5
- sh 'git submodule update --init'
5
+ sh 'git submodule update --init --recursive'
6
6
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
7
  end
8
8
 
9
- Gemgem.init(dir) do |s|
9
+ Gemgem.init(__dir__) do |s|
10
10
  require 'pork/version'
11
11
  s.name = 'pork'
12
12
  s.version = Pork::VERSION
13
+ s.files.delete('screenshot.png')
14
+
13
15
  %w[method_source ruby-progressbar].
14
16
  each(&s.method(:add_development_dependency))
15
- s.files.delete('screenshot.png')
16
17
  end
data/lib/pork/api.rb CHANGED
@@ -12,6 +12,10 @@ module Pork
12
12
  Suite.after(&block)
13
13
  end
14
14
 
15
+ def around &block
16
+ Suite.around(&block)
17
+ end
18
+
15
19
  def copy desc=:default, &block
16
20
  Suite.copy(desc, &block)
17
21
  end
@@ -3,12 +3,31 @@ require 'method_source'
3
3
 
4
4
  module Pork
5
5
  module ShowSource
6
+ module FrozenStringFix
7
+ def extract_first_expression(lines, consume=0, &block)
8
+ code = consume.zero? ? [] : lines.slice!(0..(consume - 1))
9
+
10
+ lines.each do |v|
11
+ code << v
12
+
13
+ result = block ? block.call(code.join) : code.join
14
+
15
+ if complete_expression?(result)
16
+ return result
17
+ end
18
+ end
19
+ raise SyntaxError, "unexpected $end"
20
+ end
21
+ end
22
+
23
+ MethodSource.extend(FrozenStringFix)
24
+
6
25
  def show_source test, err
7
26
  source = test.source
8
27
  sopath = "#{test.source_location.first}:"
9
28
  lowers = test.source_location.last
10
29
  uppers = lowers + source.size
11
- lineno = reject_pork(test, err).find do |backtrace|
30
+ lineno = reject_pork(test, err.backtrace).find do |backtrace|
12
31
  # find the line from the test source, exclude everything else
13
32
  next unless backtrace.start_with?(sopath)
14
33
  number = backtrace[/(?<=\.rb:)\d+/].to_i
@@ -28,7 +47,7 @@ module Pork
28
47
  end
29
48
  end.join
30
49
  "\n#{result.chomp}"
31
- rescue SyntaxError => e
50
+ rescue SyntaxError, MethodSource::SourceNotFoundError => e
32
51
  "\nPork bug: Cannot parse the source. Please report: #{e}"
33
52
  end
34
53
  end
data/lib/pork/isolator.rb CHANGED
@@ -68,38 +68,78 @@ module Pork
68
68
 
69
69
  def build_all_tests result={}, path=[]
70
70
  suite.tests.each_with_index.inject(result) do |
71
- r, ((type, imp, test, opts), index)|
71
+ tests, ((type, imp, block, opts), index)|
72
72
  current = path + [index]
73
73
 
74
+ case type
75
+ when :describe, :would
76
+ source_location = expand_source_location(block)
77
+ init_source_store_path(tests, source_location)
78
+ end
79
+
74
80
  case type
75
81
  when :describe
76
- Isolator[imp].build_all_tests(r, current) do |nested|
77
- store_path(r, nested, test, opts[:groups])
82
+ Isolator[imp].build_all_tests(tests, current) do |nested|
83
+ store_path(tests, nested, source_location, opts[:groups])
78
84
  end
79
85
  when :would
80
86
  yield(current) if block_given?
81
- store_path(r, current, test, opts[:groups])
87
+ store_path(tests, current, source_location, opts[:groups])
82
88
  end
83
89
 
84
- r
90
+ tests
85
91
  end
86
92
  end
87
93
 
88
- def store_path tests, path, test, groups
94
+ def expand_source_location block
95
+ file, line = block.source_location
96
+ [File.expand_path(file), line]
97
+ end
98
+
99
+ def init_source_store_path tests, source_location
100
+ source, line = source_location
101
+
102
+ root = tests[:files] ||= {}
103
+ map = root[source] ||= {}
104
+
105
+ # Most of the time, line is always getting larger because we're
106
+ # scanning from top to bottom, and we really need to make sure
107
+ # that the map is sorted because whenever we're looking up which
108
+ # test we want from a particular line, we want to find the closest
109
+ # block rounding up. See Isolator#by_source
110
+ # However, it's not always appending from top to bottom, because
111
+ # we might be adding more tests from Suite#paste, and the original
112
+ # test could be defined in the same file, on previous lines!
113
+ # Because of this, we really need to make sure the map is balanced.
114
+ # If we ever have ordered map in Ruby, we don't have to do this...
115
+ # See the test for Isolator.all_tests (test/test_isolator.rb)
116
+ balanced_append(map, line, [])
117
+ end
118
+
119
+ def store_path tests, path, source_location, groups
89
120
  store_for_groups(tests, path, groups) if groups
90
- store_for_source(tests, path, *test.source_location)
121
+ store_for_source(tests, path, source_location)
91
122
  end
92
123
 
93
124
  def store_for_groups tests, path, groups
94
- r = tests[:groups] ||= {}
125
+ map = tests[:groups] ||= {}
95
126
  groups.each do |g|
96
- (r[g.to_s] ||= []) << path
127
+ (map[g.to_s] ||= []) << path
97
128
  end
98
129
  end
99
130
 
100
- def store_for_source tests, path, file, line
101
- r = tests[:files] ||= {}
102
- ((r[File.expand_path(file)] ||= {})[line] ||= []) << path
131
+ def store_for_source tests, path, source_location
132
+ source, line = source_location
133
+
134
+ tests[:files][source][line] << path
135
+ end
136
+
137
+ def balanced_append map, key, value
138
+ last_key = map.reverse_each.first.first unless map.empty?
139
+
140
+ map[key] ||= []
141
+
142
+ map.replace(Hash[map.sort]) if last_key && key < last_key
103
143
  end
104
144
  end
105
145
  end
@@ -1,7 +1,9 @@
1
1
 
2
2
  module Kernel
3
3
  def should *args, &block
4
- stat = Thread.current.group.list.find{ |t| t[:pork_stat] }[:pork_stat]
4
+ stat = Thread.current.group.list.find do |t|
5
+ t.thread_variable_get(:pork_stat)
6
+ end.thread_variable_get(:pork_stat)
5
7
  Pork::Expect.new(stat, self, *args, &block)
6
8
  end
7
9
  end
@@ -11,12 +13,12 @@ module Pork
11
13
  def execute stat=Stat.new, *args
12
14
  thread = Thread.current
13
15
  original_group, group = thread.group, ThreadGroup.new
14
- original_stat = thread[:pork_stat]
16
+ original_stat = thread.thread_variable_get(:pork_stat)
15
17
  group.add(thread)
16
- thread[:pork_stat] = stat
18
+ thread.thread_variable_set(:pork_stat, stat)
17
19
  super(stat, *args)
18
20
  ensure
19
- thread[:pork_stat] = original_stat
21
+ thread.thread_variable_set(:pork_stat, original_stat)
20
22
  original_group.add(thread)
21
23
  end
22
24
  end
data/lib/pork/report.rb CHANGED
@@ -86,10 +86,16 @@ module Pork
86
86
  end
87
87
 
88
88
  def backtrace test, err
89
- if $VERBOSE
89
+ bt = if $VERBOSE
90
90
  err.backtrace
91
91
  else
92
- strip(reject_pork(test, err))
92
+ strip(reject_pork(test, err.backtrace))
93
+ end
94
+
95
+ if bt.empty?
96
+ ["#{test.source_location.join(':')}:in `block in would'"]
97
+ else
98
+ bt
93
99
  end
94
100
  end
95
101
 
@@ -113,13 +119,8 @@ module Pork
113
119
  "#{err.class}: #{err.message}"
114
120
  end
115
121
 
116
- def reject_pork test, err
117
- bt = err.backtrace.reject{ |l| l =~ %r{/lib/pork(/\w+)*\.rb:\d+} }
118
- if bt.empty?
119
- ["#{test.source_location.join(':')}:in `block in would'"]
120
- else
121
- bt
122
- end
122
+ def reject_pork test, bt
123
+ bt.reject{ |l| l =~ %r{/lib/pork(/\w+)*\.rb:\d+} }
123
124
  end
124
125
 
125
126
  def strip bt
@@ -127,11 +128,13 @@ module Pork
127
128
  end
128
129
 
129
130
  def strip_home bt
130
- bt.map{ |path| path.sub(ENV['HOME'], '~') }
131
+ home = ENV['HOME']
132
+ bt.map{ |path| path.sub(home, '~') }
131
133
  end
132
134
 
133
135
  def strip_cwd bt
134
- bt.map{ |path| path.sub("#{Dir.pwd}/", '') }
136
+ cwd = Dir.pwd
137
+ bt.map{ |path| path.sub("#{cwd}/", '') }
135
138
  end
136
139
 
137
140
  def pork_test source_location
data/lib/pork/runner.rb CHANGED
@@ -5,7 +5,7 @@ module Pork
5
5
  class Runner < Struct.new(:suite, :seed, :stat, :desc, :test, :env)
6
6
  def run
7
7
  assertions = stat.assertions
8
- context = suite.new(stat, desc)
8
+ context = suite.new(stat, desc, [])
9
9
 
10
10
  stat.reporter.case_start(context)
11
11
 
data/lib/pork/suite.rb CHANGED
@@ -1,15 +1,30 @@
1
1
 
2
+ require 'fiber'
3
+
2
4
  require 'pork/runner'
3
5
  require 'pork/context'
4
6
 
5
7
  module Pork
6
- class Suite < Struct.new(:pork_stat, :pork_description)
8
+ class Suite < Struct.new(:pork_stat, :pork_description, :pork_fibers)
7
9
  module Imp
8
10
  attr_reader :desc, :tests
9
11
 
10
12
  def before &block; @tests << [:before, block]; end
11
13
  def after &block; @tests << [:after , block]; end
12
14
 
15
+ def around &block
16
+ before do
17
+ fiber = Fiber.new{ instance_exec(Fiber.method(:yield), &block) }
18
+ pork_fibers << fiber
19
+ fiber.resume
20
+ end
21
+
22
+ after do
23
+ fiber = pork_fibers.pop
24
+ fiber.resume if fiber.alive?
25
+ end
26
+ end
27
+
13
28
  def copy desc=:default, &suite
14
29
  @stash[desc] = suite
15
30
  end
data/lib/pork/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Pork
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  end
data/lib/pork.rb CHANGED
@@ -46,11 +46,7 @@ module Pork
46
46
  end
47
47
 
48
48
  def self.seed
49
- @seed ||= if Random.const_defined?(:DEFAULT)
50
- Random::DEFAULT.seed
51
- else
52
- Thread.current.randomizer.seed # Rubinius (rbx)
53
- end
49
+ @seed ||= Random.seed
54
50
  end
55
51
 
56
52
  def self.reseed
data/pork.gemspec CHANGED
@@ -1,20 +1,20 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: pork 2.0.0 ruby lib
2
+ # stub: pork 2.1.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pork".freeze
6
- s.version = "2.0.0"
6
+ s.version = "2.1.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
- s.date = "2016-09-10"
11
+ s.date = "2022-12-28"
12
12
  s.description = "Pork -- Simple and clean and modular testing library.\n\nInspired by [Bacon][].\n\n[Bacon]: https://github.com/chneukirchen/bacon".freeze
13
13
  s.email = ["godfat (XD) godfat.org".freeze]
14
14
  s.files = [
15
15
  ".gitignore".freeze,
16
+ ".gitlab-ci.yml".freeze,
16
17
  ".gitmodules".freeze,
17
- ".travis.yml".freeze,
18
18
  "CHANGES.md".freeze,
19
19
  "Gemfile".freeze,
20
20
  "LICENSE".freeze,
@@ -52,42 +52,38 @@ Gem::Specification.new do |s|
52
52
  "pork.gemspec".freeze,
53
53
  "task/README.md".freeze,
54
54
  "task/gemgem.rb".freeze,
55
+ "test/test_around.rb".freeze,
55
56
  "test/test_bacon.rb".freeze,
56
57
  "test/test_expect.rb".freeze,
57
58
  "test/test_inspect.rb".freeze,
59
+ "test/test_isolator.rb".freeze,
58
60
  "test/test_meta.rb".freeze,
59
61
  "test/test_nested.rb".freeze,
60
62
  "test/test_pork_test.rb".freeze,
61
63
  "test/test_readme.rb".freeze,
62
64
  "test/test_should.rb".freeze,
63
- "test/test_stat.rb".freeze]
65
+ "test/test_stat.rb".freeze,
66
+ "test/test_suite.rb".freeze]
64
67
  s.homepage = "https://github.com/godfat/pork".freeze
65
- s.licenses = ["Apache License 2.0".freeze]
66
- s.rubygems_version = "2.6.6".freeze
68
+ s.licenses = ["Apache-2.0".freeze]
69
+ s.rubygems_version = "3.4.1".freeze
67
70
  s.summary = "Pork -- Simple and clean and modular testing library.".freeze
68
71
  s.test_files = [
72
+ "test/test_around.rb".freeze,
69
73
  "test/test_bacon.rb".freeze,
70
74
  "test/test_expect.rb".freeze,
71
75
  "test/test_inspect.rb".freeze,
76
+ "test/test_isolator.rb".freeze,
72
77
  "test/test_meta.rb".freeze,
73
78
  "test/test_nested.rb".freeze,
74
79
  "test/test_pork_test.rb".freeze,
75
80
  "test/test_readme.rb".freeze,
76
81
  "test/test_should.rb".freeze,
77
- "test/test_stat.rb".freeze]
82
+ "test/test_stat.rb".freeze,
83
+ "test/test_suite.rb".freeze]
78
84
 
79
- if s.respond_to? :specification_version then
80
- s.specification_version = 4
85
+ s.specification_version = 4
81
86
 
82
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
83
- s.add_development_dependency(%q<method_source>.freeze, [">= 0"])
84
- s.add_development_dependency(%q<ruby-progressbar>.freeze, [">= 0"])
85
- else
86
- s.add_dependency(%q<method_source>.freeze, [">= 0"])
87
- s.add_dependency(%q<ruby-progressbar>.freeze, [">= 0"])
88
- end
89
- else
90
- s.add_dependency(%q<method_source>.freeze, [">= 0"])
91
- s.add_dependency(%q<ruby-progressbar>.freeze, [">= 0"])
92
- end
87
+ s.add_development_dependency(%q<method_source>.freeze, [">= 0"])
88
+ s.add_development_dependency(%q<ruby-progressbar>.freeze, [">= 0"])
93
89
  end
data/task/README.md CHANGED
@@ -4,16 +4,16 @@
4
4
 
5
5
  Provided tasks:
6
6
 
7
- rake clean # Remove ignored files
7
+ rake clean # Trash ignored files
8
8
  rake gem:build # Build gem
9
9
  rake gem:install # Install gem
10
10
  rake gem:release # Release gem
11
11
  rake gem:spec # Generate gemspec
12
- rake test # Run tests in memory
12
+ rake test # Run tests
13
13
 
14
14
  ## REQUIREMENTS:
15
15
 
16
- * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
16
+ * Tested with MRI (official CRuby) and JRuby.
17
17
 
18
18
  ## INSTALLATION:
19
19
 
@@ -23,13 +23,13 @@ And in Rakefile:
23
23
 
24
24
  ``` ruby
25
25
  begin
26
- require "#{dir = File.dirname(__FILE__)}/task/gemgem"
26
+ require "#{__dir__}/task/gemgem"
27
27
  rescue LoadError
28
- sh 'git submodule update --init'
28
+ sh 'git submodule update --init --recursive'
29
29
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
30
  end
31
31
 
32
- Gemgem.init(dir) do |s|
32
+ Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
33
33
  s.name = 'your-gem'
34
34
  s.version = '0.1.0'
35
35
  end
@@ -37,9 +37,9 @@ end
37
37
 
38
38
  ## LICENSE:
39
39
 
40
- Apache License 2.0
40
+ Apache License 2.0 (Apache-2.0)
41
41
 
42
- Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
42
+ Copyright (c) 2011-2021, Lin Jen-Shin (godfat)
43
43
 
44
44
  Licensed under the Apache License, Version 2.0 (the "License");
45
45
  you may not use this file except in compliance with the License.
data/task/gemgem.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Gemgem
3
3
  class << self
4
- attr_accessor :dir, :spec, :spec_create
4
+ attr_accessor :dir, :spec, :submodules, :spec_create
5
5
  end
6
6
 
7
7
  module_function
@@ -11,12 +11,14 @@ module Gemgem
11
11
  def pkg_dir ; "#{dir}/pkg" ; end
12
12
  def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
13
 
14
- def init dir, &block
14
+ def init dir, options={}, &block
15
15
  self.dir = dir
16
- $LOAD_PATH.unshift("#{dir}/lib")
17
16
  ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
17
  ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
18
+ self.submodules = options[:submodules] || []
19
19
  self.spec_create = block
20
+
21
+ $LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
20
22
  end
21
23
 
22
24
  def create
@@ -26,7 +28,7 @@ module Gemgem
26
28
 
27
29
  s.description = description.join
28
30
  s.summary = description.first
29
- s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
31
+ s.license = license
30
32
 
31
33
  s.date = Time.now.strftime('%Y-%m-%d')
32
34
  s.files = gem_files
@@ -40,6 +42,7 @@ module Gemgem
40
42
 
41
43
  def gem_install
42
44
  require 'rubygems/commands/install_command'
45
+ require 'rubygems/package'
43
46
  # read ~/.gemrc
44
47
  Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
45
48
  Gem::Command.extra_args = Gem.configuration[:gem]
@@ -49,7 +52,8 @@ module Gemgem
49
52
  cmd.handle_options([])
50
53
 
51
54
  # install
52
- install = Gem::Installer.new(gem_path, cmd.options)
55
+ gem_package = Gem::Package.new(gem_path)
56
+ install = Gem::Installer.new(gem_package, cmd.options)
53
57
  install.install
54
58
  puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
55
59
  end
@@ -115,6 +119,7 @@ module Gemgem
115
119
  SimpleCov.start do
116
120
  add_filter('test/')
117
121
  add_filter('test.rb')
122
+ submodules_libs.each(&method(:add_filter))
118
123
  end
119
124
  end
120
125
 
@@ -159,11 +164,15 @@ module Gemgem
159
164
  end
160
165
 
161
166
  def strip_home_path path
162
- path.sub(ENV['HOME'], '~')
167
+ path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
163
168
  end
164
169
 
165
170
  def strip_cwd_path path
166
- path.sub(Dir.pwd, '.')
171
+ path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
172
+ end
173
+
174
+ def submodules_libs
175
+ submodules.map{ |path| "#{dir}/#{path}/lib" }
167
176
  end
168
177
 
169
178
  def git *args
@@ -201,6 +210,11 @@ module Gemgem
201
210
  @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
202
211
  end
203
212
 
213
+ def license
214
+ readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
215
+ split(/[()]/).map(&:strip).reject(&:empty?).last
216
+ end
217
+
204
218
  def all_files
205
219
  @all_files ||= fold_files(glob).sort
206
220
  end
@@ -221,7 +235,8 @@ module Gemgem
221
235
 
222
236
  def gem_files
223
237
  @gem_files ||= all_files.reject{ |f|
224
- f =~ ignored_pattern && !git_files.include?(f)
238
+ f =~ submodules_pattern ||
239
+ (f =~ ignored_pattern && !git_files.include?(f))
225
240
  }
226
241
  end
227
242
 
@@ -253,6 +268,15 @@ module Gemgem
253
268
  end
254
269
  end
255
270
 
271
+ def submodules_pattern
272
+ @submodules_pattern ||= if submodules.empty?
273
+ /^$/
274
+ else
275
+ Regexp.new(submodules.map{ |path|
276
+ "^#{Regexp.escape(path)}/" }.join('|'))
277
+ end
278
+ end
279
+
256
280
  def expand_patterns pathes
257
281
  # http://git-scm.com/docs/gitignore
258
282
  pathes.flat_map{ |path|
@@ -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
@@ -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_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
 
@@ -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: 2.0.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-09-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
@@ -90,20 +90,23 @@ files:
90
90
  - pork.gemspec
91
91
  - task/README.md
92
92
  - task/gemgem.rb
93
+ - test/test_around.rb
93
94
  - test/test_bacon.rb
94
95
  - test/test_expect.rb
95
96
  - test/test_inspect.rb
97
+ - test/test_isolator.rb
96
98
  - test/test_meta.rb
97
99
  - test/test_nested.rb
98
100
  - test/test_pork_test.rb
99
101
  - test/test_readme.rb
100
102
  - test/test_should.rb
101
103
  - test/test_stat.rb
104
+ - test/test_suite.rb
102
105
  homepage: https://github.com/godfat/pork
103
106
  licenses:
104
- - Apache License 2.0
107
+ - Apache-2.0
105
108
  metadata: {}
106
- post_install_message:
109
+ post_install_message:
107
110
  rdoc_options: []
108
111
  require_paths:
109
112
  - lib
@@ -118,18 +121,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
121
  - !ruby/object:Gem::Version
119
122
  version: '0'
120
123
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.6.6
123
- signing_key:
124
+ rubygems_version: 3.4.1
125
+ signing_key:
124
126
  specification_version: 4
125
127
  summary: Pork -- Simple and clean and modular testing library.
126
128
  test_files:
129
+ - test/test_around.rb
127
130
  - test/test_bacon.rb
128
131
  - test/test_expect.rb
129
132
  - test/test_inspect.rb
133
+ - test/test_isolator.rb
130
134
  - test/test_meta.rb
131
135
  - test/test_nested.rb
132
136
  - test/test_pork_test.rb
133
137
  - test/test_readme.rb
134
138
  - test/test_should.rb
135
139
  - test/test_stat.rb
140
+ - test/test_suite.rb
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.5
5
- - 2.3.1
6
- - rbx
7
- - jruby-9
8
-
9
- before_install:
10
- - rvm get head
11
- - rvm reload
12
- - rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
13
- install: 'gem install bundler; bundle install --retry=3'
14
- script: 'ruby -r bundler/setup -S rake test'