我正在尝试设置我的rails项目,以使贡献者所需的所有验证都在一个命令中,当前我们正在运行:
rake test
但是现在我们也想使用rubocop进行静态分析:
rubocop -R -a
我希望这可以在一个简单的rake任务中执行。最好覆盖“ rake test”以运行rubocop,然后覆盖Rails项目的标准rake测试内容,因为这样就无需记住更改命令了。但是,如果我必须创建一个单独的rake任务,那也可能很好。
我已经看过rubocop耙式集成here, at the bottom,但是我不确定如何将'rake test'捆绑到一个任务中……有什么想法吗?
test
rake任务,然后调用您提到的rubocop的代码段。例如,在.rake文件中,您可能会有类似的内容:
require 'rubocop/rake_task'
desc 'Run tests and rubocop'
task :my_test do
Rake::Task['test'].invoke
Rubocop::RakeTask.new
end
[如果您需要自定义对Rubocop的调用并且涉及更多代码,则可以创建另一个自定义任务,例如:rubocop,然后您也可以从:my_test调用它。最后,创建自己的rake任务并坚持使用
rake test
的另一种方法是修改test_helper以调用测试完成后需要调用的任何东西。
require 'rubocop/rake_task'
task :default => [:rubocop, :test]
desc 'Run tests'
task(:test) do
# run your specs here
end
desc 'Run rubocop'
task :rubocop do
RuboCop::RakeTask.new
end
您的任务:
> rake -T rake rubocop # Run rubocop rake test # Run tests
desc 'Run tests and rubocop'
task :validate do
Rake::Task['rubocop'].invoke
Rake::Task['test'].invoke
end
task :rubocop do
require 'rubocop'
cli = Rubocop::CLI.new
cli.run(%w(--rails --auto-correct))
end
Rubocop :: RakeTask.new
至:
Rubo
C op :: RakeTask.new
见妈妈?我知道如何使用CamelCase!