File: rspec_runner

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (66 lines) | stat: -rwxr-xr-x 2,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'rubygems'
require 'rspec'
require 'rspec/core/formatters/progress_formatter'
require 'rspec/core/runner'

# Disable ruby verbosity
# We need control over output so that the parallel task can parse it correctly
$VERBOSE = nil

module Parallel
  module RSpec
    #
    # Responsible for formatting output.
    # This differs from the built-in progress formatter by not appending an index to failures.
    #
    class Formatter < ::RSpec::Core::Formatters::ProgressFormatter
      ::RSpec::Core::Formatters.register self, :dump_failure
      def dump_failure(example, _)
        # Unlike the super class implementation, do not print the failure number
        output.puts "#{short_padding}#{example.full_description}"
        dump_failure_info(example)
      end
    end

    #
    # Responsible for running spec files given a spec file.
    # Can supply an optional list of additional options (used when running in CI).
    # We do it this way so that we can run very long spec file lists on Windows, since
    # Windows has a limited argument length depending on method of invocation.
    #
    class Runner
      def initialize(specs_file, options = [])
        abort "error: spec list file '#{specs_file}' does not exist." unless File.exist? specs_file
        if options.empty?
          @options = ['-fParallel::RSpec::Formatter']
        else
          @options = options
        end
        File.readlines(specs_file).each { |line| @options << line.chomp }
      end

      def run
        @options = ::RSpec::Core::ConfigurationOptions.new(@options)
        ::RSpec::Core::Runner.new(@options).run($stderr, $stdout)
      end
    end
  end
end

def print_usage
  puts 'usage: rspec_runner <spec_list_file> [<rspec_options_string>]'
end

if __FILE__ == $PROGRAM_NAME
  if ARGV.length < 1
    print_usage
  elsif ARGV.length == 1
    exit Parallel::RSpec::Runner.new(ARGV[0]).run
  else
    spec_file, *options = ARGV
    exit Parallel::RSpec::Runner.new(spec_file, options).run
  end
end