maxitest 5.0.0 → 5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19e93c5987b050a84f348f6ce96cfad62a5dc537ab22d36ff14429da227e4574
4
- data.tar.gz: 0f5f6db565378b594acc9e18bc2f202954324b98847d5bbbc635e4c4e3234a6b
3
+ metadata.gz: bf5d2aa58f3aff1492c20ee215eee1158a08d8cb5494c1549560ad19788c4b40
4
+ data.tar.gz: 711007c687350abbaf006f30bab9283846f8c33309717513dde02d7a1b078adb
5
5
  SHA512:
6
- metadata.gz: 8c4b6beacd1f6d0e6168278ff2a9df72620f8ca474612f573fac23785f507dd5129dac43846a8c98dddc181a14198c5d1463de16938dfc2af304905dfe2a290d
7
- data.tar.gz: 6257ee5847b0a6ed31acd716c26ad4b190b17176ef31e21475dd57f3c32aa139fba704f9f66c8299b68b2c5b2e7a2696de1e93de5486acf31e325b1a1f37511f
6
+ metadata.gz: ac882f4678a9f32b130de1ebe2c542c33909519b7ca334f072d9e1659af38873cef24051d714ef91ef9958f4b01c8dd39ccf89e0a920a0290e547337c6dcc981
7
+ data.tar.gz: c725d8a83554977d1b1e0b920db1f1540fffe5ee153e2ab9787632f03335d62e0010107630004917a2d0cbfc139c434087e7345d38b50095a48dfe8a82d632a3
data/README.md CHANGED
@@ -9,6 +9,7 @@ Features
9
9
  - **Ctrl+c** stops tests and prints failures
10
10
  - **pastable rerun snippet** for failures (disabled/integrated on rails 5)
11
11
  - multiple before & after blocks
12
+ - `before :all` blocks
12
13
  - **around** blocks `around { |t| Dir.chdir(...) { t.call } }`
13
14
  - **red-green** output (disabled/integrated on rails 5)
14
15
  - `mtest` executable to **run by line number** and by folder (disabled/integrated on rails 5)
@@ -47,7 +48,7 @@ Development
47
48
  - tested via rspec to avoid messing up our own tests by accident
48
49
  - fixes should go back to the original libraries
49
50
  - restrictive minitest dependency so nothing breaks by accident
50
- - ruby >=2.6
51
+ - ruby >=3.0
51
52
  - `rake bundle` to update all vendored gems
52
53
 
53
54
  Author
@@ -57,6 +58,6 @@ Author
57
58
  - mtest from [testrbl](https://github.com/grosser/testrbl)
58
59
  - red-green from [minitest-rg](https://github.com/blowmage/minitest-rg)
59
60
 
60
- [Michael Grosser](http://grosser.it)<br/>
61
- michael@grosser.it<br/>
62
- License: MIT<br/>
61
+ [Michael Grosser](http://grosser.it)<br>
62
+ michael@grosser.it<br>
63
+ License: MIT
@@ -4,6 +4,7 @@ require "maxitest/vendor/around"
4
4
  require "maxitest/trap"
5
5
  require "maxitest/let_bang"
6
6
  require "maxitest/let_all"
7
+ require "maxitest/hook_all"
7
8
  require "maxitest/pending"
8
9
  require "maxitest/xit"
9
10
  require "maxitest/static_class_order"
@@ -0,0 +1,29 @@
1
+ module Maxitest
2
+ class << self
3
+ attr_accessor :hook_all_counter
4
+ end
5
+ end
6
+ Maxitest.hook_all_counter = 0
7
+
8
+ module Maxitest
9
+ module HookAll
10
+ [:before, :after].each do |hook|
11
+ # minitest discards the type argument, so we are not sending it along
12
+ define_method(hook) do |type = :each, &block|
13
+ case type
14
+ when :each then super(&block)
15
+ when :all
16
+ raise ArgumentError, ":all is not supported in after" if hook == :after
17
+ c = (Maxitest.hook_all_counter += 1)
18
+ callback = :"maxitest_hook_all_#{c}"
19
+ let_all(callback, &block)
20
+ super() { send callback }
21
+ else
22
+ raise ArgumentError, "only :each and :all are supported"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Minitest::Spec::DSL.prepend(Maxitest::HookAll)
@@ -1,12 +1,19 @@
1
- Minitest::Spec::DSL.class_eval do
2
- def let_all(name, &block)
3
- cache = []
4
- define_method(name) do
5
- if cache.empty?
6
- cache[0] = instance_eval(&block)
7
- else
8
- cache[0]
1
+ module Maxitest
2
+ module LetAll
3
+ def let_all(name, &block)
4
+ cache = []
5
+ define_method(name) do
6
+ if cache.empty?
7
+ cache << instance_eval(&block)
8
+ end
9
+ cache.first
9
10
  end
10
11
  end
12
+
13
+ def self.included(base)
14
+ base.extend(self)
15
+ end
11
16
  end
12
17
  end
18
+
19
+ Minitest::Spec::DSL.include(Maxitest::LetAll)
data/lib/maxitest/trap.rb CHANGED
@@ -1,33 +1,33 @@
1
- Minitest::Test.class_eval do
2
- alias_method :capture_exceptions_without_stop, :capture_exceptions
3
- def capture_exceptions(&block)
4
- capture_exceptions_without_stop(&block)
5
- rescue Interrupt
6
- Maxitest.interrupted = true
7
- self.failures << Minitest::UnexpectedError.new($!)
8
- end
9
-
10
- alias_method :run_without_stop, :run
11
- def run
12
- if Maxitest.interrupted
13
- # only things with class `Minitest::Skip` get counted as skips
14
- # we need to raise and capture to get a skip with a backtrace
15
- skip = begin
16
- raise Minitest::Skip, "Maxitest::Interrupted"
17
- rescue Minitest::Skip
18
- $!
19
- end
20
- self.failures = [skip]
21
- defined?(Minitest::Result) ? Minitest::Result.from(self) : self
22
- else
23
- run_without_stop
24
- end
25
- end
26
- end
1
+ # frozen_string_literal: true
27
2
 
28
3
  module Maxitest
29
4
  Interrupted = Class.new(StandardError)
30
5
  class << self
31
6
  attr_accessor :interrupted
32
7
  end
8
+
9
+ module InterruptHandler
10
+ def capture_exceptions(&block)
11
+ super(&block)
12
+ rescue Interrupt => e
13
+ Maxitest.interrupted = true
14
+ failures << Minitest::UnexpectedError.new(e)
15
+ end
16
+
17
+ def run
18
+ if Maxitest.interrupted
19
+ skip = begin
20
+ raise Minitest::Skip, 'Maxitest::Interrupted'
21
+ rescue Minitest::Skip => e
22
+ e
23
+ end
24
+ self.failures = [skip]
25
+ defined?(Minitest::Result) ? Minitest::Result.from(self) : self
26
+ else
27
+ super()
28
+ end
29
+ end
30
+ end
33
31
  end
32
+
33
+ Minitest::Test.prepend(Maxitest::InterruptHandler)
@@ -57,6 +57,7 @@ Minitest::Spec::DSL.class_eval do
57
57
  # - execute test
58
58
  # - resume fiber to execute last part
59
59
  def around(*args, &block)
60
+ raise ArgumentError, "only :each or no argument is supported" if args != [] && args != [:each]
60
61
  fib = nil
61
62
  before do
62
63
  fib = Fiber.new do |context, resume|
@@ -1,3 +1,3 @@
1
1
  module Maxitest
2
- VERSION = "5.0.0"
2
+ VERSION = "5.1.0"
3
3
  end
data/lib/maxitest/xit.rb CHANGED
@@ -1,9 +1,19 @@
1
- Minitest::Spec::DSL.class_eval do
2
- def xit(*args, &block)
3
- describe "skip" do
4
- def setup; end
5
- def teardown; end
6
- it(*args)
1
+ # frozen_string_literal: true
2
+
3
+ module Maxitest
4
+ module XitMethod
5
+ def xit(*args)
6
+ describe 'skip' do
7
+ define_method(:setup) {}
8
+ define_method(:teardown) {}
9
+ it(*args)
10
+ end
11
+ end
12
+
13
+ def self.included(base)
14
+ base.extend(self)
7
15
  end
8
16
  end
9
17
  end
18
+
19
+ Minitest::Spec::DSL.include(Maxitest::XitMethod)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-08 00:00:00.000000000 Z
11
+ date: 2023-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -71,6 +71,7 @@ files:
71
71
  - lib/maxitest.rb
72
72
  - lib/maxitest/autorun.rb
73
73
  - lib/maxitest/global_must.rb
74
+ - lib/maxitest/hook_all.rb
74
75
  - lib/maxitest/implicit_subject.rb
75
76
  - lib/maxitest/let_all.rb
76
77
  - lib/maxitest/let_bang.rb