Created
April 10, 2012 14:30
-
-
Save krasio/2351762 to your computer and use it in GitHub Desktop.
spec/support/lite/nulldb.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nulldb' | |
module NullDB | |
class << self | |
def nullify(options={}) | |
begin | |
@prev_connection = ActiveRecord::Base.connection_pool.try(:spec) | |
rescue | |
end | |
ActiveRecord::Base.establish_connection(options.merge(:adapter => :nulldb)) | |
end | |
end | |
end | |
def setup_nulldb | |
schema_path = File.expand_path('../../../db/schema.rb', File.dirname(__FILE__)) | |
NullDB.nullify(:schema => schema_path) | |
end | |
def teardown_nulldb | |
NullDB.restore | |
end | |
RSpec.configure do |config| | |
config.before :each do | |
setup_nulldb | |
end | |
config.after :each do | |
teardown_nulldb | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment