Mike McQuaid c82518032e
Fix services types
Some of the typing/`T.must` usage when moving the
Homebrew/homebrew-services code to Homebrew/brew was not quite correct.

Rather than trying to make everything `strict` and import at the same
time: let's mostly loosen the typing to fix a few bugs and allow us to
add more later.
2025-03-14 16:53:07 +00:00

46 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require "services/commands/restart"
RSpec.describe Homebrew::Services::Commands::Restart do
describe "#TRIGGERS" do
it "contains all restart triggers" do
expect(described_class::TRIGGERS).to eq(%w[restart relaunch reload r])
end
end
describe "#run" do
it "fails with empty list" do
expect do
described_class.run([], verbose: false)
end.to raise_error UsageError, "Invalid usage: Formula(e) missing, please provide a formula name or use --all"
end
it "starts if services are not loaded" do
expect(Homebrew::Services::Cli).not_to receive(:run)
expect(Homebrew::Services::Cli).not_to receive(:stop)
expect(Homebrew::Services::Cli).to receive(:start).once
service = instance_double(Homebrew::Services::FormulaWrapper, service_name: "name", loaded?: false)
expect { described_class.run([service], verbose: false) }.not_to raise_error
end
it "starts if services are loaded with file" do
expect(Homebrew::Services::Cli).not_to receive(:run)
expect(Homebrew::Services::Cli).to receive(:start).once
expect(Homebrew::Services::Cli).to receive(:stop).once
service = instance_double(Homebrew::Services::FormulaWrapper, service_name: "name", loaded?: true,
service_file_present?: true)
expect { described_class.run([service], verbose: false) }.not_to raise_error
end
it "runs if services are loaded without file" do
expect(Homebrew::Services::Cli).not_to receive(:start)
expect(Homebrew::Services::Cli).to receive(:run).once
expect(Homebrew::Services::Cli).to receive(:stop).once
service = instance_double(Homebrew::Services::FormulaWrapper, service_name: "name", loaded?: true,
service_file_present?: false)
expect { described_class.run([service], verbose: false) }.not_to raise_error
end
end
end