Skip to content

Instantly share code, notes, and snippets.

@krasio
Created April 10, 2012 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krasio/2351762 to your computer and use it in GitHub Desktop.
Save krasio/2351762 to your computer and use it in GitHub Desktop.
spec/support/lite/nulldb.rb
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