Last Updated: February 25, 2016
·
3.013K
· pechorin

Rails in-memory sql db

database.yml:

test:
  adapter: sqlite3
  database: ":memory:"

at the end of spec/spec_helper.rb:

def in_memory_database?
  Rails.env.test? and Rails.configuration.database_configuration['test']['database'] == ':memory:'
end

if in_memory_database?
  puts "creating sqlite in memory database"
  silence_stream(STDOUT) do
    load "#{Rails.root}/db/schema.rb"
  end
end