mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
The Manjaro workspace job failed test-unit-ruby with "cannot load such file -- minitest". Debian vendors minitest in libruby, but Arch ships it as ruby-minitest and Fedora and CentOS Stream as rubygem-minitest, none of which ruby pulls in. ensure_ruby_present now probes `require "minitest"` and installs the distro package when the probe fails, then fails loudly if minitest is still missing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
85 lines
3.2 KiB
Python
85 lines
3.2 KiB
Python
"""Unit tests for :mod:`utils.install.ruby`."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
import unittest.mock as mock
|
|
|
|
from utils.install import ruby as ruby_mod
|
|
|
|
|
|
class TestEnsureRubyPresent(unittest.TestCase):
|
|
def test_provisions_ruby_then_minitest(self) -> None:
|
|
calls = mock.Mock()
|
|
with (
|
|
mock.patch.object(ruby_mod, "ensure_command_present", calls.ruby),
|
|
mock.patch.object(ruby_mod, "ensure_minitest_present", calls.minitest),
|
|
):
|
|
ruby_mod.ensure_ruby_present()
|
|
self.assertEqual(
|
|
calls.mock_calls, [mock.call.ruby("ruby"), mock.call.minitest()]
|
|
)
|
|
|
|
def test_propagates_the_hard_failure(self) -> None:
|
|
with (
|
|
mock.patch.object(
|
|
ruby_mod, "ensure_command_present", side_effect=RuntimeError("boom")
|
|
),
|
|
mock.patch.object(ruby_mod, "ensure_minitest_present") as minitest,
|
|
self.assertRaises(RuntimeError),
|
|
):
|
|
ruby_mod.ensure_ruby_present()
|
|
minitest.assert_not_called()
|
|
|
|
|
|
class TestEnsureMinitestPresent(unittest.TestCase):
|
|
def run_with(self, *, loadable: list[bool], manager: str) -> mock.Mock:
|
|
"""Run ``ensure_minitest_present`` with stubbed probe and installer.
|
|
|
|
Args:
|
|
loadable: successive results of the minitest probe.
|
|
manager: package manager the host reports.
|
|
|
|
Returns:
|
|
The stubbed ``install_package_candidates``.
|
|
"""
|
|
with (
|
|
mock.patch.object(ruby_mod, "minitest_loadable", side_effect=loadable),
|
|
mock.patch.object(ruby_mod, "detect_package_manager", return_value=manager),
|
|
mock.patch.object(ruby_mod, "install_package_candidates") as install,
|
|
mock.patch.object(ruby_mod, "log"),
|
|
):
|
|
ruby_mod.ensure_minitest_present()
|
|
return install
|
|
|
|
def test_a_loadable_minitest_installs_nothing(self) -> None:
|
|
install = self.run_with(loadable=[True], manager="pacman")
|
|
install.assert_not_called()
|
|
|
|
def test_arch_installs_ruby_minitest(self) -> None:
|
|
install = self.run_with(loadable=[False, True], manager="pacman")
|
|
install.assert_called_once_with("pacman", ["ruby-minitest"])
|
|
|
|
def test_the_redhat_family_installs_rubygem_minitest(self) -> None:
|
|
install = self.run_with(loadable=[False, True], manager="dnf")
|
|
install.assert_called_once_with("dnf", ["rubygem-minitest"])
|
|
|
|
def test_still_missing_after_the_install_fails_loudly(self) -> None:
|
|
with self.assertRaises(RuntimeError):
|
|
self.run_with(loadable=[False, False], manager="pacman")
|
|
|
|
def test_an_unmapped_manager_fails_without_installing(self) -> None:
|
|
with (
|
|
mock.patch.object(ruby_mod, "minitest_loadable", return_value=False),
|
|
mock.patch.object(ruby_mod, "detect_package_manager", return_value="brew"),
|
|
mock.patch.object(ruby_mod, "install_package_candidates") as install,
|
|
mock.patch.object(ruby_mod, "log"),
|
|
self.assertRaises(RuntimeError),
|
|
):
|
|
ruby_mod.ensure_minitest_present()
|
|
install.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|