Class: Testprune::Runner
- Inherits:
-
Object
- Object
- Testprune::Runner
- Defined in:
- lib/testprune/runner.rb
Overview
Boots the target project’s suite in a subprocess, instrumented so the adapters capture per-test coverage. Reuses the gem’s lib via RUBYOPT (-I) so the target project does not need testprune in its Gemfile.
Constant Summary collapse
- TEST_PROGRESS_RE =
Progress-line patterns: match single-char Minitest/RSpec progress indicators.
/\A[.FES*P]+\z/- ERROR_RE =
Lines that indicate a test error or failure.
/Error:|FAILED|Failure:|error:/
Instance Method Summary collapse
-
#call(explicit_command = nil, verbose: false) ⇒ Object
explicit_command: array form of a user-supplied test command (after ‘–`), or nil.
- #command_for_paths(paths) ⇒ Object
-
#initialize(config) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(config) ⇒ Runner
Returns a new instance of Runner.
19 20 21 |
# File 'lib/testprune/runner.rb', line 19 def initialize(config) @config = config end |
Instance Method Details
#call(explicit_command = nil, verbose: false) ⇒ Object
explicit_command: array form of a user-supplied test command (after ‘–`), or nil. verbose: when true, stream raw output directly (no capture, no spinner).
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/testprune/runner.rb', line 25 def call(explicit_command = nil, verbose: false) framework, command = resolve(explicit_command) FileUtils.mkdir_p(@config.output_dir) File.delete(@config.run_file) if File.exist?(@config.run_file) if verbose warn("testprune: framework=#{framework} running: #{command.join(' ')}") ok = system(env, *command, chdir: @config.root) else ok = run_captured(framework, command) end unless File.exist?(@config.run_file) raise Error, 'suite finished but no run.json was captured — the adapter may ' \ 'not have loaded. Check the framework/command and source paths.' end count = begin JSON.parse(File.read(@config.run_file)).fetch('tests', []).size rescue JSON::ParserError '(unreadable — suite may have been interrupted mid-write)' end unless verbose warn("testprune: captured #{count} test(s) -> #{@config.run_file}") end ok end |
#command_for_paths(paths) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/testprune/runner.rb', line 56 def command_for_paths(paths) bundler = File.exist?(File.join(@config.root, 'Gemfile')) prefix = bundler ? %w[bundle exec] : [] if File.directory?(File.join(@config.root, 'spec')) prefix + %w[rspec] + paths elsif File.exist?(File.join(@config.root, 'bin', 'rails')) prefix + %w[rails test] + paths else prefix + %w[rake test] + paths end end |