Created
May 3, 2010 18:37
-
-
Save gnufied/388429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepare_analyzer() | |
saved_aggregate_data = rcov_load_aggregate_data($options.aggregate_file) | |
if(saved_aggregate_data[:coverage]) | |
$rcov_code_coverage_analyzer = saved_aggregate_data[:coverage] | |
end | |
$rcov_code_coverage_analyzer.install_hook | |
end | |
def try_migration_first(db_counter) | |
begin | |
db_config = get_connection_config(db_counter) | |
ActiveRecord::Base.establish_connection(db_config) | |
ActiveRecord::Base.connection() | |
migrate_db() | |
return true | |
rescue Exception => e | |
puts "Error runnig miration #{e.inspect}" | |
puts e.backtrace | |
return false | |
end | |
end | |
def run_cucumber(n = 2) | |
dir = Dir["#{Rails.root}/features/*.feature"] | |
groups = dir.sort.in_groups(n,false) | |
p groups | |
pids = fork_cucumber(groups) | |
Signal.trap 'SIGINT', lambda { pids.each {|p| Process.kill("KILL", p)}; exit 1 } | |
errors = Process.waitall.map { |pid,status| status.exitstatus } | |
raise "Error running cucumber" if(errors.any? { |x| x != 0 }) | |
end | |
def fork_cucumber(groups) | |
pids = [] | |
GC.start | |
groups.each_with_index do |group,db_counter| | |
if(!group.empty?) | |
pids << Process.fork do | |
files = group.find_all {|f| f !~ /^-/ } | |
prepare_analyzer() | |
ENV["RAILS_ENV"] = 'cucumber' | |
Object.const_set :RAILS_ENV, 'cucumber' | |
require(File.join(RAILS_ROOT, 'config', 'environment')) | |
prepare_databse(db_counter) unless try_migration_first(db_counter) | |
require "cucumber/cli/main" | |
cucumber_options = get_cucumber_options(files) | |
failure = Cucumber::Cli::Main.execute(cucumber_options) | |
raise "Cucumber failed" if failure | |
end | |
end | |
end | |
pids | |
end | |
def fork_tests(groups) | |
pids = [] | |
GC.start | |
groups.each_with_index do |group, db_counter| | |
pids << Process.fork { child_run(group,db_counter) } | |
end | |
pids | |
end | |
def get_cucumber_options(files) | |
args = ( | |
['-m'] + ['-q'] + | |
files | |
).flatten.compact | |
args | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment