Refactor MissingFormula spec.

This commit is contained in:
Markus Reiter 2018-04-14 01:39:00 +02:00
parent 5e2d4d52ba
commit 16fb563d49
7 changed files with 42 additions and 78 deletions

View File

@ -88,3 +88,7 @@ Style/HashSyntax:
# so many of these in formulae but none in here # so many of these in formulae but none in here
Style/TrailingBodyOnMethodDefinition: Style/TrailingBodyOnMethodDefinition:
Enabled: true Enabled: true
Rspec/ExpectActual:
Exclude:
- 'test/missing_formula_spec.rb'

View File

@ -60,7 +60,7 @@ module Homebrew
rescue FormulaUnavailableError => e rescue FormulaUnavailableError => e
ofail e.message ofail e.message
# No formula with this name, try a missing formula lookup # No formula with this name, try a missing formula lookup
if (reason = Homebrew::MissingFormula.reason(f)) if (reason = MissingFormula.reason(f))
$stderr.puts reason $stderr.puts reason
end end
end end

View File

@ -257,7 +257,7 @@ module Homebrew
end end
ofail e.message ofail e.message
if (reason = Homebrew::MissingFormula.reason(e.name)) if (reason = MissingFormula.reason(e.name))
$stderr.puts reason $stderr.puts reason
return return
end end

View File

@ -64,7 +64,7 @@ module Homebrew
count = local_results.length + tap_results.length count = local_results.length + tap_results.length
ohai "Searching blacklisted, migrated and deleted formulae..." ohai "Searching blacklisted, migrated and deleted formulae..."
if reason = Homebrew::MissingFormula.reason(query, silent: true) if reason = MissingFormula.reason(query, silent: true)
if count.positive? if count.positive?
puts puts
puts "If you meant #{query.inspect} specifically:" puts "If you meant #{query.inspect} specifically:"

View File

@ -308,7 +308,7 @@ class FormulaAuditor
name = formula.name name = formula.name
if Homebrew::MissingFormula.blacklisted_reason(name) if MissingFormula.blacklisted_reason(name)
problem "'#{name}' is blacklisted." problem "'#{name}' is blacklisted."
end end

View File

@ -65,7 +65,7 @@ module Homebrew
# Don't allow blacklisted formula, or names that shadow aliases, # Don't allow blacklisted formula, or names that shadow aliases,
# unless --force is specified. # unless --force is specified.
unless ARGV.force? unless ARGV.force?
if reason = Homebrew::MissingFormula.blacklisted_reason(fc.name) if reason = MissingFormula.blacklisted_reason(fc.name)
raise "#{fc.name} is blacklisted for creation.\n#{reason}\nIf you really want to create this formula use --force." raise "#{fc.name} is blacklisted for creation.\n#{reason}\nIf you really want to create this formula use --force."
end end

View File

@ -1,117 +1,77 @@
require "missing_formula" require "missing_formula"
describe Homebrew::MissingFormula do describe Homebrew::MissingFormula do
context "::reason" do describe "::reason" do
subject { described_class.reason("gem") } subject { described_class.reason("gem") }
it { is_expected.not_to be_nil } it { is_expected.not_to be_nil }
end end
context "::blacklisted_reason" do describe "::blacklisted_reason" do
matcher(:be_blacklisted) do matcher :be_blacklisted do
match do |expected| match do |expected|
described_class.blacklisted_reason(expected) described_class.blacklisted_reason(expected)
end end
end end
context "rubygems" do specify "RubyGems is blacklisted" do
%w[gem rubygem rubygems].each do |s| expect(%w[gem rubygem rubygems]).to all be_blacklisted
subject { s }
it { is_expected.to be_blacklisted }
end
end end
context "latex" do specify "LaTeX is blacklisted" do
%w[latex tex tex-live texlive TexLive].each do |s| expect(%w[latex tex tex-live texlive TexLive]).to all be_blacklisted
subject { s }
it { is_expected.to be_blacklisted }
end
end end
context "pip" do specify "pip is blacklisted" do
subject { "pip" } expect("pip").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "pil" do specify "PIL is blacklisted" do
subject { "pil" } expect("pil").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "macruby" do specify "MacRuby is blacklisted" do
subject { "MacRuby" } expect("MacRuby").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "lzma" do specify "lzma is blacklisted" do
%w[lzma liblzma].each do |s| expect(%w[lzma liblzma]).to all be_blacklisted
subject { s }
it { is_expected.to be_blacklisted }
end
end end
context "gtest" do specify "gtest is blacklisted" do
%w[gtest googletest google-test].each do |s| expect(%w[gtest googletest google-test]).to all be_blacklisted
subject { s }
it { is_expected.to be_blacklisted }
end
end end
context "gmock" do specify "gmock is blacklisted" do
%w[gmock googlemock google-mock].each do |s| expect(%w[gmock googlemock google-mock]).to all be_blacklisted
subject { s }
it { is_expected.to be_blacklisted }
end
end end
context "sshpass" do specify "sshpass is blacklisted" do
subject { "sshpass" } expect("sshpass").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "gsutil" do specify "gsutil is blacklisted" do
subject { "gsutil" } expect("gsutil").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "gfortran" do specify "gfortran is blacklisted" do
subject { "gfortran" } expect("gfortran").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "play" do specify "play is blacklisted" do
subject { "play" } expect("play").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "haskell-platform" do specify "haskell-platform is blacklisted" do
subject { "haskell-platform" } expect("haskell-platform").to be_blacklisted
it { is_expected.to be_blacklisted }
end end
context "xcode", :needs_macos do specify "Xcode is blacklisted", :needs_macos do
%w[xcode Xcode].each do |s| expect(%w[xcode Xcode]).to all be_blacklisted
subject { s }
it { is_expected.to be_blacklisted }
end
end end
end end
context "::tap_migration_reason" do describe "::tap_migration_reason" do
subject { described_class.tap_migration_reason(formula) } subject { described_class.tap_migration_reason(formula) }
before do before do
@ -136,7 +96,7 @@ describe Homebrew::MissingFormula do
end end
end end
context "::deleted_reason" do describe "::deleted_reason" do
subject { described_class.deleted_reason(formula, silent: true) } subject { described_class.deleted_reason(formula, silent: true) }
before do before do