zilkey (owner)

Revisions

gist: 108373 Download_button fork
public
Public Clone URL: git://gist.github.com/108373.git
Embed All Files: show embed
initializer.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
spec_suite_in_parallel.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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