使用Minitest的Rails,如何设置RuboCop在每次使用rake运行测试时自动运行? [英] With Rails using Minitest, how can I set up RuboCop to run automatically each time tests are run with rake?

查看:82
本文介绍了使用Minitest的Rails,如何设置RuboCop在每次使用rake运行测试时自动运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下命令时,我希望 RuboCop 可以在测试运行之前检查我指定的应用程序目录:

When I run the following command, I want RuboCop to inspect application directories I specify before tests run:

bundle exec rake test

推荐答案

我向lib/tasks/test.rake添加了以下任务:

require 'rubocop/rake_task'

# Add additional test suite definitions to the default test task here
namespace :test do
  desc 'Runs RuboCop on specified directories'
  RuboCop::RakeTask.new(:rubocop) do |task|
    # Dirs: app, lib, test
    task.patterns = ['app/**/*.rb', 'lib/**/*.rb', 'test/**/*.rb']

    # Make it easier to disable cops.
    task.options << "--display-cop-names"

    # Abort on failures (fix your code first)
    task.fail_on_error = false
  end
end

Rake::Task[:test].enhance ['test:rubocop']

结果:

$ bundle exec rake test
Running RuboCop...
Inspecting 9 files
.........

9 files inspected, no offenses detected
Run options: --seed 55148

# Running:

...................

Finished in 1.843280s, 10.3077 runs/s, 34.7207 assertions/s.

19 runs, 64 assertions, 0 failures, 0 errors, 0 skips

这篇关于使用Minitest的Rails,如何设置RuboCop在每次使用rake运行测试时自动运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆