Ruby 测试的 Makefile

Makefile for Ruby tests

我知道 Rake::TestTask

但是,我该如何编写 Makefile 来实现类似的功能?

我希望能够 运行 我的所有 Ruby 测试 运行ning:

make test

最好能有一种方法来 运行 一个测试文件,例如:

TEST=just_one_file.rb make test

我使用 MiniTest。

我想要这个是因为我喜欢 Make,我想开始更多地使用它。

我认为看到这个例子会对我有所帮助。

我也不明白 rake 测试在幕后做了什么,所以看看 Makefile 可能会帮助我了解测试的方式 运行。

嗯,就运行 MiniTest from command line:

这就是你 运行 1 个文件的方式:

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

为了运行一切,你需要通过某种模式收集所有文件(Rake::TestTask默认使用test/test*.rb)然后将它作为参数提供给上面的命令,就像这样

$ find test -name 'test*.rb' | xargs ruby -Ilib:test

目录结构

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

生成文件

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

.PHONY : test

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

how to run all the tests with minitest?

测试命令

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