├── .autotest ├── History.rdoc ├── Manifest.txt ├── README.rdoc ├── Rakefile ├── bin └── minitest ├── lib └── minitest │ ├── binstub_reporter.rb │ ├── complete.rb │ ├── path_expander.rb │ ├── rake_reporter.rb │ ├── sprint.rb │ ├── sprint_plugin.rb │ └── sprint_reporter.rb └── test └── test_minitest_sprint.rb /.autotest: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | 3 | require "autotest/restart" 4 | 5 | Autotest.add_hook :initialize do |at| 6 | at.testlib = "minitest/autorun" 7 | at.add_exception "tmp" 8 | 9 | # at.extra_files << "../some/external/dependency.rb" 10 | # 11 | # at.libs << ":../some/external" 12 | # 13 | # at.add_exception "vendor" 14 | # 15 | # at.add_mapping(/dependency.rb/) do |f, _| 16 | # at.files_matching(/test_.*rb$/) 17 | # end 18 | # 19 | # %w(TestA TestB).each do |klass| 20 | # at.extra_class_map[klass] = "test/test_misc.rb" 21 | # end 22 | end 23 | 24 | # Autotest.add_hook :run_command do |at| 25 | # system "rake build" 26 | # end 27 | -------------------------------------------------------------------------------- /History.rdoc: -------------------------------------------------------------------------------- 1 | === 1.3.0 / 2024-07-23 2 | 3 | * 1 minor enhancement: 4 | 5 | * Allow rake task name to be passed as an argument and repeated back in failure list. (adam12) 6 | 7 | * 1 bug fix: 8 | 9 | * Fixed wonky shebang in bin/minitest. 10 | 11 | === 1.2.2 / 2022-06-20 12 | 13 | * 1 bug fix: 14 | 15 | * Fixed print_list for --binstub and --rake. (adam12) 16 | 17 | === 1.2.1 / 2019-09-22 18 | 19 | * 1 minor enhancement: 20 | 21 | * Refactored and moved bin/minitest to Minitest::Sprint.run. 22 | 23 | * 1 bug fix: 24 | 25 | * Fixed a bug where having only options would prevent default "test" directory arg. 26 | 27 | === 1.2.0 / 2016-05-16 28 | 29 | * 1 minor enhancement: 30 | 31 | * Switched to path_expander to deal with cmdline args. See path_expander for details. 32 | 33 | === 1.1.1 / 2015-08-10 34 | 35 | * 1 bug fix: 36 | 37 | * Remove -w from bin/minitest because SOME people run dirty code. :P 38 | 39 | === 1.1.0 / 2015-03-09 40 | 41 | * 2 minor enhancements: 42 | 43 | * Added minitest/complete for cmdline test name completion. (tenderlove) 44 | * bin/minitest now directly loads tests, supports specifying files and minitest args. 45 | 46 | === 1.0.0 / 2015-01-23 47 | 48 | * 1 major enhancement 49 | 50 | * Birthday! 51 | -------------------------------------------------------------------------------- /Manifest.txt: -------------------------------------------------------------------------------- 1 | .autotest 2 | History.rdoc 3 | Manifest.txt 4 | README.rdoc 5 | Rakefile 6 | bin/minitest 7 | lib/minitest/binstub_reporter.rb 8 | lib/minitest/complete.rb 9 | lib/minitest/path_expander.rb 10 | lib/minitest/rake_reporter.rb 11 | lib/minitest/sprint.rb 12 | lib/minitest/sprint_plugin.rb 13 | lib/minitest/sprint_reporter.rb 14 | test/test_minitest_sprint.rb 15 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = minitest-sprint 2 | 3 | home :: https://github.com/seattlerb/minitest-sprint 4 | rdoc :: http://docs.seattlerb.org/minitest-sprint 5 | 6 | == DESCRIPTION: 7 | 8 | Runs (Get it? It's fast!) your tests and makes it easier to rerun individual 9 | failures. 10 | 11 | === Tab Completion 12 | 13 | Add this to your .bashrc (or .zshrc?--someone please confirm with a PR): 14 | 15 | $ complete -o bashdefault -f -C 'ruby --disable-gems $(gem which minitest/complete)' minitest 16 | 17 | Running individual minitest tests will now have tab completion for the 18 | method names. When running tests, just hit tab after -n. For example: 19 | 20 | $ minitest test/test_whatever.rb -n test_thingy 21 | test_thingy_error 22 | test_thingy_error_teardown 23 | test_thingy_failing 24 | test_thingy_failing_filtered 25 | ... etc ... 26 | 27 | == FEATURES/PROBLEMS: 28 | 29 | * TEENY implementation. 30 | * Includes a script for commandline autocompletion of test names. 31 | * Includes extra plugins to print out failure re-run commands. 32 | * One for the minitest commandline runner. (--binstub) 33 | * One for rake test runners. (--rake) 34 | * Uses path_expander, so you can use: 35 | * dir_arg -- expand a directory automatically 36 | * @file_of_args -- persist arguments in a file 37 | * -path_to_subtract -- ignore intersecting subsets of files/directories 38 | 39 | == SYNOPSIS: 40 | 41 | $ minitest test/test_whatever.rb -n test_thingy 42 | test_thingy_error 43 | test_thingy_error_teardown 44 | test_thingy_failing 45 | test_thingy_failing_filtered 46 | ... etc ... 47 | 48 | # Rakefile 49 | Minitest::TestTask.create do |t| 50 | t.extra_args = ["--rake"] # Or --binstub 51 | end 52 | 53 | == REQUIREMENTS: 54 | 55 | * ruby 56 | 57 | == INSTALL: 58 | 59 | * gem install minitest-sprint 60 | 61 | == LICENSE: 62 | 63 | (The MIT License) 64 | 65 | Copyright (c) Ryan Davis, seattle.rb 66 | 67 | Permission is hereby granted, free of charge, to any person obtaining 68 | a copy of this software and associated documentation files (the 69 | 'Software'), to deal in the Software without restriction, including 70 | without limitation the rights to use, copy, modify, merge, publish, 71 | distribute, sublicense, and/or sell copies of the Software, and to 72 | permit persons to whom the Software is furnished to do so, subject to 73 | the following conditions: 74 | 75 | The above copyright notice and this permission notice shall be 76 | included in all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 81 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 82 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 83 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 84 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 85 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | 3 | require "rubygems" 4 | require "hoe" 5 | 6 | Hoe.plugin :isolate 7 | Hoe.plugin :seattlerb 8 | Hoe.plugin :rdoc 9 | 10 | Hoe.spec "minitest-sprint" do 11 | developer "Ryan Davis", "ryand-ruby@zenspider.com" 12 | license "MIT" 13 | 14 | dependency "path_expander", "~> 1.1" 15 | end 16 | 17 | # vim: syntax=ruby 18 | -------------------------------------------------------------------------------- /bin/minitest: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "minitest/sprint" 4 | 5 | Minitest::Sprint.run 6 | -------------------------------------------------------------------------------- /lib/minitest/binstub_reporter.rb: -------------------------------------------------------------------------------- 1 | require "minitest/sprint_reporter" 2 | 3 | module Minitest 4 | class BinstubReporter < SprintReporter 5 | def print_list 6 | results.each do |result| 7 | puts " minitest -n #{result.class_name}##{result.name}" 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/minitest/complete.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # see instructions in the readme for use 4 | 5 | require 'optparse' 6 | require 'shellwords' 7 | 8 | argv = Shellwords.split(ENV['COMP_LINE']).drop 1 9 | options = {} 10 | 11 | begin 12 | OptionParser.new do |opts| 13 | opts.on("-n", "--name [METHOD]", "Test method") do |m| 14 | options[:method] = m 15 | end 16 | end.parse!(argv) 17 | rescue 18 | retry # ignore options passed to Ruby 19 | end 20 | 21 | file = argv.find { |f| File.file?(f) && !File.directory?(f) } 22 | 23 | exit unless options.key?(:method) && file 24 | 25 | require 'ripper' 26 | 27 | methods = [] 28 | K = Class.new(Ripper) { define_method(:on_def) { |n,_,_| methods << n } } 29 | 30 | begin 31 | K.parse File.read(file), file, 1 32 | methods = methods.grep(/^#{options[:method]}/) if options[:method] 33 | puts methods.join("\n") 34 | rescue # give up on parse errors 35 | end 36 | -------------------------------------------------------------------------------- /lib/minitest/path_expander.rb: -------------------------------------------------------------------------------- 1 | require "path_expander" 2 | 3 | module Minitest; end # :nodoc: 4 | 5 | ## 6 | # Minitest's PathExpander to find and filter tests. 7 | 8 | class Minitest::PathExpander < PathExpander 9 | TEST_GLOB = "**/{test_*,*_test,spec_*,*_spec}.rb" # :nodoc: 10 | 11 | def initialize args = ARGV # :nodoc: 12 | super args, TEST_GLOB, "test" 13 | end 14 | 15 | ## 16 | # Overrides PathExpander#process_flags to filter out ruby flags 17 | # from minitest flags. Only supports -I, -d, and -w for 18 | # ruby. 19 | 20 | def process_flags flags 21 | flags.reject { |flag| # all hits are truthy, so this works out well 22 | case flag 23 | when /^-I(.*)/ then 24 | $LOAD_PATH.concat $1.split(/:/) 25 | when /^-d/ then 26 | $DEBUG = true 27 | when /^-w/ then 28 | $VERBOSE = true 29 | else 30 | false 31 | end 32 | } 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/minitest/rake_reporter.rb: -------------------------------------------------------------------------------- 1 | require "minitest/sprint_reporter" 2 | 3 | module Minitest 4 | class RakeReporter < SprintReporter 5 | attr_accessor :name 6 | 7 | def initialize name = nil 8 | self.results = [] 9 | self.name = name 10 | end 11 | 12 | def print_list 13 | results.each do |result| 14 | puts [" rake", name, "N=#{result.class_name}##{result.name}"].compact.join(" ") 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/minitest/sprint.rb: -------------------------------------------------------------------------------- 1 | require "minitest/autorun" 2 | require "minitest/path_expander" 3 | 4 | $LOAD_PATH.unshift "test" 5 | $LOAD_PATH.unshift "lib" 6 | 7 | class Minitest::Sprint 8 | VERSION = "1.3.0" 9 | 10 | def self.run args = ARGV 11 | Minitest::PathExpander.new(args).process.each do |f| 12 | require "./#{f}" 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/minitest/sprint_plugin.rb: -------------------------------------------------------------------------------- 1 | require "minitest" 2 | 3 | module Minitest 4 | def self.plugin_sprint_options opts, options # :nodoc: 5 | opts.on "--rake [TASK]", "Report how to re-run failures with rake." do |task| 6 | options[:sprint] = :rake 7 | options[:rake_task] = task 8 | end 9 | 10 | opts.on "--binstub", "Report how to re-run failures with minitest." do 11 | options[:sprint] = :binstub 12 | end 13 | end 14 | 15 | def self.plugin_sprint_init options 16 | case options[:sprint] 17 | when :rake then 18 | require "minitest/rake_reporter" 19 | self.reporter << Minitest::RakeReporter.new(options[:rake_task]) 20 | when :binstub then 21 | require "minitest/binstub_reporter" 22 | self.reporter << Minitest::BinstubReporter.new 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/minitest/sprint_reporter.rb: -------------------------------------------------------------------------------- 1 | module Minitest 2 | class SprintReporter < AbstractReporter 3 | attr_accessor :results 4 | 5 | def initialize 6 | self.results = [] 7 | end 8 | 9 | def record result 10 | results << result unless result.passed? or result.skipped? 11 | end 12 | 13 | def report 14 | return if results.empty? 15 | 16 | puts 17 | puts "Happy Happy Sprint List:" 18 | puts 19 | print_list 20 | puts 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/test_minitest_sprint.rb: -------------------------------------------------------------------------------- 1 | require "minitest/autorun" 2 | require "minitest/sprint" 3 | 4 | class TestMinitestSprint < Minitest::Test 5 | def test_pass 6 | assert true 7 | end 8 | 9 | def test_skip 10 | skip "nope" 11 | end 12 | 13 | if ENV["BAD"] then # allows it to pass my CI but easy to demo 14 | def test_fail 15 | flunk "write tests or I will kneecap you" 16 | end 17 | 18 | def test_error 19 | raise "nope" 20 | end 21 | end 22 | end 23 | --------------------------------------------------------------------------------