Sha256: f68a3a19e27f8b6cbeb306e54a18ee1ef2e210d67c73d3fb3d49a9f49a25fe33

Contents?: true

Size: 1.97 KB

Versions: 38

Compression:

Stored size: 1.97 KB

Contents

require "parallel_tests/test/runner"

module ParallelTests
  module RSpec
    class Runner < ParallelTests::Test::Runner
      DEV_NULL = (WINDOWS ? "NUL" : "/dev/null")
      NAME = 'RSpec'

      class << self
        def run_tests(test_files, process_number, num_processes, options)
          exe = executable # expensive, so we cache
          version = (exe =~ /\brspec\b/ ? 2 : 1)
          cmd = [exe, options[:test_options], (rspec_2_color if version == 2), spec_opts, *test_files].compact.join(" ")
          options = options.merge(:env => rspec_1_color) if version == 1
          execute_command(cmd, process_number, num_processes, options)
        end

        def determine_executable
          cmd = case
          when File.exist?("bin/rspec")
            WINDOWS ? "ruby bin/rspec" : "bin/rspec"
          when File.file?("script/spec")
            "script/spec"
          when ParallelTests.bundler_enabled?
            cmd = (run("bundle show rspec-core") =~ %r{Could not find gem.*} ? "spec" : "rspec")
            "bundle exec #{cmd}"
          else
            %w[spec rspec].detect{|cmd| system "#{cmd} --version > #{DEV_NULL} 2>&1" }
          end

          cmd or raise("Can't find executables rspec or spec")
        end

        def runtime_log
          'tmp/parallel_runtime_rspec.log'
        end

        def test_file_name
          "spec"
        end

        def test_suffix
          /_spec\.rb$/
        end

        private

        # so it can be stubbed....
        def run(cmd)
          `#{cmd}`
        end

        def rspec_1_color
          if $stdout.tty?
            {'RSPEC_COLOR' => "1"}
          else
            {}
          end
        end

        def rspec_2_color
          '--color --tty' if $stdout.tty?
        end

        def spec_opts
          options_file = ['.rspec_parallel', 'spec/parallel_spec.opts', 'spec/spec.opts'].detect{|f| File.file?(f) }
          return unless options_file
          "-O #{options_file}"
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
parallel_tests-2.9.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.8.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.7.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.7.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.6.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.5.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.4.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.4.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.3.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.3.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.2.2 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.2.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.2.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.1.2 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.1.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.1.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-2.0.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-1.9.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-1.8.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-1.7.1 lib/parallel_tests/rspec/runner.rb