maxitest 5.2.0 → 5.3.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
2
  SHA256:
3
- metadata.gz: 7e06cbb1ba436c88ea73dfd4b7dbb9120c6c792ca6567241f7f0021c47a3586c
4
- data.tar.gz: 83e7039de6f6a61edcde5832e1b2852fdc908602eff7f838a01bfa6cb7accfba
3
+ metadata.gz: 9061b66cde59aa2093b1b9b0261c18d5134e64790936084086bcf4dd6ef9f954
4
+ data.tar.gz: cca38bde23d12a34db6c54dbd0f783eb8b568555fcdfa81aa259aaca1020af3c
5
5
  SHA512:
6
- metadata.gz: d8004ce78125ad9cf96d3259a8924e92f18e45c4e53b7883ee112919b7124f21f417f0ab443cc36a09e85fa353f7949598ea09cf139fdae67ab0025c126d3314
7
- data.tar.gz: aa0e90f8862c314d23f9043d932b757208324ce0f18c7fdf8af3d8f577e616a4b6e025c8b4b2d5b5f34e103c9478321ad7fbf539e6073a0f030f5f854e4b251e
6
+ metadata.gz: 0303fec9b3ca3f7f6fe419576beb0ebf9185f9bcd9850d386308ad2781bfa004138c2c01d77e7496b6a3516c1b783a0c5a7f0d8efe2b82cd4fabc45ad0135541
7
+ data.tar.gz: 80e22f71856fce5b79cf8e26fcf60887fce07f6934b4923cd9e1a0e7ab25c297c72ab3c98c7a6e54d343a8d91c3863e0ce3555caccbdf635a0a20c51e62e596c
data/README.md CHANGED
@@ -22,6 +22,8 @@ Features
22
22
  - `pending { assert false }` is skip when it fails, but fails when it passes
23
23
  - implicit subject via `require 'maxitest/implicit_subject'`
24
24
  - `xit` to skip test (also does not call setup or teardown)
25
+ - `with_env` to change environment variables during test run
26
+ - `capture_stdout` and `capture_stderr` to capture stdout or stderr but not both (like `capture_io` does)
25
27
  - `require 'maxitest/timeout'` to make hanging tests fail after `Maxitest.timeout` seconds
26
28
  - `require 'maxitest/threads'` fail tests that leave extra threads running
27
29
  - `require 'maxitest/global_must'` (before autorun) disable deprecation on global `must_*` or [global_expectations](https://github.com/jeremyevans/minitest-global_expectations) gem
@@ -42,6 +44,11 @@ require "maxitest/autorun"
42
44
  ... normal tests ...
43
45
  ```
44
46
 
47
+ ### pending
48
+
49
+ - `pending "need to fix" do` to show why something is pending
50
+ - `pending "need to fix", if: ENV["CI"] do` to only skip on CI (if something is supposed to work locally)
51
+
45
52
  Development
46
53
  ===========
47
54
  - everything vendored into 1 gem to avoid dependency madness
@@ -6,6 +6,7 @@ require "maxitest/let_bang"
6
6
  require "maxitest/let_all"
7
7
  require "maxitest/hook_all"
8
8
  require "maxitest/pending"
9
+ require "maxitest/helpers"
9
10
  require "maxitest/xit"
10
11
  require "maxitest/static_class_order"
11
12
  require "maxitest/shorted_backtrace"
@@ -20,3 +21,8 @@ Minitest::Spec::DSL.send(:alias_method, :context, :describe)
20
21
  class << Minitest::Test
21
22
  alias_method :order_dependent!, :i_suck_and_my_tests_are_order_dependent!
22
23
  end
24
+
25
+ # do not show maxitest as causing errors, but the last line in the users code
26
+ old = MiniTest::BacktraceFilter::MT_RE
27
+ MiniTest::BacktraceFilter.send(:remove_const, :MT_RE)
28
+ MiniTest::BacktraceFilter::MT_RE = Regexp.union(old, %r%lib/maxitest%)
@@ -0,0 +1,54 @@
1
+ module Maxitest
2
+ module Helpers
3
+ module InstanceMethods
4
+ def with_env(env)
5
+ _synchronize do
6
+ old = ENV.to_h
7
+ env.each { |k, v| ENV[k.to_s] = v }
8
+ yield
9
+ ensure
10
+ ENV.replace old
11
+ end
12
+ end
13
+
14
+ # stripped down version of capture_io
15
+ def capture_stdout
16
+ _synchronize do
17
+ begin
18
+ captured_stdout = StringIO.new
19
+ orig_stdout = $stdout
20
+ $stdout = captured_stdout
21
+ yield
22
+ return captured_stdout.string
23
+ ensure
24
+ $stdout = orig_stdout
25
+ end
26
+ end
27
+ end
28
+
29
+ # stripped down version of capture_io
30
+ def capture_stderr
31
+ _synchronize do
32
+ begin
33
+ captured_stderr = StringIO.new
34
+ orig_stderr = $stderr
35
+ $stderr = captured_stderr
36
+ yield
37
+ return captured_stderr.string
38
+ ensure
39
+ $stderr = orig_stderr
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ module ClassMethods
46
+ def with_env(env)
47
+ around { |t| with_env(env, &t) }
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ Minitest::Test.send(:include, Maxitest::Helpers::InstanceMethods)
54
+ Minitest::Test.send(:extend, Maxitest::Helpers::ClassMethods)
@@ -1,16 +1,16 @@
1
1
  module Maxitest
2
2
  module Pending
3
- def pending(reason=nil)
4
- if block_given?
5
- begin
6
- yield
7
- rescue StandardError, Minitest::Assertion
8
- skip reason
9
- else
10
- raise "Fixed"
11
- end
3
+ def pending(reason=nil, **kwargs)
4
+ raise ArgumentError, "Need a block to execute" unless block_given?
5
+ raise ArgumentError, "Only :if option is supported" if (kwargs.keys | [:if] != [:if])
6
+ return yield if kwargs.fetch(:if, true) == false # allow user to for example mark test only pending on CI with `if: ENV["CI"]`
7
+
8
+ begin
9
+ yield # execute test
10
+ rescue StandardError, Minitest::Assertion
11
+ skip reason # test failed as expected
12
12
  else
13
- raise ArgumentError, "Need a block to execute"
13
+ flunk "Test is fixed, remove `pending`"
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Maxitest
2
- VERSION = "5.2.0"
2
+ VERSION = "5.3.0"
3
3
  end
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.2.0
4
+ version: 5.3.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-07-27 00:00:00.000000000 Z
11
+ date: 2023-10-09 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/helpers.rb
74
75
  - lib/maxitest/hook_all.rb
75
76
  - lib/maxitest/implicit_subject.rb
76
77
  - lib/maxitest/let_all.rb