spec/spec_helper.rb in sequel-rails-0.1.8 vs spec/spec_helper.rb in sequel-rails-0.4.0.pre
- old
+ new
@@ -1,21 +1,35 @@
-begin
- # Just in case the bundle was locked
- # This shouldn't happen in a dev environment but lets be safe
- require File.expand_path('../../.bundle/environment', __FILE__)
-rescue LoadError
- require 'rubygems'
- require 'bundler'
- Bundler.setup
-end
-Bundler.require(:default, :test)
+require "rubygems"
+require "bundler"
-$LOAD_PATH.unshift(File.expand_path('../', __FILE__))
-$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
+Bundler.require :default, :development, :test
-require 'sequel-rails'
+# Combustion initialization has to happend before loading rspec/rails
+Combustion.initialize! "sequel_rails"
-require 'spec'
-require 'spec/autorun'
+# Load support files
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
-Spec::Runner.configure do |config|
+RSpec.configure do |config|
+ config.around :each do |example|
+ Sequel::Model.db.transaction(rollback: :always) do
+ example.run
+ end
+ end
+end
+
+# Ensure db exists and clean state
+begin
+ require "sequel_rails/storage"
+ silence(:stdout) do
+ SequelRails::Storage.adapter_for(:test).drop
+ SequelRails::Storage.adapter_for(:test).create
+ end
+
+ require 'sequel/extensions/migration'
+ load "#{Rails.root}/db/schema.rb"
+ Sequel::Migration.descendants.first.apply Sequel::Model.db, :up
+rescue Sequel::DatabaseConnectionError => e
+ puts "Database connection error: #{e.message}"
+ puts "Ensure test db exists before running specs."
+ exit 1
end