我正在尝试创建一些可以单独调用的rake任务:
require 'rspec/core/rake_task'
namespace :grouped_tests do
desc "Run the Group A specs."
task :group_a => :spec
puts "starting tests a"
RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/helpers/*_spec.rb"
end
desc "Run the Group B specs."
task :group_b => :spec
puts "starting tests b"
RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/views/*_spec.rb"
end
end
但是当我打电话给以下时间时:
rake grouped_tests:group_b
它仍显示在输出中(来自puts
):
starting tests a
starting tests b
它只运行:group_a
,即使我正在调用group_b
。
任何想法为什么?
答案 0 :(得分:0)
您需要更新代码,如下所示:
require 'rake'
require 'rspec/core/rake_task'
namespace :grouped_tests do
namespace :helpers do
desc "Run the Group A specs."
RSpec::Core::RakeTask.new(:selective => "db:test:prepare") do |t|
puts "starting tests a"
t.pattern = "spec/helpers/*_spec.rb"
end
end
namespace :views do
desc "Run the Group B specs."
RSpec::Core::RakeTask.new(:selective => "db:test:prepare") do |t|
puts "starting tests b"
t.pattern = "spec/views/*_spec.rb"
end
end
end
task :selective => ["grouped_tests:helpers:selective", "grouped_tests:views:selective"]
您可以将rake任务调用为:
rake grouped_tests:helpers:selective
rake grouped_tests:views:selective
答案 1 :(得分:-1)
我认为这是语法错误,您错过了do
关键字:
task :group_a => :spec do
// Do your thing
end
task :group_b => :spec do
// Do your other thing
end