Sha256: 53eefd23e0105de9d8b3ee91317768953449a819cf1848f257c7b6c41afb88b4

Contents?: true

Size: 1.59 KB

Versions: 19

Compression:

Stored size: 1.59 KB

Contents

require 'parallel_tests/test/runner'

module ParallelTests
  module RSpec
    class Runner < ParallelTests::Test::Runner
      def self.run_tests(test_files, process_number, options)
        exe = executable # expensive, so we cache
        version = (exe =~ /\brspec\b/ ? 2 : 1)
        cmd = "#{rspec_1_color if version == 1}#{exe} #{options[:test_options]} #{rspec_2_color if version == 2}#{spec_opts} #{test_files*' '}"
        execute_command(cmd, process_number, options)
      end

      def self.executable
        cmd = if File.file?("script/spec")
          "script/spec"
        elsif ParallelTests.bundler_enabled?
          cmd = (run("bundle show rspec") =~ %r{/rspec-1[^/]+$} ? "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 self.runtime_log
        'tmp/parallel_runtime_rspec.log'
      end

      def self.test_file_name
        "spec"
      end

      def self.test_suffix
        "_spec.rb"
      end

      private

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

      def self.rspec_1_color
        'RSPEC_COLOR=1 ; export RSPEC_COLOR ;' if $stdout.tty?
      end

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

      def self.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

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
friendlyfashion-parallel_tests-0.9.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.9.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.9.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.14 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.13 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.12 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.11 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.10 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.9 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.8 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.7 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.6 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.5 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.4 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.3 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.2 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.1 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.8.0 lib/parallel_tests/rspec/runner.rb
parallel_tests-0.7.4 lib/parallel_tests/rspec/runner.rb