Module: SimpleCov::CLI::Run

Defined in:
lib/simplecov/cli/run.rb

Overview

‘simplecov run <command…>` — exec the given command with simplecov auto-loaded so a coverage report drops into the project’s coverage/ directory at the end. Useful for projects without a test_helper that already calls SimpleCov.start (e.g. plain ‘bundle exec rake test` on an unconfigured library).

Constant Summary collapse

AUTOSTART =
File.expand_path("../autostart", __dir__)

Class Method Summary collapse

Class Method Details

.rubyopt_envObject



28
29
30
31
32
33
# File 'lib/simplecov/cli/run.rb', line 28

def rubyopt_env
  existing = ENV["RUBYOPT"].to_s.strip
  injection = "-r#{AUTOSTART}"
  merged = existing.empty? ? injection : "#{existing} #{injection}"
  ENV.to_hash.merge("RUBYOPT" => merged)
end

.run(args, stderr:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simplecov/cli/run.rb', line 15

def run(args, stderr:, **)
  cmd = args.first == "--" ? args.drop(1) : args
  if cmd.empty?
    stderr.puts("simplecov run: missing command")
    return 1
  end

  Kernel.exec(rubyopt_env, *cmd)
rescue Errno::ENOENT => e
  stderr.puts("simplecov run: #{e.message}")
  127
end