views:

93

answers:

1

It is easy to setup Datamapper with a Sqlite3 in memory database with: DataMapper.setup :default, 'sqlite3::memory:'.

However, when testing, I'd like to destroy the whole in memory database after each test, instead of invoking automigrate! as a shortcut on dropping everything. Is it possible? Or is it enough to set the default repository to nil, and let the garbage collector dispose of it?

+1  A: 

My method of doing this is (in rspec):

Spec::Runner.configure do |config|
  config.before(:all) do
    DataMapper.auto_migrate!
  end

  config.before(:each) do
    DataMapper::Repository.context << repository(:default)
  end

  config.after(:each) do
    DataMapper::Repository.context.pop
  end
end
x1a4