如何防止 Rake 测试调用任务 db:test:prepare [英] How to prevent Rake test to call task db:test:prepare

查看:27
本文介绍了如何防止 Rake 测试调用任务 db:test:prepare的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我想运行 Rake 测试时,都会调用任务 db:test:prepare 并从 schema.rb 和迁移重建我的测试环境数据库.我想要实现的是在我想测试 make Rails 应用程序时禁用 db:test:prepare 的调用.是否可以不修改 Rails gem?

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?

推荐答案

这是我见过的一个解决方案:

Here's a solution I've seen around:

在您的 Rakefile 中:

In your 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: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

这篇关于如何防止 Rake 测试调用任务 db:test:prepare的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆