Module: Ace::TestSupport::Fixtures::TestRunnerMocks

Defined in:
lib/ace/test_support/fixtures/test_runner_mocks.rb

Overview

Shared mock fixtures for ace-test-runner testing Used to stub subprocess execution and speed up integration tests

Class Method Summary collapse

Class Method Details

.mock_failure_statusObject

Standard failure status object for Open3.capture3

Returns:

  • (Object)

    Mock status with success? => false



66
67
68
69
70
71
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 66

def self.mock_failure_status
  status = Object.new
  status.define_singleton_method(:success?) { false }
  status.define_singleton_method(:exitstatus) { 1 }
  status
end

.mock_package_not_found_error(path) ⇒ String

Mock error output for package not found

Parameters:

  • path (String)

    The invalid package path

Returns:

  • (String)

    Mock error output



48
49
50
51
52
53
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 48

def self.mock_package_not_found_error(path)
  <<~OUTPUT
    Error: Package not found: #{path}
    Directory does not exist or is not a valid package
  OUTPUT
end

.mock_profile_outputString

Mock profile output (slowest tests)

Returns:

  • (String)

    Mock profile header



27
28
29
30
31
32
33
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 27

def self.mock_profile_output
  <<~OUTPUT

    Slowest Tests:
    =============
  OUTPUT
end

.mock_success_output(package: "ace-bundle", test_count: 2, assertion_count: 4) ⇒ String

Standard successful test run output

Parameters:

  • package (String) (defaults to: "ace-bundle")

    The package name (default: “ace-bundle”)

  • test_count (Integer) (defaults to: 2)

    Number of tests run (default: 2)

  • assertion_count (Integer) (defaults to: 4)

    Number of assertions (default: 4)

Returns:

  • (String)

    Mock test output



16
17
18
19
20
21
22
23
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 16

def self.mock_success_output(package: "ace-bundle", test_count: 2, assertion_count: 4)
  <<~OUTPUT
    Running tests in #{package}
    #{"." * test_count}
    Finished tests in 0.001s
    #{test_count} tests, #{assertion_count} assertions, 0 failures
  OUTPUT
end

.mock_success_statusObject

Standard success status object for Open3.capture3

Returns:

  • (Object)

    Mock status with success? => true



57
58
59
60
61
62
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 57

def self.mock_success_status
  status = Object.new
  status.define_singleton_method(:success?) { true }
  status.define_singleton_method(:exitstatus) { 0 }
  status
end

.mock_unknown_target_error(target) ⇒ String

Mock error output for unknown target

Parameters:

  • target (String)

    The unknown target name

Returns:

  • (String)

    Mock error output



38
39
40
41
42
43
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 38

def self.mock_unknown_target_error(target)
  <<~OUTPUT
    Error: Unknown target '#{target}'
    No matching files found for pattern: #{target}
  OUTPUT
end

.stub_test_run(output: mock_success_output, success: true) { ... } ⇒ Object

Stub Open3.capture3 for test runner execution

Parameters:

  • output (String) (defaults to: mock_success_output)

    The mock output (default: success output)

  • success (Boolean) (defaults to: true)

    Whether the mock should succeed (default: true)

Yields:

  • Block where the stub is active



77
78
79
80
81
82
# File 'lib/ace/test_support/fixtures/test_runner_mocks.rb', line 77

def self.stub_test_run(output: mock_success_output, success: true)
  status = success ? mock_success_status : mock_failure_status
  Open3.stub(:capture3, [output, "", status]) do
    yield
  end
end