diff --git a/Library/Homebrew/bundle/brew_services.rb b/Library/Homebrew/bundle/brew_services.rb index 4b0bf81c85151..c20eff3c97312 100644 --- a/Library/Homebrew/bundle/brew_services.rb +++ b/Library/Homebrew/bundle/brew_services.rb @@ -63,11 +63,11 @@ def started_services if !Homebrew::Services::System.launchctl? && !Homebrew::Services::System.systemctl? odie Homebrew::Services::System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE end - states_to_skip = %w[stopped none] + states_to_skip = [:stopped, :none] - services_list = JSON.parse(Utils.safe_popen_read(HOMEBREW_BREW_FILE, "services", "list", "--json")) - services_list.filter_map do |hash| - hash.fetch("name") if states_to_skip.exclude?(hash.fetch("status")) + require "services/formulae" + Homebrew::Services::Formulae.services_list.filter_map do |hash| + hash.fetch(:name) if states_to_skip.exclude?(hash.fetch(:status)) end end end diff --git a/Library/Homebrew/test/bundle/brew_services_spec.rb b/Library/Homebrew/test/bundle/brew_services_spec.rb index 7437659e57cc8..e6154c4bfc554 100644 --- a/Library/Homebrew/test/bundle/brew_services_spec.rb +++ b/Library/Homebrew/test/bundle/brew_services_spec.rb @@ -2,6 +2,7 @@ require "bundle" require "bundle/brew_services" +require "services/formulae" RSpec.describe Homebrew::Bundle::Brew::Services do describe ".started_services" do @@ -10,27 +11,27 @@ end it "returns started services" do - allow(Utils).to receive(:safe_popen_read).and_return <<~EOS + allow(Homebrew::Services::Formulae).to receive(:services_list).and_return( [ { - "name": "nginx", - "status": "started" + name: "nginx", + status: :started, }, { - "name": "apache", - "status": "stopped" + name: "apache", + status: :stopped, }, { - "name": "mysql", - "status": "started" - } - ] - EOS + name: "mysql", + status: :started, + }, + ], + ) expect(described_class.started_services).to contain_exactly("nginx", "mysql") end it "returns empty array when no services exist" do - allow(Utils).to receive(:safe_popen_read).and_return("[]\n") + allow(Homebrew::Services::Formulae).to receive(:services_list).and_return([]) expect(described_class.started_services).to eq([]) end diff --git a/Library/Homebrew/test/bundle/brew_spec.rb b/Library/Homebrew/test/bundle/brew_spec.rb index 4b1fc953838df..c8a8d5ed5c804 100644 --- a/Library/Homebrew/test/bundle/brew_spec.rb +++ b/Library/Homebrew/test/bundle/brew_spec.rb @@ -5,6 +5,7 @@ require "bundle/brew_services" require "tsort" require "formula" +require "services/formulae" require "tab" require "utils/bottles" @@ -224,7 +225,7 @@ describe "#dump" do it "returns a dump string with installed formulae" do expect(Formula).to receive(:installed).and_return([foo, bar, baz]) - allow(Utils).to receive(:safe_popen_read).and_return("[]") + allow(Homebrew::Services::Formulae).to receive(:services_list).and_return([]) expected = <<~EOS # barfoo brew "bar"