Updated PR in response to suggestions

- changed require_relative to require
    - removed useless begin
    - removed unnecessary test
    - updated brew info positive test case to verify a cask was found
    - moved cask search logic to missing_formula.rb
This commit is contained in:
Zach Auten 2019-01-16 20:50:44 -05:00
parent 468496b5ff
commit abb81a52e6
3 changed files with 18 additions and 26 deletions

View File

@ -42,10 +42,6 @@ require "formula"
require "keg" require "keg"
require "tab" require "tab"
require "json" require "json"
require_relative "../cask/cmd/abstract_command"
require_relative "../cask/cmd/info"
require_relative "../cask/cask_loader"
require_relative "../cask/installer"
module Homebrew module Homebrew
module_function module_function
@ -130,11 +126,6 @@ module Homebrew
if (reason = MissingFormula.reason(f)) if (reason = MissingFormula.reason(f))
$stderr.puts reason $stderr.puts reason
end end
begin
ohai "Searching for a cask with the name \"#{f}\""
cask = Cask::CaskLoader.load(f)
Cask::Cmd::Info.info(cask)
end
end end
end end
end end

View File

@ -1,9 +1,15 @@
require "formulary" require "formulary"
require "cask/cmd/abstract_command"
require "cask/cmd/info"
require "cask/cask_loader"
require "cask/installer"
module Homebrew module Homebrew
module MissingFormula module MissingFormula
class << self class << self
def reason(name, silent: false) def reason(name, silent: false)
search_for_cask(name)
rescue
blacklisted_reason(name) || tap_migration_reason(name) || blacklisted_reason(name) || tap_migration_reason(name) ||
deleted_reason(name, silent: silent) deleted_reason(name, silent: silent)
end end
@ -167,6 +173,11 @@ module Homebrew
end end
end end
def search_for_cask(name)
cask = Cask::CaskLoader.load(name)
Cask::Cmd::Info.info(cask)
end
require "extend/os/missing_formula" require "extend/os/missing_formula"
end end
end end

View File

@ -19,22 +19,12 @@ describe "brew info", :integration_test do
.and be_a_success .and be_a_success
end end
it "looks for a Cask with the same name if a given Formula does not exist" do it "looks for a Cask with the same name if a given Formula does not exist", :needs_network do
expect { brew "info", "basic-cask" } setup_remote_tap "homebrew/cask"
.to output(/Searching for a cask with the name "basic-cask"/).to_stdout
.and output(/No available formula with the name "basic-cask"/).to_stderr
end
it "does not look for a Cask if a given Formula exists" do expect { brew "info", "firefox" }
RSpec::Matchers.define_negated_matcher :not_output, :output .to output(/No available formula with the name "firefox"/).to_stderr
expect { brew "info", "testball" } .and output(/firefox/).to_stdout
.to not_output(/Searching for a cask with the name "testball"/).to_stdout
.and not_to_output.to_stderr
end
it "prints an error message if a given Cask does not exist" do
expect { brew "info", "non_existant_cask" }
.to output(/No Cask with this name exists./).to_stderr
end end
end end