0
我有一堆不属于单位或功能测试的测试,他们是格式test/foo/special_test.rb
创建我自己的耙测试:富任务
我想创建一个rake任务一样rake test:units
将运行所有foo
文件夹中的测试。我该怎么做呢?
编辑:其实我喜欢rake test:foo
是有点不同rake test:units
,在我做不希望它当我做简单rake test
运行。
我有一堆不属于单位或功能测试的测试,他们是格式test/foo/special_test.rb
创建我自己的耙测试:富任务
我想创建一个rake任务一样rake test:units
将运行所有foo
文件夹中的测试。我该怎么做呢?
编辑:其实我喜欢rake test:foo
是有点不同rake test:units
,在我做不希望它当我做简单rake test
运行。
我不记得这是从哪里来的,所以很遗憾我无法给予适当的承认,但是这应该起作用。我说“应该”,因为我已经停止使用它,但是从我的git历史中抓住了它。
# First, 'reopen' the default :test namespace and create your custom task.
namespace :test do
Rake::TestTask.new(:foo_tests => ["test:prepare", "other_dependent_rake_tasks"]) do |t|
DatabaseCleaner.strategy = :transaction # If using this.
t.libs << "test"
# Will also get subfolders within test/foo
t.test_files = FileList['test/foo/**/*_test.rb', 'test/foo/*_test.rb']
end
end
您可以删除默认的“测试”任务,并重新定义它,这样当你运行rake test
它会自动运行也rake test:foo_tests
。
remove_task "test"
desc 'Adding onto Rails regular tests'
task :test do
# Add all the names of tests you want run here.
errors = %w(test:units test:functionals test:integration test:foo_tests).collect do |task|
begin
puts "Running: #{task}"
Rake::Task[task].invoke
nil
rescue => e
task
end
end.compact
abort "Errors running #{errors * ', '}!" if errors.any?
end
这似乎工作,但我希望我知道't.libs <<“test”正在做什么。 – spike
@spike我很高兴它的工作原理!至于您的担心,它将添加“测试”到目录列表以添加到加载路径。 – MrDanA
太好了,谢谢 – spike