minitest-rerun-failed 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2b20ea10693d44179e02baffbbc4138190df565c4a03c8d5ae53f0a933407415
4
+ data.tar.gz: 00136a77f31014f04d110bd21651feb2da893529bbd45b7e31302e98c2896268
5
+ SHA512:
6
+ metadata.gz: 98c5ea06f7777e1ba131f46d6c16397b474e980f368074dae65dd30b6832487dceb4b03fa34ae9e12d582e76ff3735c504998101956ba9b72f45097c7d34940c
7
+ data.tar.gz: 46df4fdc85e2f5bc26a6dd078eb81e98d2886cabf4cd664e5bd9d194fd2570949dbde729bb3778dbd8c4f1e5d662d86481756778e1a0bc8b02c425244fcba650
@@ -0,0 +1,16 @@
1
+ name: Master
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ rake_test:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ bundler-cache: true
15
+ - name: Run rake test
16
+ run: bundle exec rake test
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /test_output/
11
+ .minitest_failed_tests.txt
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Enabled: true
15
+ Max: 200
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Metrics/AbcSize:
21
+ Max: 19
22
+
23
+ Style/ConditionalAssignment:
24
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-09-09
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in minitest_rerun_failed.gemspec
6
+ gemspec
7
+
8
+ gem "minitest"
9
+ gem "minitest-reporters"
10
+ gem "rake"
11
+ gem "rubocop"
12
+ gem "rubocop-minitest"
13
+ gem "rubocop-rake"
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ minitest-rerun-failed (0.1.3)
5
+ minitest (~> 5.14.4)
6
+ minitest-reporters (~> 1.4.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ansi (1.5.0)
12
+ ast (2.4.2)
13
+ builder (3.2.4)
14
+ minitest (5.14.4)
15
+ minitest-reporters (1.4.3)
16
+ ansi
17
+ builder
18
+ minitest (>= 5.0)
19
+ ruby-progressbar
20
+ parallel (1.20.1)
21
+ parser (3.0.2.0)
22
+ ast (~> 2.4.1)
23
+ rainbow (3.0.0)
24
+ rake (13.0.6)
25
+ regexp_parser (2.1.1)
26
+ rexml (3.2.5)
27
+ rubocop (1.20.0)
28
+ parallel (~> 1.10)
29
+ parser (>= 3.0.0.0)
30
+ rainbow (>= 2.2.2, < 4.0)
31
+ regexp_parser (>= 1.8, < 3.0)
32
+ rexml
33
+ rubocop-ast (>= 1.9.1, < 2.0)
34
+ ruby-progressbar (~> 1.7)
35
+ unicode-display_width (>= 1.4.0, < 3.0)
36
+ rubocop-ast (1.11.0)
37
+ parser (>= 3.0.1.1)
38
+ rubocop-minitest (0.15.0)
39
+ rubocop (>= 0.90, < 2.0)
40
+ rubocop-rake (0.6.0)
41
+ rubocop (~> 1.0)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.0.0)
44
+
45
+ PLATFORMS
46
+ x86_64-darwin-19
47
+ x86_64-linux
48
+
49
+ DEPENDENCIES
50
+ minitest
51
+ minitest-reporters
52
+ minitest-rerun-failed!
53
+ rake
54
+ rubocop
55
+ rubocop-minitest
56
+ rubocop-rake
57
+
58
+ BUNDLED WITH
59
+ 2.2.18
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Søren Houen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # minitest-rerun-failed
2
+ ![master branch CI](https://github.com/houen/minitest-rerun-failed/actions/workflows/main.yml/badge.svg?branch=master)
3
+
4
+ Easy rerun of failed tests with minitest.
5
+
6
+ ![Example screenshot](assets/screenshot.png)
7
+
8
+ ## Goals
9
+ - Outputs all failed tests in short summary at end of test run.
10
+ - To console and / or to file
11
+ - Optionally includes line numbers
12
+ - Lists seed of run for rerun.
13
+ - [TODO] Executable for running only failed tests
14
+ - Until then, use something like
15
+ - `ruby $(cat .minitest_failed_tests.txt)`
16
+ - `bundle exec rails test $(cat .minitest_failed_tests.txt)`
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'minitest_rerun_failed'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle install
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install minitest_rerun_failed
33
+
34
+ ## Usage
35
+
36
+ Use it like any Minitest::Reporters like such:
37
+
38
+ ```
39
+ Minitest::Reporters.use! [
40
+ Minitest::Reporters::ProgressReporter.new, # This is just my preferred reporter. Use the one(s) you like.
41
+ Minitest::Reporters::FailedTestsReporter.new(verbose: true, include_line_numbers: true)
42
+ ]
43
+ ```
44
+
45
+ ### Options
46
+ - include_line_numbers: Include line numbers in outputs. Defaults to true
47
+ - verbose: Output to stdout. Defaults to true
48
+ - file_output: Output to file. Defaults to true
49
+ - output_path: Path to place output files in. Defaults to '.'
50
+
51
+ ## Other
52
+ ### Why line numbers instead of test names? What if the lines change as I am fixing things?
53
+ Line numbers were much easier to implement.
54
+ If you find a good way to output test names instead, please open a PR with tests to add it as an option.
55
+
56
+ As for if line numbers change, the most likely outcome is that the whole file will simply be run instead of a single test.
57
+ You can also use the option `include_line_numbers: false` to always output whole files for greater safety.
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/houen/minitest_rerun_failed.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
72
+
73
+ ## TODO
74
+ - Executable for rerun? (https://stackoverflow.com/a/65707495)
75
+ - Rerun with same seed
76
+ - Minitest-reporters or minitest plugin?
77
+
78
+ https://stackoverflow.com/questions/19910533/minitest-rerun-only-failed-tests
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/real/**/*_test.rb"]
10
+ end
11
+
12
+ Rake::TestTask.new(:tests_meant_to_fail) do |t|
13
+ t.libs << "test"
14
+ t.libs << "lib"
15
+ t.test_files = FileList["test/meant_to_fail/**/*_test.rb"]
16
+ end
17
+
18
+ require "rubocop/rake_task"
19
+
20
+ RuboCop::RakeTask.new
21
+
22
+ task default: %i[test rubocop]
Binary file
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "minitest/rerun/failed"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minitest
4
+ module Reporters
5
+ # Source: https://www.houen.net/2021/08/23/minitest-rerun-failed-tests/
6
+ # License: MIT
7
+ #
8
+ # Outputs failed tests to screen and / or file
9
+ # Allows to rerun only failed tests with minitest if added to Minitest::Reporters.use!
10
+ #
11
+ # Example:
12
+ # In test_helper.rb or similar:
13
+ # Minitest::Reporters.use! [Minitest::Reporters::ProgressReporter.new, Minitest::Reporters::FailedTestsReporter.new(verbose: true, include_line_numbers: true)]
14
+ #
15
+ # Now after a failed test run, rerun failed tests only with: `bundle exec rails test $(cat .minitest_failed_tests.txt)`
16
+ #
17
+ class FailedTestsReporter < Minitest::Reporters::BaseReporter
18
+ def initialize(options = {})
19
+ super(options)
20
+ @options = options
21
+
22
+ # Include line numbers? (failed_test.rb:42 or just failed_test.rb)
23
+ @include_line_numbers = options.fetch(:include_line_numbers, true)
24
+ # Output to console?
25
+ @verbose = options.fetch(:verbose, true)
26
+ # Output to file?
27
+ @file_output = options.fetch(:file_output, true)
28
+ # What path to file?
29
+ @output_path = options.fetch(:output_path, ".")
30
+ FileUtils.mkdir_p(@output_path) if @output_path
31
+
32
+ @output_file_path = File.join(@output_path, ".minitest_failed_tests.txt")
33
+ end
34
+
35
+ def record(test)
36
+ tests << test
37
+ end
38
+
39
+ def report
40
+ super
41
+
42
+ failure_paths = []
43
+ file_output = []
44
+ curdir = FileUtils.pwd
45
+
46
+ tests.each do |test|
47
+ next if test.skipped?
48
+ next if test.failure.nil?
49
+
50
+ # DEBUG OUTPUT STR
51
+ # p '============================================='
52
+ # p "Failure:\n#{test.class}##{test.name} [#{test.failure.location}]\n#{test.failure.class}: #{test.failure.message}"
53
+ # p '============================================='
54
+
55
+ failure_file_location = find_failure_location(test, curdir)
56
+ failure_paths << failure_file_location if failure_file_location
57
+ end
58
+
59
+ output_results(failure_paths, file_output)
60
+ File.write(@output_file_path, file_output.join("\n"), encoding: "UTF-8")
61
+ end
62
+
63
+ private
64
+
65
+ def find_failure_location(test, curdir)
66
+ # Build a haystack string from failures and errors to find test file location in
67
+ tmp_haystack = []
68
+ tmp_haystack << test.failure.location
69
+ tmp_haystack << test.to_s
70
+ # Add filtered backtrace unless it is an unexpected error, which do not have a useful trace
71
+ tmp_haystack << filter_backtrace(test.failure.backtrace).join unless test.failure.is_a?(MiniTest::UnexpectedError)
72
+
73
+ # Get failure location as best we can from haystack
74
+ if @include_line_numbers
75
+ failure_file_location = tmp_haystack.join[/(.+_test\.rb:[0-9]+)/, 1]
76
+ else
77
+ failure_file_location = tmp_haystack.join[/(.+_test\.rb):[0-9]+/, 1]
78
+ end
79
+
80
+ return unless failure_file_location
81
+
82
+ # Make path relative if absolute
83
+ failure_file_location.gsub!(curdir, "")
84
+ failure_file_location.gsub!(%r{^/}, "")
85
+
86
+ failure_file_location
87
+ end
88
+
89
+ def output_results(failure_paths, file_output)
90
+ return if failure_paths.empty?
91
+
92
+ _puts("")
93
+ headline = @include_line_numbers ? "Failed tests: #{failure_paths.count} (seed #{@options[:seed]}):" : "Failed test files: #{failure_paths.count} (seed #{@options[:seed]}):"
94
+ _puts(headline)
95
+ failure_paths.uniq.each do |file_path|
96
+ file_output << file_path.to_s
97
+ _puts red(file_path.strip)
98
+ end
99
+ end
100
+
101
+ def _puts(str)
102
+ return unless @verbose
103
+
104
+ puts(str)
105
+ end
106
+
107
+ def print_padded_comment(line)
108
+ puts "##{pad(line)}"
109
+ end
110
+
111
+ def color?
112
+ return @color if defined?(@color)
113
+
114
+ @color = @options.fetch(:color) do
115
+ io.tty? && (
116
+ ENV["TERM"] =~ /^screen|color/ ||
117
+ ENV["EMACS"] == "t"
118
+ )
119
+ end
120
+ end
121
+
122
+ def green(string)
123
+ color? ? ANSI::Code.green(string) : string
124
+ end
125
+
126
+ def yellow(string)
127
+ color? ? ANSI::Code.yellow(string) : string
128
+ end
129
+
130
+ def red(string)
131
+ color? ? ANSI::Code.red(string) : string
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MinitestRerunFailed
4
+ VERSION = "0.1.3"
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest/reporters"
4
+
5
+ require_relative "minitest_rerun_failed/version"
6
+ require_relative "minitest_rerun_failed/failed_tests_reporter"
7
+
8
+ module MinitestRerunFailed
9
+ class Error < StandardError; end
10
+
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/minitest_rerun_failed/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "minitest-rerun-failed"
7
+ spec.version = MinitestRerunFailed::VERSION
8
+ spec.authors = ["Søren Houen"]
9
+ spec.email = ["s@houen.net"]
10
+
11
+ spec.summary = "Easily rerun failed tests with Minitest"
12
+ spec.homepage = "https://www.github.com/houen/minitest_rerun_failed"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://www.github.com/houen/minitest_rerun_failed"
18
+ spec.metadata["changelog_uri"] = "https://www.github.com/houen/minitest_rerun_failed/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ spec.add_dependency "minitest", "~> 5.14.4"
31
+ spec.add_dependency "minitest-reporters", "~> 1.4.3"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-rerun-failed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Søren Houen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.14.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.14.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-reporters
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.3
41
+ description:
42
+ email:
43
+ - s@houen.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/main.yml"
49
+ - ".gitignore"
50
+ - ".rubocop.yml"
51
+ - CHANGELOG.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - assets/screenshot.png
58
+ - bin/console
59
+ - bin/setup
60
+ - lib/minitest_rerun_failed.rb
61
+ - lib/minitest_rerun_failed/failed_tests_reporter.rb
62
+ - lib/minitest_rerun_failed/version.rb
63
+ - minitest_rerun_failed.gemspec
64
+ homepage: https://www.github.com/houen/minitest_rerun_failed
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ homepage_uri: https://www.github.com/houen/minitest_rerun_failed
69
+ source_code_uri: https://www.github.com/houen/minitest_rerun_failed
70
+ changelog_uri: https://www.github.com/houen/minitest_rerun_failed/CHANGELOG.md
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.7.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.2.15
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Easily rerun failed tests with Minitest
90
+ test_files: []