How to run all tests with minitest? How to run all tests with minitest? ruby ruby

How to run all tests with minitest?


Here's a link to Rake::TestTask.

There is an example in the page to get you started.
I'll post another one that I'm using right now for a gem:

require 'rake/testtask'Rake::TestTask.new do |t|  t.pattern = "spec/*_spec.rb"end

As you can see, I assume that my files are all in /lib and that my specs are in /spec and are named whatever_spec.rb

Hope it helps.


locks' answer is better, but I also wanted to point out that you can also run minitest directly from the command like with the ruby command. To run the tests in the spec/calculator_spec.rb file run:

$ ruby spec/calculator_spec.rb 

Remember to include the following code in the calculator_spec.rb file:

require 'minitest/spec'require 'minitest/autorun'

To run all tests in the spec/ directory, use the following command (see this post for more details Globbing doesn't work with Minitest - Only one file is run)

$ for file in spec/*.rb; do ruby $file; done 


This is what Rake::TestTask does under the hood, more or less:

ruby -Ilib -e 'ARGV.each { |f| require f }' ./test/test*.rb

Note: lib & test/test*.rb (above) are the defaults but test & test/*_test.rb, respectively, are more typical.

Source: rake/testtask.rb at c34d9e0 line 169

If you're using JRuby and want to avoid paying the startup cost twice (once for Rake and then once for the subprocess that Rake starts), just use that command.