0

I know about Rake::TestTask.

But, how would I write a Makefile to achive similar functionality?

I want to be able to run all my Ruby tests by running:

make test

It'd also be nice to have a way to run one test file, e.g.:

TEST=just_one_file.rb make test

I use MiniTest.

I want this because I like Make, and I want to start using it more.

I figured seeing this example would help me.

I also don't understand what rake test does under the scenes, so seeing the Makefile might help me understand how tests run.

ma11hew28
  • 121,420
  • 116
  • 450
  • 651

2 Answers2

1

Well, just run MiniTest from command line:

This is how you run 1 file:

$ ruby -Ilib:test test/minitest/test_minitest_unit.rb

To run everything, you need to collect all files by some pattern (Rake::TestTask by default uses test/test*.rb) and then supply it to above command as arguments, something like this

$ find test -name 'test*.rb' | xargs ruby -Ilib:test
Alexey Shein
  • 7,342
  • 1
  • 25
  • 38
1

Directory Structure

├── Makefile
├── app
│   ├── controllers
│   ├── helpers
│   ├── views
├── test
│   ├── controllers
│   ├── helpers
│   ├── test_helper.rb

Makefile

TEST := test/**/*_test.rb

.PHONY : test

test :
    ruby -Itest -e 'ARGV.each { |f| require "./#{f}" }' $(TEST)

See how to run all the tests with minitest?

Test Commands

make test # runs all tests
make test TEST=test/controllers/* # runs all tests in test/controllers
make test TEST='test/controllers/users_controller_test.rb test/controllers/groups_controller_test.rb' # runs some tests
make test TEST=test/controllers/users_controller_test.rb # runs a single test
Community
  • 1
  • 1
ma11hew28
  • 121,420
  • 116
  • 450
  • 651