Skip to content

Instantly share code, notes, and snippets.

@zilkey
Created May 7, 2009 21:11
Show Gist options
  • Save zilkey/108373 to your computer and use it in GitHub Desktop.
Save zilkey/108373 to your computer and use it in GitHub Desktop.
def in_memory_database?
ENV["RAILS_ENV"] == "test" and
ENV["IN_MEMORY_DB"] and
Rails::Configuration.new.database_configuration['test-in-memory']['database'] == ':memory:'
end
$TESTING=true
if in_memory_database?
puts "connecting to in-memory database ..."
ActiveRecord::Base.establish_connection(Rails::Configuration.new.database_configuration['test-in-memory'])
puts "building in-memory database from db/schema.rb ..."
load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
# ActiveRecord::Migrator.up('db/migrate') # use migrations
end
require "spec/spec_helper"
GEO_SPECS = Dir["spec/geocoding/**/*_spec.rb"]
SOLR_SPECS = Dir["spec/solr/**/*_spec.rb"]
EXCLUDED_SPECS = GEO_SPECS + SOLR_SPECS
if ENV['IN_MEMORY_DB']
N_PROCESSES = 2 # for dual-core machines
specs = (Dir["spec/**/*_spec.rb"] - EXCLUDED_SPECS).sort.in_groups_of(N_PROCESSES)
processes = []
interrupt_handler = lambda do
STDERR.puts "caught keyboard interrupt, exiting gracefully ..."
processes.each { |process| Process.kill "KILL", process }
exit 1
end
Signal.trap 'SIGINT', interrupt_handler
1.upto(N_PROCESSES) do |j|
processes << Process.fork {
specs.each do |array|
if array[j-1]
require array[j-1]
end
end
}
end
1.upto(N_PROCESSES) { Process.wait }
else
(Dir["spec/**/*_spec.rb"] - EXCLUDED_SPECS).each do |file|
require file
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment