I have done this in my spec file:
RSpec.configure do |config|
config_file = YAML.load_file('settingsyml')[
'test']
DataMapper.setup(:default, config_file['db_url'])
DataMapper.finalize
DataMapper::Model.raise_on_save_failure = true
#--------------------------------------------------------------------------------------------#
# Flush all tables before each test and enter some default values #
#--------------------------------------------------------------------------------------------#
config.before(:each) {
DataMapper.auto_migrate!
# Seed tables here
}
And this in my Rakefile:
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
So, whenever i do:
$ rake spec
It automigrates the db and seeds it and executes the specs
You might want to auto_upgrade! instead of auto_migrate!