How to prevent Rake test to call task db:test:prepare

不羁岁月 提交于 2019-12-18 02:44:26

问题


Every time I want to run Rake test the task db:test:prepare is being called and it rebuilds my test environment database from schema.rb and migrations. What I would like to achive is to disable the call of db:test:prepare when I want to test make Rails application. Is it possible without modifying Rails gem?


回答1:


Here's a solution I've seen around:

In your Rakefile:

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

In lib/tasks/db/test.rake:

Rake.application.remove_task 'db:test:prepare'

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



回答2:


There is a plugin that takes care of this for you: override_rake_task. Here is a quick usage example:

namespace :db do
  namespace :test do
    override_task :prepare do; end
  end
end



回答3:


For some older version of rails - you can place Rake::Task['db:test:prepare'].clear at the end of your Rakefile



来源:https://stackoverflow.com/questions/1097845/how-to-prevent-rake-test-to-call-task-dbtestprepare

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!