diff --git a/lib/bundle/cask_dumper.rb b/lib/bundle/cask_dumper.rb index 5468b3d7d..2a923b3bb 100644 --- a/lib/bundle/cask_dumper.rb +++ b/lib/bundle/cask_dumper.rb @@ -26,10 +26,10 @@ def dump(casks_required_by_formulae) def formula_dependencies(cask_list) return [] unless cask_list.present? - cask_info_response = `brew info --cask #{cask_list.join(" ")} --json=v1` + cask_info_response = `brew info --cask #{cask_list.join(" ")} --json=v2` cask_info = JSON.parse(cask_info_response) - cask_info.flat_map do |cask| + cask_info["casks"].flat_map do |cask| cask.dig("depends_on", "formula") end.compact.uniq rescue JSON::ParserError => e diff --git a/lib/bundle/locker.rb b/lib/bundle/locker.rb index ef0bf2fdc..5999d4fcc 100644 --- a/lib/bundle/locker.rb +++ b/lib/bundle/locker.rb @@ -87,7 +87,7 @@ def lock(entries, global: false, file: nil, no_lock: false) def brew_list_info @brew_list_info ||= begin - name_bottles = JSON.parse(`brew info --json=v1 --installed --quiet`) + name_bottles = JSON.parse(`brew info --json=v2 --installed --quiet`) .each_with_object({}) do |f, hash| bottle = f["bottle"]["stable"] bottle&.delete("rebuild") diff --git a/spec/bundle/cask_dumper_spec.rb b/spec/bundle/cask_dumper_spec.rb index 4c3c6b607..5fc33b6d3 100644 --- a/spec/bundle/cask_dumper_spec.rb +++ b/spec/bundle/cask_dumper_spec.rb @@ -57,8 +57,8 @@ before do allow(described_class) .to receive(:`) - .with("brew info --cask foo --json=v1") - .and_return("[{\"depends_on\":{}}]") + .with("brew info --cask foo --json=v2") + .and_return("{\"formulae\":[],\"casks\":[]") end it "returns an empty array" do @@ -70,8 +70,8 @@ before do allow(described_class) .to receive(:`) - .with("brew info --cask foo --json=v1") - .and_return("Error: somethng from cask!") + .with("brew info --cask foo --json=v2") + .and_return("Error: something from cask!") end it "returns an empty array" do @@ -80,11 +80,18 @@ end context "when multiple casks have the same dependency" do + let(:json_output) do + "{" \ + "\"formulae\":[]," \ + "\"casks\":[{\"depends_on\":{\"formula\":[\"baz\",\"qux\"]}},{\"depends_on\":{\"formula\":[\"baz\"]}}]" \ + "}" + end + before do allow(described_class) .to receive(:`) - .with("brew info --cask foo bar --json=v1") - .and_return("[{\"depends_on\":{\"formula\":[\"baz\",\"qux\"]}},{\"depends_on\":{\"formula\":[\"baz\"]}}]") + .with("brew info --cask foo bar --json=v2") + .and_return(json_output) end it "returns an array of unique formula dependencies" do diff --git a/spec/bundle/locker_spec.rb b/spec/bundle/locker_spec.rb index 564ce1ab4..f7aff50ab 100644 --- a/spec/bundle/locker_spec.rb +++ b/spec/bundle/locker_spec.rb @@ -70,7 +70,7 @@ allow(locker).to receive(:lockfile).and_return(lockfile) allow(brew_options).to receive(:deep_stringify_keys) .and_return("restart_service" => true) - allow(locker).to receive(:`).with("brew info --json=v1 --installed --quiet").and_return <<~EOS + allow(locker).to receive(:`).with("brew info --json=v2 --installed --quiet").and_return <<~EOS [ { "name":"mysql",