运行“db:test:load => db:test:purge”而不重置数据库

时间:2013-09-09 12:22:03

标签: ruby-on-rails ruby-on-rails-3

当我运行“rake test:integration”时,它调用“db:test:load => db:test:purge”。我不想重新创建数据库,只想在不触及数据库的情况下运行测试用例。有什么方法可以做到吗?

1 个答案:

答案 0 :(得分:2)

它和我的评论一样

对于你的情况它会是这样的: -

在您的Rakefile中:

Rake::TaskManager.class_eval do
  def remove_task(task_name)
   @tasks.delete(task_name.to_s)
 end
end

在lib / tasks / db / test.rake中:

Rake.application.remove_task 'db:test:load'
Rake.application.remove_task 'db:test:purge'

namespace :db do
 namespace :test do 
   task :load do |t|
     # rewrite the task to not do anything you don't want
   end
   task :purge do |t|
      # rewrite the task to not do anything you don't want
   end  
  end
end