class CIHelper::Commands::RunSpecs

Public Instance Methods

call() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 6
def call
  return if job_files.empty?

  create_and_migrate_database! if with_database?
  execute("bundle exec rspec #{Shellwords.join(job_files)}")
  return 0 unless split_resultset?

  execute("mv coverage/.resultset.json coverage/resultset.#{job_index}.json")
end

Private Instance Methods

env() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 18
def env
  :test
end
job_count() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 35
def job_count
  @job_count ||= options[:node_total]&.to_i || 1
end
job_files() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 22
def job_files
  all_files = path.glob("spec/**/*_spec.rb")
  sorted_files =
    all_files.map { |x| [x.size, x.relative_path_from(path).to_s] }.sort.map(&:last)
  sorted_files.reverse.select.with_index do |_file, index|
    (index % job_count) == (job_index - 1)
  end
end
job_index() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 31
def job_index
  @job_index ||= options[:node_index]&.to_i || 1
end
split_resultset?() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 43
def split_resultset?
  boolean_option(:split_resultset)
end
with_database?() click to toggle source
# File lib/ci_helper/commands/run_specs.rb, line 39
def with_database?
  boolean_option(:with_database)
end