gpt4 book ai didi

ruby-on-rails - 使用 Minitest 的 Rails,如何设置 RuboCop 在每次使用 rake 运行测试时自动运行?

转载 作者:行者123 更新时间:2023-12-04 06:03:36 26 4
gpt4 key购买 nike

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

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

关于ruby-on-rails - 使用 Minitest 的 Rails,如何设置 RuboCop 在每次使用 rake 运行测试时自动运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34026866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com