spec/spec_helper.rb in dm-constraints-0.10.2 vs spec/spec_helper.rb in dm-constraints-1.0.0.rc1

- old
+ new

@@ -1,63 +1,26 @@ require 'rubygems' -# use local dm-core if running from a typical dev checkout. -lib = File.join('..', '..', 'dm-core', 'lib') -$LOAD_PATH.unshift(lib) if File.directory?(lib) -require 'dm-core' +require 'dm-core/spec/setup' +require 'dm-core/spec/lib/spec_helper' +require 'dm-core/spec/lib/adapter_helpers' -# Support running specs with 'rake spec' and 'spec' -$LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib') - require 'dm-constraints' -ADAPTERS = {} -def load_driver(name, default_uri) - connection_string = ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri - begin - adapter = DataMapper.setup(name.to_sym, connection_string) - - # test the connection if possible - if adapter.respond_to?(:query) - adapter.select('SELECT 1') - end - - ADAPTERS[name] = connection_string - rescue LoadError => e - warn "Could not load do_#{name}: #{e}" - false - end -end - - -HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:') -HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test') -HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test') - - Spec::Runner.configure do |config| - config.after :all do - # global model cleanup - descendants = DataMapper::Model.descendants.to_a - while model = descendants.shift - descendants.concat(model.descendants.to_a - [ model ]) - parts = model.name.split('::') - constant_name = parts.pop.to_sym - base = parts.empty? ? Object : Object.full_const_get(parts.join('::')) + config.extend(DataMapper::Spec::Adapters::Helpers) + config.extend(DataMapper::Spec::Helpers) - if base.const_defined?(constant_name) - base.send(:remove_const, constant_name) - end - - DataMapper::Model.descendants.delete(model) - end + config.before(:each) do + DataMapper.auto_migrate! end - config.before do - DataMapper.auto_migrate! + config.after :each do + DataMapper.send(:auto_migrate_down!, DataMapper::Spec.adapter.name) end - config.after do - DataMapper.send(:auto_migrate_down!, @repository.name) + config.after :all do + DataMapper::Spec.cleanup_models end + end