【问题标题】:With Rails using Minitest, how can I set up RuboCop to run automatically each time tests are run with rake?使用使用 Minitest 的 Rails,我如何设置 RuboCop 以在每次使用 rake 运行测试时自动运行?
【发布时间】:2015-12-01 17:52:42
【问题描述】:

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

bundle exec rake test

【问题讨论】:

  • 也许您应该考虑拥有一个运行 rubocop 的 Guardfile,然后在文件更改时自动进行测试。

标签: ruby-on-rails minitest rubocop


【解决方案1】:

我将以下任务添加到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

【讨论】:

    猜你喜欢
    • 2012-05-21
    • 2015-10-10
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    相关资源
    最近更新 更多