【问题标题】:Makefile for Ruby tests用于 Ruby 测试的 Makefile
【发布时间】:2015-12-24 09:29:15
【问题描述】:

我知道Rake::TestTask

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

我希望能够通过运行来运行我所有的 Ruby 测试:

make test

如果有一种方法可以运行一个测试文件,例如:

TEST=just_one_file.rb make test

我使用 MiniTest。

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

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

我也不明白 rake test 在幕后做了什么,所以查看 Makefile 可能有助于我了解测试是如何运行的。

【问题讨论】:

    标签: ruby unit-testing makefile rake


    【解决方案1】:

    好吧,运行MiniTestfrom 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
    

    【讨论】:

      【解决方案2】:

      目录结构

      ├── 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-18
        • 1970-01-01
        • 2011-03-04
        • 2017-06-27
        • 2017-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多