9

是否可以让 minitest 通过 rake 任务仅运行失败的测试?

在互联网上找不到任何关于此的内容...使用 rspec 或 cucumber 可以正常工作..这里有可能吗?

4

3 回答 3

1

您可以查看guard-minitest gem。我想这就是你要找的。

于 2014-10-18T00:07:07.567 回答
1

spring: 'bin/rails test'Guardfile 中的 # 选项将仅运行更改的文件。

我在 Guardfile 中有以下配置。(该项目混合了 Unit & Spec 风格的测试)

# all_on_start: false               # run all tests in group on startup, default: true
# all_after_pass: true              # run all tests in group after changed specs pass, default: false
# cli: '--test'                     # pass arbitrary Minitest CLI arguments, default: ''
# test_folders: ['tests']           # specify an array of paths that contain test files, default: %w[test spec]
# include: ['lib']                  # specify an array of include paths to the command that runs the tests
# test_file_patterns: %w[test_*.rb] # specify an array of patterns that test files must match in order to be run, default: %w[*_test.rb test_*.rb *_spec.rb]
# spring: true                      # enable spring support, default: false
# zeus: true                        # enable zeus support; default: false
# drb: true                         # enable DRb support, default: false
# bundler: false                    # don't use "bundle exec" to run the minitest command, default: true
# rubygems: true                    # require rubygems when running the minitest command (only if bundler is disabled), default: false
# env: {}                           # specify some environment variables to be set when the test command is invoked, default: {}
# all_env: {}                       # specify additional environment variables to be set when all tests are being run, default: false
# autorun: false                    # require 'minitest/autorun' automatically, default: true
options = {
  spring: 'bin/rails test', # NOTE: true = run all tests on every run
  all_on_start: false,
  all_after_pass: false
}
guard :minitest, options do
  # with Minitest::Unit
  watch(%r{^test/(.*)\/?test_(.*)\.rb$})
  watch(%r{^test/(.*)\/.+_test\.rb$})
  watch(%r{^lib/(.*/)?([^/]+)\.rb$})     { |m| "test/#{m[1]}test_#{m[2]}.rb" }
  watch(%r{^test/test_helper\.rb$})      { 'test' }
  watch(%r{^test/.+_test\.rb$})

  # watch('test/test_helper.rb')                        { 'test' }
  watch('config/routes.rb')                           { 'test/routing' }
  watch('app/controllers/application_controller.rb')  { 'test/controllers' }
  watch(%r{^app/(.+)\.rb$})                           { |m| "test/#{m[1]}_test.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "test/#{m[1]}#{m[2]}_test.rb" }
  watch(%r{^lib/(.+)\.rb$})                           { |m| "test/lib/#{m[1]}_test.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["test/routing/#{m[1]}_routing_test.rb", "test/#{m[2]}s/#{m[1]}_#{m[2]}_test.rb", "test/system/#{m[1]}_test.rb"] }

  # with Minitest::Spec
  watch(%r{^spec/(.*)_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})         { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
end
于 2018-02-13T17:11:26.987 回答
1

我能找到的最接近的是这个插件:

https://github.com/ivantsepp/minitest-rerun-options

它为失败的测试输出命令行选项,如下所示:

Rerun failed tests options:
--name TestExample#test_another_that_will_fail
--name TestExample#test_that_will_fail

因此您可以将它们附加到您的rake test命令中。

于 2016-08-08T12:23:40.873 回答