Recently I’ve been configuring RailsEventStore to run tests on many databases on the Travis CI. We do it using DATABASE_URL environment variable but I couldn’t find good examples easily. So here they are.

Struggling with finding Senior Ruby developers? - Show your job post here and reach thousands of developers quickly.

PostgreSQL

DATABASE_URL=postgres://localhost/rails_event_store_active_record?pool=5

MySQL

DATABASE_URL=mysql2://root:@127.0.0.1/rails_event_store_active_record?pool=5

Sqlite in memory

DATABASE_URL=sqlite3::memory:

Code

ENV['DATABASE_URL'] ||= "postgres://localhost/rails_event_store_active_record?pool=5"

RSpec.configure do |config|
  config.around(:each) do |example|
    ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
  end
end