Sha256: 793c972fdb90e73edbb6c85aeb7a867c8e615532ff8cb7ea04faca580dac0fc0

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

#try and see what frameworks are available

%w(
  rspec-rails
  rspec/core
  rspec/core/rake_task
).each do |library|
  begin
    require library
  rescue LoadError
    puts "could not require #{library}"
  end
end

num_workers = SnapCI::ParallelTests.total_workers
worker_index = SnapCI::ParallelTests.worker_index

desc 'Run all specs in spec directory (excluding plugin specs)'
RSpec::Core::RakeTask.new(:'snap-parallel' => 'snap-parallel:prepare') do |t|
  all_specs = FileList['./spec/**{,/*/**}/*_spec.rb'].sort
  specs_to_run = SnapCI::ParallelTests.partition(things: all_specs, total_workers: num_workers, current_worker_index: worker_index)

  if specs_to_run && specs_to_run.count > 0
    t.pattern = specs_to_run
  end
end

namespace :'snap-parallel' do
  types = begin
    dirs = Dir['./spec/**/*_spec.rb'].
      map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }.
      uniq.
      select { |f| File.directory?(f) }
    Hash[dirs.map { |d| [d.split('/').last, d] }]
  end

  task :prepare do
    ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
    if Rails.configuration.generators.options[:rails][:orm] == :active_record
      if Rake::Task.task_defined?('test:prepare')
        Rake::Task['test:prepare'].invoke
      end
    end
  end

  types.each do |type, dir|
    desc "Run the code examples in #{dir}"
    all_specs = FileList["./#{dir}/**/*_spec.rb"].sort

    RSpec::Core::RakeTask.new(type => 'snap-parallel:prepare') do |t|
      specs_to_run = SnapCI::ParallelTests.partition(things: all_specs, total_workers: num_workers, current_worker_index: worker_index)

      if specs_to_run && specs_to_run.count > 0
        t.pattern = specs_to_run
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
snap_ci-parallel_tests-0.1.0 lib/snap_ci/parallel_tests/tasks/parallel_specs.rake
snap_ci-parallel_tests-0.0.3 lib/snap_ci/parallel_tests/tasks/parallel_specs.rake
snap_ci-parallel_tests-0.0.2 lib/snap_ci/parallel_tests/tasks/parallel_specs.rake
snap_ci-parallel_tests-0.0.1 lib/snap_ci/parallel_tests/tasks/parallel_specs.rake