views:

911

answers:

2

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  A: 

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
Dave Pirotte
+3  A: 

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
mckeed
I like this. With this you don't have to install any plugin and it works well. However, what about if I want to use prepare method in the future? Is it possible to keep it only remove it from Rake running queue?
Edvinas Bartkus
In that case, I guess you'd have to use this method to rewrite `test:units`, `test:functionals`, and `test:integration` so that they don't inherit from the `db:test:prepare` task.
mckeed
Actually, I haven't tested this, but you could probably change `remove_task` to: `def rename_task(task_name, new_task_name) @tasks[new_task_name] = @tasks.delete(task_name)end`You'll still have to rewrite `db:test:prepare` because the test tasks will still run it.
mckeed