Class: Henitai::Integration::Rspec

Inherits:
Base
  • Object
show all
Includes:
MutantRunSupport, RspecChildRunner, RspecTestSelection
Defined in:
lib/henitai/integration.rb

Overview

RSpec integration adapter.

Constant Summary collapse

DEFAULT_SUITE_TIMEOUT =
300.0

Constants included from RspecTestSelection

Henitai::Integration::RspecTestSelection::REQUIRE_DIRECTIVE_PATTERN

Instance Method Summary collapse

Methods included from RspecTestSelection

#select_tests

Methods included from MutantRunSupport

#build_result, #mutant_log_name, #run_in_child, #run_mutant, #scenario_log_paths, #spawn_mutant

Methods inherited from Base

#cleanup_process_group, #reap_child, #run_mutant, #select_tests, #spawn_mutant, #wait_with_timeout

Instance Method Details

#per_test_coverage_supported?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/henitai/integration.rb', line 57

def per_test_coverage_supported?
  true
end

#rspec_suite_runner_scriptObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/henitai/integration.rb', line 74

def rspec_suite_runner_script
  <<~RUBY
    require "rspec/core"

    test_files = ARGV.map { |file| File.expand_path(file) }
    config = RSpec.configuration
    options = RSpec::Core::ConfigurationOptions.new(
      ["--format", "progress", "--format", "Henitai::CoverageFormatter"]
    )
    runner = RSpec::Core::Runner.send(:new, options)

    RSpec::Core::Runner.send(:trap_interrupt)
    runner.send(:configure, $stderr, $stdout)
    config.files_to_run = test_files
    config.load_spec_files

    status = runner.send(:run_specs, RSpec.world.ordered_example_groups)
    exit(status.is_a?(Integer) ? status : (status == true ? 0 : 1))
  RUBY
end

#run_suite(test_files, timeout: DEFAULT_SUITE_TIMEOUT) ⇒ Object



61
62
63
# File 'lib/henitai/integration.rb', line 61

def run_suite(test_files, timeout: DEFAULT_SUITE_TIMEOUT)
  RspecProcessRunner.new.run_suite(self, test_files, timeout:)
end

#spawn_suite_process(test_files, log_paths) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/henitai/integration.rb', line 95

def spawn_suite_process(test_files, log_paths)
  File.open(log_paths[:stdout_path], "w") do |stdout_file|
    File.open(log_paths[:stderr_path], "w") do |stderr_file|
      Process.spawn(
        subprocess_env,
        *suite_command(test_files),
        out: stdout_file,
        err: stderr_file,
        pgroup: true
      )
    end
  end
end

#suite_command(test_files) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/henitai/integration.rb', line 65

def suite_command(test_files)
  [
    "bundle", "exec", "ruby",
    "-r", "henitai/rspec_coverage_formatter",
    "-e", rspec_suite_runner_script,
    *test_files
  ]
end

#test_filesObject



55
# File 'lib/henitai/integration.rb', line 55

def test_files = spec_files