lib/minitest/queue.rb in ci-queue-0.20.0 vs lib/minitest/queue.rb in ci-queue-0.20.1

- old
+ new

@@ -1,6 +1,7 @@ # frozen_string_literal: true +require 'shellwords' require 'minitest' require 'minitest/reporters' require 'minitest/queue/failure_formatter' require 'minitest/queue/error_report' @@ -100,9 +101,50 @@ end end end module Queue + attr_writer :run_command_formatter, :project_root + + def run_command_formatter + @run_command_formatter ||= if defined?(Railties) + RAILS_RUN_COMMAND_FORMATTER + else + DEFAULT_RUN_COMMAND_FORMATTER + end + end + + DEFAULT_RUN_COMMAND_FORMATTER = lambda do |runnable| + filename = Minitest::Queue.relative_path(runnable.source_location[0]) + identifier = "#{runnable.klass}##{runnable.name}" + ['bundle', 'exec', 'ruby', '-Ilib:test', filename, '-n', identifier] + end + + RAILS_RUN_COMMAND_FORMATTER = lambda do |runnable| + filename = Minitest::Queue.relative_path(runnable.source_location[0]) + lineno = runnable.source_location[1] + ['bin/rails', 'test', "#{filename}:#{lineno}"] + end + + def run_command_for_runnable(runnable) + command = run_command_formatter.call(runnable) + if command.is_a?(Array) + Shellwords.join(command) + else + command + end + end + + def self.project_root + @project_root ||= Dir.pwd + end + + def self.relative_path(path, root: project_root) + Pathname(path).relative_path_from(Pathname(root)).to_s + rescue ArgumentError + path + end + class SingleExample def initialize(runnable, method_name) @runnable = runnable @method_name = method_name