A simple way to create a rake task to run with Minitest
First, in your
lib/tasks/test.task or yet
tasks/test.task) we need to require the
require "bundler/gem_tasks" require "rake/testtask"
Now we can instantiate a new
TestTask object, wich receives a block where we can configure the task.
Rake::TestTask.new do |t| end
In the configuration block, we set the test files that will run in the test task (everything inside
Rake::TestTask.new do |t| t.test_files = FileList['tests/**/*_test.rb'] #my directory to tests is 'tests' you can change at you will end desc "Run tests"
A good practice is to set the test task as default, we can do this adding this line in after creating the
task default: :test
Don't forget to require
minitest/autorun to your test files.
The final file looks like this:
require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |t| t.test_files = FileList['tests/**/*_test.rb'] end desc "Run tests" task default: :test
Check other configuration options in the Rake::TestTask documentation.
Hope this helps! ;)