minitest-silence 0.1.0 → 0.2.4
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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README.md +14 -6
- data/lib/minitest/silence/version.rb +1 -1
- data/lib/minitest/silence_plugin.rb +24 -13
- data/minitest-silence.gemspec +1 -1
- metadata +4 -5
- data/Gemfile.lock +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba38e3bdb96751df36f3ea01b1e81cf30bd4d0a4368c251ea6e1ddae9b443b2e
|
4
|
+
data.tar.gz: 796edae9f0796115e6ae2695e1c7bde32d587013ce2ac4582f6466fa1151a382
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 324baca320f1db91b0e0a226034626d2fe280a3386c171412bdb6e48ad3a0450eb321304ae9af320f0e2e4163f80faf45b5fc9a821ed4b654fbdcde1aab927c1
|
7
|
+
data.tar.gz: 622f58efbca12b35eb445fccd5f22c2214fdf26536412d85b9b076cac7863e1a8e2bcbd8115ddd8064194762dcf8daa83b3fbb73a8db35e50948fffd30c359d2
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Minitest::Silence
|
2
2
|
|
3
|
-
Minitest plugin to
|
3
|
+
Minitest plugin to capture output to stdout and stderr from tests.
|
4
|
+
|
5
|
+
It's best practice for tests to not write anything to `STDOUT` or `STDERR` while running. Besides it being an implicit dependency, it interferes with the output from the test runner. Even though this is a best practice, when your test suite grows large enough, it becomes almost impossible to make sure every test conforms to this best practice.
|
6
|
+
|
7
|
+
This plugins aims to solve this problem by rebinding `STDOUT` and `STDERR` while a test is running. Any output written will be redirected to a pipe, so it won't interfere with the output of the test runner. The plugin will also bind `STDIN` to `/dev/null`. This codifies the best practice that automated tests should not depend on user input.
|
8
|
+
|
9
|
+
This plugin is inspired by [how the Python test runner handles output](https://docs.pytest.org/en/stable/capture.html).
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -12,11 +18,13 @@ gem 'minitest-silence', require: false
|
|
12
18
|
|
13
19
|
## Usage
|
14
20
|
|
15
|
-
The plugin will be automatically
|
21
|
+
The plugin will be automatically loaded by Minitest if it is in your application's bundle.
|
22
|
+
|
23
|
+
- By default, output will be written to `STDOUT` and `STDERR` normally for local test runs, and captured for CI runs. In CI (environments with `ENV["CI"]` set), out put will be captured and discarded, so the output of the test runner will look like how it was intended.
|
24
|
+
- If you run tests with the `--verbose` option , it will be nicely included in the test runner's output, inside a box that will tell you what test it originated from.
|
25
|
+
- You can also run this plugin in "strict mode": by running tests with the `--fail-on-output` option, tests will fail if they produce any output to `STDOUT` or `STDERR`.
|
16
26
|
|
17
|
-
|
18
|
-
- When specifying `--verbose`, the output will be buffered and written to the `STDOUT` inside a box that makes clear what test the output originated from.
|
19
|
-
- When running with the `--fail-on-output` option, a test will fail if it writes anything to either `STDOUT` or `STDERR`.
|
27
|
+
You can enable the plugin in any environment by providing the `--enable-silence` command line option to your test invocation. The primary use case for this is when you want to silence output locally.
|
20
28
|
|
21
29
|
## Development
|
22
30
|
|
@@ -26,7 +34,7 @@ To install this gem onto your local machine, run `bin/rake install`. To release
|
|
26
34
|
|
27
35
|
## Contributing
|
28
36
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/minitest-silence. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Shopify/minitest-silence/blob/master/CODE_OF_CONDUCT.md).
|
30
38
|
|
31
39
|
## License
|
32
40
|
|
@@ -16,24 +16,30 @@ module Minitest
|
|
16
16
|
|
17
17
|
module RunOneMethodPatch
|
18
18
|
def run_one_method(klass, method_name)
|
19
|
+
@original_stdin ||= $stdin.dup
|
20
|
+
@original_stdout ||= $stdout.dup
|
21
|
+
@original_stderr ||= $stderr.dup
|
22
|
+
|
19
23
|
output_reader, output_writer = IO.pipe
|
20
24
|
output_thread = Thread.new { output_reader.read }
|
21
25
|
|
22
|
-
old_stdout = $stdout.dup
|
23
|
-
old_stderr = $stderr.dup
|
24
|
-
|
25
26
|
result = begin
|
26
27
|
$stdout.reopen(output_writer)
|
27
28
|
$stderr.reopen(output_writer)
|
29
|
+
$stdin.reopen(File::NULL)
|
30
|
+
|
28
31
|
super
|
29
32
|
ensure
|
30
|
-
$stdout.reopen(
|
31
|
-
$stderr.reopen(
|
33
|
+
$stdout.reopen(@original_stdout)
|
34
|
+
$stderr.reopen(@original_stderr)
|
35
|
+
$stdin.reopen(@original_stdin)
|
32
36
|
output_writer.close
|
33
37
|
end
|
34
38
|
|
35
39
|
result.output = output_thread.value
|
36
40
|
result
|
41
|
+
ensure
|
42
|
+
output_reader.close
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
@@ -48,21 +54,26 @@ module Minitest
|
|
48
54
|
|
49
55
|
class << self
|
50
56
|
def plugin_silence_options(opts, options)
|
57
|
+
opts.on('--enable-silence', "Rebind standard IO") do
|
58
|
+
options[:enable_silence] = true
|
59
|
+
end
|
51
60
|
opts.on('--fail-on-output', "Fail a test when it writes to STDOUT or STDERR") do
|
52
61
|
options[:fail_on_output] = true
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
56
65
|
def plugin_silence_init(options)
|
57
|
-
|
58
|
-
|
66
|
+
if options[:enable_silence] || ENV["CI"]
|
67
|
+
Minitest::Result.prepend(Minitest::Silence::ResultOutputPatch)
|
68
|
+
Minitest.singleton_class.prepend(Minitest::Silence::RunOneMethodPatch)
|
59
69
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
if options[:fail_on_output]
|
71
|
+
# We have to make sure this reporter runs as the first reporter, so it can still adjust
|
72
|
+
# the result and other reporters will take the change into account.
|
73
|
+
reporter.reporters.unshift(Minitest::Silence::FailOnOutputReporter.new(options[:io], options))
|
74
|
+
elsif options[:verbose]
|
75
|
+
reporter << Minitest::Silence::BoxedOutputReporter.new(options[:io], options)
|
76
|
+
end
|
66
77
|
end
|
67
78
|
end
|
68
79
|
end
|
data/minitest-silence.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
DESCRIPTION
|
18
18
|
spec.homepage = "https://github.com/Shopify/minitest-silence"
|
19
19
|
spec.license = "MIT"
|
20
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
21
21
|
|
22
22
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
23
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-silence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -42,7 +42,6 @@ files:
|
|
42
42
|
- ".travis.yml"
|
43
43
|
- CODE_OF_CONDUCT.md
|
44
44
|
- Gemfile
|
45
|
-
- Gemfile.lock
|
46
45
|
- LICENSE.txt
|
47
46
|
- README.md
|
48
47
|
- Rakefile
|
@@ -70,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
69
|
requirements:
|
71
70
|
- - ">="
|
72
71
|
- !ruby/object:Gem::Version
|
73
|
-
version: 2.
|
72
|
+
version: 2.5.0
|
74
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
74
|
requirements:
|
76
75
|
- - ">="
|
77
76
|
- !ruby/object:Gem::Version
|
78
77
|
version: '0'
|
79
78
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.0.3
|
81
80
|
signing_key:
|
82
81
|
specification_version: 4
|
83
82
|
summary: Minitest plugin to suppress output from tests.
|
data/Gemfile.lock
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
minitest-silence (0.1.0)
|
5
|
-
minitest (~> 5.12)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.0)
|
11
|
-
jaro_winkler (1.5.4)
|
12
|
-
minitest (5.14.1)
|
13
|
-
parallel (1.19.1)
|
14
|
-
parser (2.7.1.3)
|
15
|
-
ast (~> 2.4.0)
|
16
|
-
rainbow (3.0.0)
|
17
|
-
rake (12.3.3)
|
18
|
-
rexml (3.2.4)
|
19
|
-
rubocop (0.82.0)
|
20
|
-
jaro_winkler (~> 1.5.1)
|
21
|
-
parallel (~> 1.10)
|
22
|
-
parser (>= 2.7.0.1)
|
23
|
-
rainbow (>= 2.2.2, < 4.0)
|
24
|
-
rexml
|
25
|
-
ruby-progressbar (~> 1.7)
|
26
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
27
|
-
rubocop-shopify (1.0.2)
|
28
|
-
rubocop (~> 0.82.0)
|
29
|
-
ruby-progressbar (1.10.1)
|
30
|
-
unicode-display_width (1.7.0)
|
31
|
-
|
32
|
-
PLATFORMS
|
33
|
-
ruby
|
34
|
-
|
35
|
-
DEPENDENCIES
|
36
|
-
minitest (~> 5.0)
|
37
|
-
minitest-silence!
|
38
|
-
rake (~> 12.0)
|
39
|
-
rubocop-shopify
|
40
|
-
|
41
|
-
BUNDLED WITH
|
42
|
-
2.1.4
|