style: remove RSpec/NamedSubject violations

This commit is contained in:
Rylan Polster 2021-01-31 13:14:23 -05:00
parent 3e00b3ea28
commit af40e072b0
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
47 changed files with 744 additions and 714 deletions

View File

@ -4,9 +4,9 @@
require "extend/ENV" require "extend/ENV"
shared_examples EnvActivation do shared_examples EnvActivation do
subject { env.extend(described_class) } subject(:env) { env_activation.extend(described_class) }
let(:env) { {}.extend(EnvActivation) } let(:env_activation) { {}.extend(EnvActivation) }
it "supports switching compilers" do it "supports switching compilers" do
subject.clang subject.clang
@ -180,28 +180,28 @@ describe Superenv do
include_examples EnvActivation include_examples EnvActivation
it "initializes deps" do it "initializes deps" do
expect(subject.deps).to eq([]) expect(env.deps).to eq([])
expect(subject.keg_only_deps).to eq([]) expect(env.keg_only_deps).to eq([])
end end
describe "#cxx11" do describe "#cxx11" do
it "supports gcc-5" do it "supports gcc-5" do
subject["HOMEBREW_CC"] = "gcc-5" env["HOMEBREW_CC"] = "gcc-5"
subject.cxx11 env.cxx11
expect(subject["HOMEBREW_CCCFG"]).to include("x") expect(env["HOMEBREW_CCCFG"]).to include("x")
end end
example "supports gcc-6" do example "supports gcc-6" do
subject["HOMEBREW_CC"] = "gcc-6" env["HOMEBREW_CC"] = "gcc-6"
subject.cxx11 env.cxx11
expect(subject["HOMEBREW_CCCFG"]).to include("x") expect(env["HOMEBREW_CCCFG"]).to include("x")
end end
it "supports clang" do it "supports clang" do
subject["HOMEBREW_CC"] = "clang" env["HOMEBREW_CC"] = "clang"
subject.cxx11 env.cxx11
expect(subject["HOMEBREW_CCCFG"]).to include("x") expect(env["HOMEBREW_CCCFG"]).to include("x")
expect(subject["HOMEBREW_CCCFG"]).to include("g") expect(env["HOMEBREW_CCCFG"]).to include("g")
end end
end end
end end

View File

@ -43,11 +43,11 @@ describe BuildEnvironment do
end end
describe BuildEnvironment::DSL do describe BuildEnvironment::DSL do
subject { double.extend(described_class) } subject(:build_environment_dsl) { double.extend(described_class) }
context "single argument" do context "single argument" do
before do before do
subject.instance_eval do build_environment_dsl.instance_eval do
env :userpaths env :userpaths
end end
end end
@ -57,7 +57,7 @@ describe BuildEnvironment do
context "multiple arguments" do context "multiple arguments" do
before do before do
subject.instance_eval do build_environment_dsl.instance_eval do
env :userpaths, :std env :userpaths, :std
end end
end end

View File

@ -8,7 +8,7 @@ describe BuildOptions do
alias_matcher :be_built_with, :be_with alias_matcher :be_built_with, :be_with
alias_matcher :be_built_without, :be_without alias_matcher :be_built_without, :be_without
subject { described_class.new(args, opts) } subject(:build_options) { described_class.new(args, opts) }
let(:bad_build) { described_class.new(bad_args, opts) } let(:bad_build) { described_class.new(bad_args, opts) }
let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) } let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) }
@ -16,22 +16,22 @@ describe BuildOptions do
let(:bad_args) { Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc]) } let(:bad_args) { Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc]) }
specify "#with?" do specify "#with?" do
expect(subject).to be_built_with("foo") expect(build_options).to be_built_with("foo")
expect(subject).to be_built_with("bar") expect(build_options).to be_built_with("bar")
expect(subject).to be_built_with("baz") expect(build_options).to be_built_with("baz")
end end
specify "#without?" do specify "#without?" do
expect(subject).to be_built_without("qux") expect(build_options).to be_built_without("qux")
expect(subject).to be_built_without("xyz") expect(build_options).to be_built_without("xyz")
end end
specify "#used_options" do specify "#used_options" do
expect(subject.used_options).to include("--with-foo") expect(build_options.used_options).to include("--with-foo")
expect(subject.used_options).to include("--with-bar") expect(build_options.used_options).to include("--with-bar")
end end
specify "#unused_options" do specify "#unused_options" do
expect(subject.unused_options).to include("--without-baz") expect(build_options.unused_options).to include("--without-baz")
end end
end end

View File

@ -4,7 +4,7 @@
require "cache_store" require "cache_store"
describe CacheStoreDatabase do describe CacheStoreDatabase do
subject { described_class.new(:sample) } subject(:sample_db) { described_class.new(:sample) }
describe "self.use" do describe "self.use" do
let(:type) { :test } let(:type) { :test }
@ -22,12 +22,12 @@ describe CacheStoreDatabase do
it "sets the value in the `CacheStoreDatabase`" do it "sets the value in the `CacheStoreDatabase`" do
allow(File).to receive(:write) allow(File).to receive(:write)
allow(subject).to receive(:created?).and_return(true) allow(sample_db).to receive(:created?).and_return(true)
allow(subject).to receive(:db).and_return(db) allow(sample_db).to receive(:db).and_return(db)
expect(db).to receive(:has_key?).with(:foo).and_return(false) expect(db).to receive(:has_key?).with(:foo).and_return(false)
expect(db).not_to have_key(:foo) expect(db).not_to have_key(:foo)
subject.set(:foo, "bar") sample_db.set(:foo, "bar")
end end
end end
@ -36,11 +36,11 @@ describe CacheStoreDatabase do
let(:db) { double("db", :[] => "bar") } let(:db) { double("db", :[] => "bar") }
it "gets value in the `CacheStoreDatabase` corresponding to the key" do it "gets value in the `CacheStoreDatabase` corresponding to the key" do
allow(subject).to receive(:created?).and_return(true) allow(sample_db).to receive(:created?).and_return(true)
expect(db).to receive(:has_key?).with(:foo).and_return(true) expect(db).to receive(:has_key?).with(:foo).and_return(true)
allow(subject).to receive(:db).and_return(db) allow(sample_db).to receive(:db).and_return(db)
expect(db).to have_key(:foo) expect(db).to have_key(:foo)
expect(subject.get(:foo)).to eq("bar") expect(sample_db.get(:foo)).to eq("bar")
end end
end end
@ -48,17 +48,17 @@ describe CacheStoreDatabase do
let(:db) { double("db", :[] => nil) } let(:db) { double("db", :[] => nil) }
before do before do
allow(subject).to receive(:created?).and_return(false) allow(sample_db).to receive(:created?).and_return(false)
allow(subject).to receive(:db).and_return(db) allow(sample_db).to receive(:db).and_return(db)
end end
it "does not get value in the `CacheStoreDatabase` corresponding to key" do it "does not get value in the `CacheStoreDatabase` corresponding to key" do
expect(subject.get(:foo)).not_to be("bar") expect(sample_db.get(:foo)).not_to be("bar")
end end
it "does not call `db[]` if `CacheStoreDatabase.created?` is `false`" do it "does not call `db[]` if `CacheStoreDatabase.created?` is `false`" do
expect(db).not_to receive(:[]) expect(db).not_to receive(:[])
subject.get(:foo) sample_db.get(:foo)
end end
end end
end end
@ -68,13 +68,13 @@ describe CacheStoreDatabase do
let(:db) { double("db", :[] => { foo: "bar" }) } let(:db) { double("db", :[] => { foo: "bar" }) }
before do before do
allow(subject).to receive(:created?).and_return(true) allow(sample_db).to receive(:created?).and_return(true)
allow(subject).to receive(:db).and_return(db) allow(sample_db).to receive(:db).and_return(db)
end end
it "deletes value in the `CacheStoreDatabase` corresponding to the key" do it "deletes value in the `CacheStoreDatabase` corresponding to the key" do
expect(db).to receive(:delete).with(:foo) expect(db).to receive(:delete).with(:foo)
subject.delete(:foo) sample_db.delete(:foo)
end end
end end
@ -82,13 +82,13 @@ describe CacheStoreDatabase do
let(:db) { double("db", delete: nil) } let(:db) { double("db", delete: nil) }
before do before do
allow(subject).to receive(:created?).and_return(false) allow(sample_db).to receive(:created?).and_return(false)
allow(subject).to receive(:db).and_return(db) allow(sample_db).to receive(:db).and_return(db)
end end
it "does not call `db.delete` if `CacheStoreDatabase.created?` is `false`" do it "does not call `db.delete` if `CacheStoreDatabase.created?` is `false`" do
expect(db).not_to receive(:delete) expect(db).not_to receive(:delete)
subject.delete(:foo) sample_db.delete(:foo)
end end
end end
end end
@ -96,17 +96,17 @@ describe CacheStoreDatabase do
describe "#write_if_dirty!" do describe "#write_if_dirty!" do
context "database open" do context "database open" do
it "does not raise an error when `close` is called on the database" do it "does not raise an error when `close` is called on the database" do
expect { subject.write_if_dirty! }.not_to raise_error(NoMethodError) expect { sample_db.write_if_dirty! }.not_to raise_error(NoMethodError)
end end
end end
context "database not open" do context "database not open" do
before do before do
subject.instance_variable_set(:@db, nil) sample_db.instance_variable_set(:@db, nil)
end end
it "does not raise an error when `close` is called on the database" do it "does not raise an error when `close` is called on the database" do
expect { subject.write_if_dirty! }.not_to raise_error(NoMethodError) expect { sample_db.write_if_dirty! }.not_to raise_error(NoMethodError)
end end
end end
end end
@ -115,7 +115,7 @@ describe CacheStoreDatabase do
let(:cache_path) { Pathname("path/to/homebrew/cache/sample.json") } let(:cache_path) { Pathname("path/to/homebrew/cache/sample.json") }
before do before do
allow(subject).to receive(:cache_path).and_return(cache_path) allow(sample_db).to receive(:cache_path).and_return(cache_path)
end end
context "`cache_path.exist?` returns `true`" do context "`cache_path.exist?` returns `true`" do
@ -124,7 +124,7 @@ describe CacheStoreDatabase do
end end
it "returns `true`" do it "returns `true`" do
expect(subject.created?).to be(true) expect(sample_db.created?).to be(true)
end end
end end
@ -134,7 +134,7 @@ describe CacheStoreDatabase do
end end
it "returns `false`" do it "returns `false`" do
expect(subject.created?).to be(false) expect(sample_db.created?).to be(false)
end end
end end
end end

View File

@ -106,7 +106,7 @@ describe Cask::Audit, :cask do
end end
describe "#run!" do describe "#run!" do
subject { audit.run! } subject(:run) { audit.run! }
def tmp_cask(name, text) def tmp_cask(name, text)
path = Pathname.new "#{dir}/#{name}.rb" path = Pathname.new "#{dir}/#{name}.rb"
@ -149,7 +149,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "Upper-Case" } let(:cask_token) { "Upper-Case" }
it "fails" do it "fails" do
expect(subject).to fail_with(/lowercase/) expect(run).to fail_with(/lowercase/)
end end
end end
@ -157,7 +157,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "ascii⌘" } let(:cask_token) { "ascii⌘" }
it "fails" do it "fails" do
expect(subject).to fail_with(/contains non-ascii characters/) expect(run).to fail_with(/contains non-ascii characters/)
end end
end end
@ -165,7 +165,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app++" } let(:cask_token) { "app++" }
it "fails" do it "fails" do
expect(subject).to fail_with(/\+ should be replaced by -plus-/) expect(run).to fail_with(/\+ should be replaced by -plus-/)
end end
end end
@ -173,7 +173,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app@stuff" } let(:cask_token) { "app@stuff" }
it "fails" do it "fails" do
expect(subject).to fail_with(/@ should be replaced by -at-/) expect(run).to fail_with(/@ should be replaced by -at-/)
end end
end end
@ -181,7 +181,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app stuff" } let(:cask_token) { "app stuff" }
it "fails" do it "fails" do
expect(subject).to fail_with(/whitespace should be replaced by hyphens/) expect(run).to fail_with(/whitespace should be replaced by hyphens/)
end end
end end
@ -189,7 +189,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app_stuff" } let(:cask_token) { "app_stuff" }
it "fails" do it "fails" do
expect(subject).to fail_with(/underscores should be replaced by hyphens/) expect(run).to fail_with(/underscores should be replaced by hyphens/)
end end
end end
@ -197,7 +197,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app(stuff)" } let(:cask_token) { "app(stuff)" }
it "fails" do it "fails" do
expect(subject).to fail_with(/alphanumeric characters and hyphens/) expect(run).to fail_with(/alphanumeric characters and hyphens/)
end end
end end
@ -205,7 +205,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app--stuff" } let(:cask_token) { "app--stuff" }
it "fails" do it "fails" do
expect(subject).to fail_with(/should not contain double hyphens/) expect(run).to fail_with(/should not contain double hyphens/)
end end
end end
@ -213,7 +213,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "-app" } let(:cask_token) { "-app" }
it "fails" do it "fails" do
expect(subject).to fail_with(/should not have leading or trailing hyphens/) expect(run).to fail_with(/should not have leading or trailing hyphens/)
end end
end end
@ -221,7 +221,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "app-" } let(:cask_token) { "app-" }
it "fails" do it "fails" do
expect(subject).to fail_with(/should not have leading or trailing hyphens/) expect(run).to fail_with(/should not have leading or trailing hyphens/)
end end
end end
end end
@ -247,7 +247,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "token.app" } let(:cask_token) { "token.app" }
it "fails" do it "fails" do
expect(subject).to fail_with(/token contains .app/) expect(run).to fail_with(/token contains .app/)
end end
end end
@ -257,13 +257,13 @@ describe Cask::Audit, :cask do
it "fails if the cask is from an official tap" do it "fails if the cask is from an official tap" do
allow(cask).to receive(:tap).and_return(Tap.fetch("homebrew/cask")) allow(cask).to receive(:tap).and_return(Tap.fetch("homebrew/cask"))
expect(subject).to fail_with(/token contains version designation/) expect(run).to fail_with(/token contains version designation/)
end end
it "does not fail if the cask is from the `cask-versions` tap" do it "does not fail if the cask is from the `cask-versions` tap" do
allow(cask).to receive(:tap).and_return(Tap.fetch("homebrew/cask-versions")) allow(cask).to receive(:tap).and_return(Tap.fetch("homebrew/cask-versions"))
expect(subject).to pass expect(run).to pass
end end
end end
@ -271,7 +271,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "token-launcher" } let(:cask_token) { "token-launcher" }
it "fails" do it "fails" do
expect(subject).to fail_with(/token mentions launcher/) expect(run).to fail_with(/token mentions launcher/)
end end
end end
@ -279,7 +279,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "token-desktop" } let(:cask_token) { "token-desktop" }
it "fails" do it "fails" do
expect(subject).to fail_with(/token mentions desktop/) expect(run).to fail_with(/token mentions desktop/)
end end
end end
@ -287,7 +287,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "token-osx" } let(:cask_token) { "token-osx" }
it "fails" do it "fails" do
expect(subject).to fail_with(/token mentions platform/) expect(run).to fail_with(/token mentions platform/)
end end
end end
@ -295,7 +295,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "token-x86" } let(:cask_token) { "token-x86" }
it "fails" do it "fails" do
expect(subject).to fail_with(/token mentions architecture/) expect(run).to fail_with(/token mentions architecture/)
end end
end end
@ -303,7 +303,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "token-java" } let(:cask_token) { "token-java" }
it "fails" do it "fails" do
expect(subject).to fail_with(/cask token mentions framework/) expect(run).to fail_with(/cask token mentions framework/)
end end
end end
@ -311,7 +311,7 @@ describe Cask::Audit, :cask do
let(:cask_token) { "java" } let(:cask_token) { "java" }
it "does not fail" do it "does not fail" do
expect(subject).to pass expect(run).to pass
end end
end end
@ -328,7 +328,7 @@ describe Cask::Audit, :cask do
let(:new_cask) { true } let(:new_cask) { true }
it "fails" do it "fails" do
expect(subject).to fail_with("#{cask_token} is listed in tap_migrations.json") expect(run).to fail_with("#{cask_token} is listed in tap_migrations.json")
end end
end end
@ -336,7 +336,7 @@ describe Cask::Audit, :cask do
let(:new_cask) { false } let(:new_cask) { false }
it "does not fail" do it "does not fail" do
expect(subject).to pass expect(run).to pass
end end
end end
end end
@ -382,9 +382,9 @@ describe Cask::Audit, :cask do
context "when cask locale is invalid" do context "when cask locale is invalid" do
it "error with invalid locale" do it "error with invalid locale" do
expect(subject).to fail_with(/Locale 'ZH-CN' is invalid\./) expect(run).to fail_with(/Locale 'ZH-CN' is invalid\./)
expect(subject).to fail_with(/Locale 'zh-' is invalid\./) expect(run).to fail_with(/Locale 'zh-' is invalid\./)
expect(subject).to fail_with(/Locale 'zh-cn' is invalid\./) expect(run).to fail_with(/Locale 'zh-cn' is invalid\./)
end end
end end
end end
@ -797,7 +797,7 @@ describe Cask::Audit, :cask do
context "when doing the audit" do context "when doing the audit" do
it "evaluates the block" do it "evaluates the block" do
expect(subject).to fail_with(/Boom/) expect(run).to fail_with(/Boom/)
end end
end end
end end
@ -812,7 +812,7 @@ describe Cask::Audit, :cask do
it "warns about duplicates" do it "warns about duplicates" do
expect(audit).to receive(:core_formula_names).and_return(formula_names) expect(audit).to receive(:core_formula_names).and_return(formula_names)
expect(subject).to warn_with(/possible duplicate/) expect(run).to warn_with(/possible duplicate/)
end end
end end
@ -836,12 +836,12 @@ describe Cask::Audit, :cask do
it "when download and verification succeed it does not fail" do it "when download and verification succeed it does not fail" do
expect(download_double).to receive(:fetch) expect(download_double).to receive(:fetch)
expect(subject).to pass expect(run).to pass
end end
it "when download fails it fails" do it "when download fails it fails" do
expect(download_double).to receive(:fetch).and_raise(StandardError.new(message)) expect(download_double).to receive(:fetch).and_raise(StandardError.new(message))
expect(subject).to fail_with(/#{message}/) expect(run).to fail_with(/#{message}/)
end end
end end
@ -850,7 +850,7 @@ describe Cask::Audit, :cask do
it "fails the audit" do it "fails the audit" do
expect(cask).to receive(:tap).and_raise(StandardError.new) expect(cask).to receive(:tap).and_raise(StandardError.new)
expect(subject).to fail_with(/exception while auditing/) expect(run).to fail_with(/exception while auditing/)
end end
end end
@ -873,7 +873,7 @@ describe Cask::Audit, :cask do
let(:new_cask) { true } let(:new_cask) { true }
it "fails" do it "fails" do
expect(subject).to fail_with(/should have a description/) expect(run).to fail_with(/should have a description/)
end end
end end
@ -881,7 +881,7 @@ describe Cask::Audit, :cask do
let(:new_cask) { false } let(:new_cask) { false }
it "warns" do it "warns" do
expect(subject).to warn_with(/should have a description/) expect(run).to warn_with(/should have a description/)
end end
end end
end end
@ -903,7 +903,7 @@ describe Cask::Audit, :cask do
end end
it "passes" do it "passes" do
expect(subject).to pass expect(run).to pass
end end
end end

View File

@ -2,7 +2,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe Cask::DSL::Appcast do describe Cask::DSL::Appcast do
subject { described_class.new(url, params) } subject(:appcast) { described_class.new(url, params) }
let(:url) { "https://brew.sh" } let(:url) { "https://brew.sh" }
let(:uri) { URI(url) } let(:uri) { URI(url) }
@ -10,7 +10,7 @@ describe Cask::DSL::Appcast do
describe "#to_s" do describe "#to_s" do
it "returns the parsed URI string" do it "returns the parsed URI string" do
expect(subject.to_s).to eq("https://brew.sh") expect(appcast.to_s).to eq("https://brew.sh")
end end
end end
@ -19,7 +19,7 @@ describe Cask::DSL::Appcast do
context "with empty parameters" do context "with empty parameters" do
it "returns an YAML serialized array composed of the URI and parameters" do it "returns an YAML serialized array composed of the URI and parameters" do
expect(subject.to_yaml).to eq(yaml) expect(appcast.to_yaml).to eq(yaml)
end end
end end
end end

View File

@ -5,17 +5,17 @@ require "formula"
require "caveats" require "caveats"
describe Caveats do describe Caveats do
subject { described_class.new(f) } subject(:caveats) { described_class.new(f) }
let(:f) { formula { url "foo-1.0" } } let(:f) { formula { url "foo-1.0" } }
specify "#f" do specify "#f" do
expect(subject.f).to eq(f) expect(caveats.f).to eq(f)
end end
describe "#empty?" do describe "#empty?" do
it "returns true if the Formula has no caveats" do it "returns true if the Formula has no caveats" do
expect(subject).to be_empty expect(caveats).to be_empty
end end
it "returns false if the Formula has caveats" do it "returns false if the Formula has caveats" do

View File

@ -7,7 +7,7 @@ require "formula"
describe Cleaner do describe Cleaner do
include FileUtils include FileUtils
subject { described_class.new(f) } subject(:cleaner) { described_class.new(f) }
let(:f) { formula("cleaner_test") { url "foo-1.0" } } let(:f) { formula("cleaner_test") { url "foo-1.0" } }
@ -28,7 +28,7 @@ describe Cleaner do
cp Dir["#{TEST_FIXTURE_DIR}/elf/libhello.so.0"], f.lib cp Dir["#{TEST_FIXTURE_DIR}/elf/libhello.so.0"], f.lib
end end
subject.clean cleaner.clean
if OS.mac? if OS.mac?
expect((f.bin/"a.out").stat.mode).to eq(0100555) expect((f.bin/"a.out").stat.mode).to eq(0100555)
@ -42,7 +42,7 @@ describe Cleaner do
end end
it "prunes the prefix if it is empty" do it "prunes the prefix if it is empty" do
subject.clean cleaner.clean
expect(f.prefix).not_to be_a_directory expect(f.prefix).not_to be_a_directory
end end
@ -50,7 +50,7 @@ describe Cleaner do
subdir = f.bin/"subdir" subdir = f.bin/"subdir"
subdir.mkpath subdir.mkpath
subject.clean cleaner.clean
expect(f.bin).not_to be_a_directory expect(f.bin).not_to be_a_directory
expect(subdir).not_to be_a_directory expect(subdir).not_to be_a_directory
@ -63,7 +63,7 @@ describe Cleaner do
dir.mkpath dir.mkpath
ln_s dir.basename, symlink ln_s dir.basename, symlink
subject.clean cleaner.clean
expect(dir).not_to exist expect(dir).not_to exist
expect(symlink).not_to be_a_symlink expect(symlink).not_to be_a_symlink
@ -77,7 +77,7 @@ describe Cleaner do
dir.mkpath dir.mkpath
ln_s dir.basename, symlink ln_s dir.basename, symlink
subject.clean cleaner.clean
expect(dir).not_to exist expect(dir).not_to exist
expect(symlink).not_to be_a_symlink expect(symlink).not_to be_a_symlink
@ -88,7 +88,7 @@ describe Cleaner do
symlink = f.prefix/"symlink" symlink = f.prefix/"symlink"
ln_s "target", symlink ln_s "target", symlink
subject.clean cleaner.clean
expect(symlink).not_to be_a_symlink expect(symlink).not_to be_a_symlink
end end
@ -99,7 +99,7 @@ describe Cleaner do
f.lib.mkpath f.lib.mkpath
touch file touch file
subject.clean cleaner.clean
expect(file).not_to exist expect(file).not_to exist
end end
@ -110,7 +110,7 @@ describe Cleaner do
(f.lib/"perl5/darwin-thread-multi-2level").mkpath (f.lib/"perl5/darwin-thread-multi-2level").mkpath
touch file touch file
subject.clean cleaner.clean
expect(file).not_to exist expect(file).not_to exist
end end
@ -121,7 +121,7 @@ describe Cleaner do
(f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath (f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath
touch file touch file
subject.clean cleaner.clean
expect(file).not_to exist expect(file).not_to exist
end end
@ -132,7 +132,7 @@ describe Cleaner do
f.lib.mkpath f.lib.mkpath
touch file touch file
subject.clean cleaner.clean
expect(file).not_to exist expect(file).not_to exist
end end
@ -143,7 +143,7 @@ describe Cleaner do
f.class.skip_clean "bin" f.class.skip_clean "bin"
f.bin.mkpath f.bin.mkpath
subject.clean cleaner.clean
expect(f.bin).to be_a_directory expect(f.bin).to be_a_directory
end end
@ -153,7 +153,7 @@ describe Cleaner do
subdir = f.bin/"subdir" subdir = f.bin/"subdir"
subdir.mkpath subdir.mkpath
subject.clean cleaner.clean
expect(f.bin).to be_a_directory expect(f.bin).to be_a_directory
expect(subdir).to be_a_directory expect(subdir).to be_a_directory
@ -164,7 +164,7 @@ describe Cleaner do
symlink = f.prefix/"symlink" symlink = f.prefix/"symlink"
ln_s "target", symlink ln_s "target", symlink
subject.clean cleaner.clean
expect(symlink).to be_a_symlink expect(symlink).to be_a_symlink
end end
@ -177,7 +177,7 @@ describe Cleaner do
dir.mkpath dir.mkpath
ln_s dir.basename, symlink ln_s dir.basename, symlink
subject.clean cleaner.clean
expect(dir).not_to exist expect(dir).not_to exist
expect(symlink).to be_a_symlink expect(symlink).to be_a_symlink
@ -192,7 +192,7 @@ describe Cleaner do
dir.mkpath dir.mkpath
ln_s dir.basename, symlink ln_s dir.basename, symlink
subject.clean cleaner.clean
expect(dir).not_to exist expect(dir).not_to exist
expect(symlink).to be_a_symlink expect(symlink).to be_a_symlink
@ -206,7 +206,7 @@ describe Cleaner do
f.lib.mkpath f.lib.mkpath
touch file touch file
subject.clean cleaner.clean
expect(file).to exist expect(file).to exist
end end
@ -217,7 +217,7 @@ describe Cleaner do
dir.mkpath dir.mkpath
subject.clean cleaner.clean
expect(dir).to be_a_directory expect(dir).to be_a_directory
end end
@ -230,7 +230,7 @@ describe Cleaner do
dir1.mkpath dir1.mkpath
dir2.mkpath dir2.mkpath
subject.clean cleaner.clean
expect(dir1).to exist expect(dir1).to exist
expect(dir2).not_to exist expect(dir2).not_to exist

View File

@ -31,6 +31,8 @@ describe Homebrew::Cleanup::CleanupRefinement do
end end
describe Homebrew::Cleanup do describe Homebrew::Cleanup do
subject(:cleanup) { described_class.new }
let(:ds_store) { Pathname.new("#{HOMEBREW_CELLAR}/.DS_Store") } let(:ds_store) { Pathname.new("#{HOMEBREW_CELLAR}/.DS_Store") }
let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") } let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") }
@ -49,7 +51,7 @@ describe Homebrew::Cleanup do
describe "::cleanup" do describe "::cleanup" do
it "removes .DS_Store and lock files" do it "removes .DS_Store and lock files" do
subject.clean! cleanup.clean!
expect(ds_store).not_to exist expect(ds_store).not_to exist
expect(lock_file).not_to exist expect(lock_file).not_to exist
@ -65,7 +67,7 @@ describe Homebrew::Cleanup do
it "doesn't remove the lock file if it is locked" do it "doesn't remove the lock file if it is locked" do
lock_file.open(File::RDWR | File::CREAT).flock(File::LOCK_EX | File::LOCK_NB) lock_file.open(File::RDWR | File::CREAT).flock(File::LOCK_EX | File::LOCK_NB)
subject.clean! cleanup.clean!
expect(lock_file).to exist expect(lock_file).to exist
end end
@ -89,13 +91,13 @@ describe Homebrew::Cleanup do
end end
it "doesn't remove any kegs" do it "doesn't remove any kegs" do
subject.cleanup_formula f2 cleanup.cleanup_formula f2
expect(f1.installed_kegs.size).to eq(2) expect(f1.installed_kegs.size).to eq(2)
end end
it "lists the unremovable kegs" do it "lists the unremovable kegs" do
subject.cleanup_formula f2 cleanup.cleanup_formula f2
expect(subject.unremovable_kegs).to contain_exactly(f1.installed_kegs[0]) expect(cleanup.unremovable_kegs).to contain_exactly(f1.installed_kegs[0])
end end
end end
end end
@ -133,7 +135,7 @@ describe Homebrew::Cleanup do
expect(f3).to be_latest_version_installed expect(f3).to be_latest_version_installed
expect(f4).to be_latest_version_installed expect(f4).to be_latest_version_installed
subject.cleanup_formula f3 cleanup.cleanup_formula f3
expect(f1).not_to be_latest_version_installed expect(f1).not_to be_latest_version_installed
expect(f2).not_to be_latest_version_installed expect(f2).not_to be_latest_version_installed
@ -154,7 +156,7 @@ describe Homebrew::Cleanup do
FileUtils.touch download FileUtils.touch download
subject.cleanup_cask(cask) cleanup.cleanup_cask(cask)
expect(download).not_to exist expect(download).not_to exist
end end
@ -164,7 +166,7 @@ describe Homebrew::Cleanup do
FileUtils.touch download FileUtils.touch download
subject.cleanup_cask(cask) cleanup.cleanup_cask(cask)
expect(download).to exist expect(download).to exist
end end
@ -178,7 +180,7 @@ describe Homebrew::Cleanup do
FileUtils.touch download FileUtils.touch download
subject.cleanup_cask(cask) cleanup.cleanup_cask(cask)
expect(download).to exist expect(download).to exist
end end
@ -189,7 +191,7 @@ describe Homebrew::Cleanup do
allow(download).to receive(:ctime).and_return(30.days.ago - 1.hour) allow(download).to receive(:ctime).and_return(30.days.ago - 1.hour)
allow(download).to receive(:mtime).and_return(30.days.ago - 1.hour) allow(download).to receive(:mtime).and_return(30.days.ago - 1.hour)
subject.cleanup_cask(cask) cleanup.cleanup_cask(cask)
expect(download).not_to exist expect(download).not_to exist
end end
@ -211,14 +213,14 @@ describe Homebrew::Cleanup do
it "cleans up logs if older than 30 days" do it "cleans up logs if older than 30 days" do
allow_any_instance_of(Pathname).to receive(:ctime).and_return(31.days.ago) allow_any_instance_of(Pathname).to receive(:ctime).and_return(31.days.ago)
allow_any_instance_of(Pathname).to receive(:mtime).and_return(31.days.ago) allow_any_instance_of(Pathname).to receive(:mtime).and_return(31.days.ago)
subject.cleanup_logs cleanup.cleanup_logs
expect(path).not_to exist expect(path).not_to exist
end end
it "does not clean up logs less than 30 days old" do it "does not clean up logs less than 30 days old" do
allow_any_instance_of(Pathname).to receive(:ctime).and_return(15.days.ago) allow_any_instance_of(Pathname).to receive(:ctime).and_return(15.days.ago)
allow_any_instance_of(Pathname).to receive(:mtime).and_return(15.days.ago) allow_any_instance_of(Pathname).to receive(:mtime).and_return(15.days.ago)
subject.cleanup_logs cleanup.cleanup_logs
expect(path).to exist expect(path).to exist
end end
end end
@ -228,7 +230,7 @@ describe Homebrew::Cleanup do
incomplete = (HOMEBREW_CACHE/"something.incomplete") incomplete = (HOMEBREW_CACHE/"something.incomplete")
incomplete.mkpath incomplete.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(incomplete).not_to exist expect(incomplete).not_to exist
end end
@ -237,7 +239,7 @@ describe Homebrew::Cleanup do
cargo_cache = (HOMEBREW_CACHE/"cargo_cache") cargo_cache = (HOMEBREW_CACHE/"cargo_cache")
cargo_cache.mkpath cargo_cache.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(cargo_cache).not_to exist expect(cargo_cache).not_to exist
end end
@ -246,7 +248,7 @@ describe Homebrew::Cleanup do
go_cache = (HOMEBREW_CACHE/"go_cache") go_cache = (HOMEBREW_CACHE/"go_cache")
go_cache.mkpath go_cache.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(go_cache).not_to exist expect(go_cache).not_to exist
end end
@ -255,7 +257,7 @@ describe Homebrew::Cleanup do
glide_home = (HOMEBREW_CACHE/"glide_home") glide_home = (HOMEBREW_CACHE/"glide_home")
glide_home.mkpath glide_home.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(glide_home).not_to exist expect(glide_home).not_to exist
end end
@ -264,7 +266,7 @@ describe Homebrew::Cleanup do
java_cache = (HOMEBREW_CACHE/"java_cache") java_cache = (HOMEBREW_CACHE/"java_cache")
java_cache.mkpath java_cache.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(java_cache).not_to exist expect(java_cache).not_to exist
end end
@ -273,7 +275,7 @@ describe Homebrew::Cleanup do
npm_cache = (HOMEBREW_CACHE/"npm_cache") npm_cache = (HOMEBREW_CACHE/"npm_cache")
npm_cache.mkpath npm_cache.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(npm_cache).not_to exist expect(npm_cache).not_to exist
end end
@ -282,7 +284,7 @@ describe Homebrew::Cleanup do
gclient_cache = (HOMEBREW_CACHE/"gclient_cache") gclient_cache = (HOMEBREW_CACHE/"gclient_cache")
gclient_cache.mkpath gclient_cache.mkpath
subject.cleanup_cache cleanup.cleanup_cache
expect(gclient_cache).not_to exist expect(gclient_cache).not_to exist
end end
@ -343,7 +345,7 @@ describe Homebrew::Cleanup do
it "cleans up file if outdated" do it "cleans up file if outdated" do
allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true)
subject.cleanup_cache cleanup.cleanup_cache
expect(bottle).not_to exist expect(bottle).not_to exist
expect(testball).not_to exist expect(testball).not_to exist
expect(testball_resource).not_to exist expect(testball_resource).not_to exist
@ -357,7 +359,7 @@ describe Homebrew::Cleanup do
end end
it "cleans up file if stale" do it "cleans up file if stale" do
subject.cleanup_cache cleanup.cleanup_cache
expect(bottle).not_to exist expect(bottle).not_to exist
expect(testball).not_to exist expect(testball).not_to exist
expect(testball_resource).not_to exist expect(testball_resource).not_to exist

View File

@ -33,16 +33,16 @@ describe Homebrew do
let(:remote) { "https://github.com/Homebrew/homebrew-core" } let(:remote) { "https://github.com/Homebrew/homebrew-core" }
specify "::github_remote_path" do specify "::github_remote_path" do
expect(subject.github_remote_path(remote, "Formula/git.rb")) expect(described_class.github_remote_path(remote, "Formula/git.rb"))
.to eq("https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb") .to eq("https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb")
expect(subject.github_remote_path("#{remote}.git", "Formula/git.rb")) expect(described_class.github_remote_path("#{remote}.git", "Formula/git.rb"))
.to eq("https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb") .to eq("https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb")
expect(subject.github_remote_path("git@github.com:user/repo", "foo.rb")) expect(described_class.github_remote_path("git@github.com:user/repo", "foo.rb"))
.to eq("https://github.com/user/repo/blob/HEAD/foo.rb") .to eq("https://github.com/user/repo/blob/HEAD/foo.rb")
expect(subject.github_remote_path("https://mywebsite.com", "foo/bar.rb")) expect(described_class.github_remote_path("https://mywebsite.com", "foo/bar.rb"))
.to eq("https://mywebsite.com/foo/bar.rb") .to eq("https://mywebsite.com/foo/bar.rb")
end end
end end

View File

@ -5,7 +5,7 @@ require "compilers"
require "software_spec" require "software_spec"
describe CompilerSelector do describe CompilerSelector do
subject { described_class.new(software_spec, versions, compilers) } subject(:selector) { described_class.new(software_spec, versions, compilers) }
let(:compilers) { [:clang, :gnu] } let(:compilers) { [:clang, :gnu] }
let(:software_spec) { SoftwareSpec.new } let(:software_spec) { SoftwareSpec.new }
@ -29,23 +29,23 @@ describe CompilerSelector do
describe "#compiler" do describe "#compiler" do
it "defaults to cc" do it "defaults to cc" do
expect(subject.compiler).to eq(cc) expect(selector.compiler).to eq(cc)
end end
it "returns clang if it fails with non-Apple gcc" do it "returns clang if it fails with non-Apple gcc" do
software_spec.fails_with(gcc: "7") software_spec.fails_with(gcc: "7")
expect(subject.compiler).to eq(:clang) expect(selector.compiler).to eq(:clang)
end end
it "still returns gcc-7 if it fails with gcc without a specific version" do it "still returns gcc-7 if it fails with gcc without a specific version" do
software_spec.fails_with(:clang) software_spec.fails_with(:clang)
expect(subject.compiler).to eq("gcc-7") expect(selector.compiler).to eq("gcc-7")
end end
it "returns gcc-6 if gcc formula offers gcc-6" do it "returns gcc-6 if gcc formula offers gcc-6" do
software_spec.fails_with(:clang) software_spec.fails_with(:clang)
allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0")) allow(Formulary).to receive(:factory).with("gcc").and_return(double(version: "6.0"))
expect(subject.compiler).to eq("gcc-6") expect(selector.compiler).to eq("gcc-6")
end end
it "raises an error when gcc or llvm is missing" do it "raises an error when gcc or llvm is missing" do
@ -53,7 +53,7 @@ describe CompilerSelector do
software_spec.fails_with(gcc: "7") software_spec.fails_with(gcc: "7")
software_spec.fails_with(gcc: "6") software_spec.fails_with(gcc: "6")
expect { subject.compiler }.to raise_error(CompilerSelectionError) expect { selector.compiler }.to raise_error(CompilerSelectionError)
end end
end end
end end

View File

@ -6,23 +6,23 @@ require "dependable"
describe Dependable do describe Dependable do
alias_matcher :be_a_build_dependency, :be_build alias_matcher :be_a_build_dependency, :be_build
subject { double(tags: tags).extend(described_class) } subject(:dependable) { double(tags: tags).extend(described_class) }
let(:tags) { ["foo", "bar", :build] } let(:tags) { ["foo", "bar", :build] }
specify "#options" do specify "#options" do
expect(subject.options.as_flags.sort).to eq(%w[--foo --bar].sort) expect(dependable.options.as_flags.sort).to eq(%w[--foo --bar].sort)
end end
specify "#build?" do specify "#build?" do
expect(subject).to be_a_build_dependency expect(dependable).to be_a_build_dependency
end end
specify "#optional?" do specify "#optional?" do
expect(subject).not_to be_optional expect(dependable).not_to be_optional
end end
specify "#recommended?" do specify "#recommended?" do
expect(subject).not_to be_recommended expect(dependable).not_to be_recommended
end end
end end

View File

@ -5,40 +5,42 @@ require "dependencies"
require "dependency" require "dependency"
describe Dependencies do describe Dependencies do
subject(:dependencies) { described_class.new }
describe "#<<" do describe "#<<" do
it "returns itself" do it "returns itself" do
expect(subject << Dependency.new("foo")).to eq(subject) expect(dependencies << Dependency.new("foo")).to eq(dependencies)
end end
it "preserves order" do it "preserves order" do
hash = { 0 => "foo", 1 => "bar", 2 => "baz" } hash = { 0 => "foo", 1 => "bar", 2 => "baz" }
subject << Dependency.new(hash[0]) dependencies << Dependency.new(hash[0])
subject << Dependency.new(hash[1]) dependencies << Dependency.new(hash[1])
subject << Dependency.new(hash[2]) dependencies << Dependency.new(hash[2])
subject.each_with_index do |dep, i| dependencies.each_with_index do |dep, i|
expect(dep.name).to eq(hash[i]) expect(dep.name).to eq(hash[i])
end end
end end
end end
specify "#*" do specify "#*" do
subject << Dependency.new("foo") dependencies << Dependency.new("foo")
subject << Dependency.new("bar") dependencies << Dependency.new("bar")
expect(subject * ", ").to eq("foo, bar") expect(dependencies * ", ").to eq("foo, bar")
end end
specify "#to_a" do specify "#to_a" do
dep = Dependency.new("foo") dep = Dependency.new("foo")
subject << dep dependencies << dep
expect(subject.to_a).to eq([dep]) expect(dependencies.to_a).to eq([dep])
end end
specify "#to_ary" do specify "#to_ary" do
dep = Dependency.new("foo") dep = Dependency.new("foo")
subject << dep dependencies << dep
expect(subject.to_ary).to eq([dep]) expect(dependencies.to_ary).to eq([dep])
end end
specify "type helpers" do specify "type helpers" do
@ -47,12 +49,12 @@ describe Dependencies do
baz = Dependency.new("baz", [:build]) baz = Dependency.new("baz", [:build])
qux = Dependency.new("qux", [:recommended]) qux = Dependency.new("qux", [:recommended])
quux = Dependency.new("quux") quux = Dependency.new("quux")
subject << foo << bar << baz << qux << quux dependencies << foo << bar << baz << qux << quux
expect(subject.required).to eq([foo, quux]) expect(dependencies.required).to eq([foo, quux])
expect(subject.optional).to eq([bar]) expect(dependencies.optional).to eq([bar])
expect(subject.build).to eq([baz]) expect(dependencies.build).to eq([baz])
expect(subject.recommended).to eq([qux]) expect(dependencies.recommended).to eq([qux])
expect(subject.default.sort_by(&:name)).to eq([foo, baz, quux, qux].sort_by(&:name)) expect(dependencies.default.sort_by(&:name)).to eq([foo, baz, quux, qux].sort_by(&:name))
end end
specify "equality" do specify "equality" do
@ -74,16 +76,16 @@ describe Dependencies do
end end
specify "#empty?" do specify "#empty?" do
expect(subject).to be_empty expect(dependencies).to be_empty
subject << Dependency.new("foo") dependencies << Dependency.new("foo")
expect(subject).not_to be_empty expect(dependencies).not_to be_empty
end end
specify "#inspect" do specify "#inspect" do
expect(subject.inspect).to eq("#<Dependencies: []>") expect(dependencies.inspect).to eq("#<Dependencies: []>")
subject << Dependency.new("foo") dependencies << Dependency.new("foo")
expect(subject.inspect).to eq("#<Dependencies: [#<Dependency: \"foo\" []>]>") expect(dependencies.inspect).to eq("#<Dependencies: [#<Dependency: \"foo\" []>]>")
end end
end end

View File

@ -6,102 +6,104 @@ require "dependency_collector"
describe DependencyCollector do describe DependencyCollector do
alias_matcher :be_a_build_requirement, :be_build alias_matcher :be_a_build_requirement, :be_build
subject(:collector) { described_class.new }
def find_dependency(name) def find_dependency(name)
subject.deps.find { |dep| dep.name == name } collector.deps.find { |dep| dep.name == name }
end end
def find_requirement(klass) def find_requirement(klass)
subject.requirements.find { |req| req.is_a? klass } collector.requirements.find { |req| req.is_a? klass }
end end
describe "#add" do describe "#add" do
specify "dependency creation" do specify "dependency creation" do
subject.add "foo" => :build collector.add "foo" => :build
subject.add "bar" => ["--universal", :optional] collector.add "bar" => ["--universal", :optional]
expect(find_dependency("foo")).to be_an_instance_of(Dependency) expect(find_dependency("foo")).to be_an_instance_of(Dependency)
expect(find_dependency("bar").tags.count).to eq(2) expect(find_dependency("bar").tags.count).to eq(2)
end end
it "returns the created dependency" do it "returns the created dependency" do
expect(subject.add("foo")).to eq(Dependency.new("foo")) expect(collector.add("foo")).to eq(Dependency.new("foo"))
end end
specify "requirement creation" do specify "requirement creation" do
subject.add :xcode collector.add :xcode
expect(find_requirement(XcodeRequirement)).to be_an_instance_of(XcodeRequirement) expect(find_requirement(XcodeRequirement)).to be_an_instance_of(XcodeRequirement)
end end
it "deduplicates requirements" do it "deduplicates requirements" do
2.times { subject.add :xcode } 2.times { collector.add :xcode }
expect(subject.requirements.count).to eq(1) expect(collector.requirements.count).to eq(1)
end end
specify "requirement tags" do specify "requirement tags" do
subject.add xcode: :build collector.add xcode: :build
expect(find_requirement(XcodeRequirement)).to be_a_build_requirement expect(find_requirement(XcodeRequirement)).to be_a_build_requirement
end end
it "doesn't mutate the dependency spec" do it "doesn't mutate the dependency spec" do
spec = { "foo" => :optional } spec = { "foo" => :optional }
copy = spec.dup copy = spec.dup
subject.add(spec) collector.add(spec)
expect(spec).to eq(copy) expect(spec).to eq(copy)
end end
it "creates a resource dependency from a CVS URL" do it "creates a resource dependency from a CVS URL" do
resource = Resource.new resource = Resource.new
resource.url(":pserver:anonymous:@brew.sh:/cvsroot/foo/bar", using: :cvs) resource.url(":pserver:anonymous:@brew.sh:/cvsroot/foo/bar", using: :cvs)
expect(subject.add(resource)).to eq(Dependency.new("cvs", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("cvs", [:build, :test]))
end end
it "creates a resource dependency from a '.7z' URL" do it "creates a resource dependency from a '.7z' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.7z") resource.url("https://brew.sh/foo.7z")
expect(subject.add(resource)).to eq(Dependency.new("p7zip", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("p7zip", [:build, :test]))
end end
it "creates a resource dependency from a '.gz' URL" do it "creates a resource dependency from a '.gz' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.tar.gz") resource.url("https://brew.sh/foo.tar.gz")
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
it "creates a resource dependency from a '.lz' URL" do it "creates a resource dependency from a '.lz' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.lz") resource.url("https://brew.sh/foo.lz")
expect(subject.add(resource)).to eq(Dependency.new("lzip", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("lzip", [:build, :test]))
end end
it "creates a resource dependency from a '.lha' URL" do it "creates a resource dependency from a '.lha' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.lha") resource.url("https://brew.sh/foo.lha")
expect(subject.add(resource)).to eq(Dependency.new("lha", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("lha", [:build, :test]))
end end
it "creates a resource dependency from a '.lzh' URL" do it "creates a resource dependency from a '.lzh' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.lzh") resource.url("https://brew.sh/foo.lzh")
expect(subject.add(resource)).to eq(Dependency.new("lha", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("lha", [:build, :test]))
end end
it "creates a resource dependency from a '.rar' URL" do it "creates a resource dependency from a '.rar' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.rar") resource.url("https://brew.sh/foo.rar")
expect(subject.add(resource)).to eq(Dependency.new("unrar", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("unrar", [:build, :test]))
end end
it "raises a TypeError for unknown classes" do it "raises a TypeError for unknown classes" do
expect { subject.add(Class.new) }.to raise_error(TypeError) expect { collector.add(Class.new) }.to raise_error(TypeError)
end end
it "raises a TypeError for unknown Types" do it "raises a TypeError for unknown Types" do
expect { subject.add(Object.new) }.to raise_error(TypeError) expect { collector.add(Object.new) }.to raise_error(TypeError)
end end
it "raises a TypeError for a Resource with an unknown download strategy" do it "raises a TypeError for a Resource with an unknown download strategy" do
resource = Resource.new resource = Resource.new
resource.download_strategy = Class.new resource.download_strategy = Class.new
expect { subject.add(resource) }.to raise_error(TypeError) expect { collector.add(resource) }.to raise_error(TypeError)
end end
end end
end end

View File

@ -103,13 +103,13 @@ describe Dependency do
end end
describe TapDependency do describe TapDependency do
subject { described_class.new("foo/bar/dog") } subject(:dependency) { described_class.new("foo/bar/dog") }
specify "#tap" do specify "#tap" do
expect(subject.tap).to eq(Tap.new("foo", "bar")) expect(dependency.tap).to eq(Tap.new("foo", "bar"))
end end
specify "#option_names" do specify "#option_names" do
expect(subject.option_names).to eq(%w[dog]) expect(dependency.option_names).to eq(%w[dog])
end end
end end

View File

@ -4,25 +4,25 @@
require "descriptions" require "descriptions"
describe Descriptions do describe Descriptions do
subject { described_class.new(descriptions_hash) } subject(:descriptions) { described_class.new(descriptions_hash) }
let(:descriptions_hash) { {} } let(:descriptions_hash) { {} }
it "can print description for a core Formula" do it "can print description for a core Formula" do
descriptions_hash["homebrew/core/foo"] = "Core foo" descriptions_hash["homebrew/core/foo"] = "Core foo"
expect { subject.print }.to output("foo: Core foo\n").to_stdout expect { descriptions.print }.to output("foo: Core foo\n").to_stdout
end end
it "can print description for an external Formula" do it "can print description for an external Formula" do
descriptions_hash["somedev/external/foo"] = "External foo" descriptions_hash["somedev/external/foo"] = "External foo"
expect { subject.print }.to output("foo: External foo\n").to_stdout expect { descriptions.print }.to output("foo: External foo\n").to_stdout
end end
it "can print descriptions for duplicate Formulae" do it "can print descriptions for duplicate Formulae" do
descriptions_hash["homebrew/core/foo"] = "Core foo" descriptions_hash["homebrew/core/foo"] = "Core foo"
descriptions_hash["somedev/external/foo"] = "External foo" descriptions_hash["somedev/external/foo"] = "External foo"
expect { subject.print }.to output( expect { descriptions.print }.to output(
<<~EOS, <<~EOS,
homebrew/core/foo: Core foo homebrew/core/foo: Core foo
somedev/external/foo: External foo somedev/external/foo: External foo
@ -35,7 +35,7 @@ describe Descriptions do
descriptions_hash["somedev/external/foo"] = "External foo" descriptions_hash["somedev/external/foo"] = "External foo"
descriptions_hash["otherdev/external/foo"] = "Other external foo" descriptions_hash["otherdev/external/foo"] = "Other external foo"
expect { subject.print }.to output( expect { descriptions.print }.to output(
<<~EOS, <<~EOS,
homebrew/core/foo: Core foo homebrew/core/foo: Core foo
otherdev/external/foo: Other external foo otherdev/external/foo: Other external foo

View File

@ -4,9 +4,11 @@
require "diagnostic" require "diagnostic"
describe Homebrew::Diagnostic::Checks do describe Homebrew::Diagnostic::Checks do
subject(:checks) { described_class.new }
specify "#inject_file_list" do specify "#inject_file_list" do
expect(subject.inject_file_list([], "foo:\n")).to eq("foo:\n") expect(checks.inject_file_list([], "foo:\n")).to eq("foo:\n")
expect(subject.inject_file_list(%w[/a /b], "foo:\n")).to eq("foo:\n /a\n /b\n") expect(checks.inject_file_list(%w[/a /b], "foo:\n")).to eq("foo:\n /a\n /b\n")
end end
specify "#check_for_anaconda" do specify "#check_for_anaconda" do
@ -22,7 +24,7 @@ describe Homebrew::Diagnostic::Checks do
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
expect(subject.check_for_anaconda).to match("Anaconda") expect(checks.check_for_anaconda).to match("Anaconda")
end end
end end
@ -40,7 +42,7 @@ describe Homebrew::Diagnostic::Checks do
dirs.each do |dir| dirs.each do |dir|
modes[dir] = dir.stat.mode & 0777 modes[dir] = dir.stat.mode & 0777
dir.chmod 0555 dir.chmod 0555
expect(subject.check_access_directories).to match(dir.to_s) expect(checks.check_access_directories).to match(dir.to_s)
end end
ensure ensure
modes.each do |dir, mode| modes.each do |dir, mode|
@ -60,7 +62,7 @@ describe Homebrew::Diagnostic::Checks do
# HOMEBREW_PREFIX/bin/ # HOMEBREW_PREFIX/bin/
(bin/File.basename(Dir["/usr/bin/*"].first)).mkpath (bin/File.basename(Dir["/usr/bin/*"].first)).mkpath
expect(subject.check_user_path_1) expect(checks.check_user_path_1)
.to match("/usr/bin occurs before #{HOMEBREW_PREFIX}/bin") .to match("/usr/bin occurs before #{HOMEBREW_PREFIX}/bin")
end end
@ -68,8 +70,8 @@ describe Homebrew::Diagnostic::Checks do
ENV["PATH"] = ENV["PATH"].gsub \ ENV["PATH"] = ENV["PATH"].gsub \
%r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}o, "" %r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}o, ""
expect(subject.check_user_path_1).to be nil expect(checks.check_user_path_1).to be nil
expect(subject.check_user_path_2) expect(checks.check_user_path_2)
.to match("Homebrew's \"bin\" was not found in your PATH.") .to match("Homebrew's \"bin\" was not found in your PATH.")
end end
@ -80,9 +82,9 @@ describe Homebrew::Diagnostic::Checks do
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "") ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
(sbin/"something").mkpath (sbin/"something").mkpath
expect(subject.check_user_path_1).to be nil expect(checks.check_user_path_1).to be nil
expect(subject.check_user_path_2).to be nil expect(checks.check_user_path_2).to be nil
expect(subject.check_user_path_3) expect(checks.check_user_path_3)
.to match("Homebrew's \"sbin\" was not found in your PATH") .to match("Homebrew's \"sbin\" was not found in your PATH")
ensure ensure
sbin.rmtree sbin.rmtree
@ -96,7 +98,7 @@ describe Homebrew::Diagnostic::Checks do
ENV["HOMEBREW_PATH"] = ENV["PATH"] = ENV["HOMEBREW_PATH"] = ENV["PATH"] =
"#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
expect(subject.check_for_config_scripts) expect(checks.check_for_config_scripts)
.to match('"config" scripts exist') .to match('"config" scripts exist')
end end
end end
@ -107,7 +109,7 @@ describe Homebrew::Diagnostic::Checks do
mktmpdir do |path| mktmpdir do |path|
FileUtils.ln_s path, HOMEBREW_CELLAR FileUtils.ln_s path, HOMEBREW_CELLAR
expect(subject.check_for_symlinked_cellar).to match(path) expect(checks.check_for_symlinked_cellar).to match(path)
end end
ensure ensure
HOMEBREW_CELLAR.unlink HOMEBREW_CELLAR.unlink
@ -116,7 +118,7 @@ describe Homebrew::Diagnostic::Checks do
specify "#check_tmpdir" do specify "#check_tmpdir" do
ENV["TMPDIR"] = "/i/don/t/exis/t" ENV["TMPDIR"] = "/i/don/t/exis/t"
expect(subject.check_tmpdir).to match("doesn't exist") expect(checks.check_tmpdir).to match("doesn't exist")
end end
specify "#check_for_external_cmd_name_conflict" do specify "#check_for_external_cmd_name_conflict" do
@ -130,7 +132,7 @@ describe Homebrew::Diagnostic::Checks do
allow(Tap).to receive(:cmd_directories).and_return([path1, path2]) allow(Tap).to receive(:cmd_directories).and_return([path1, path2])
expect(subject.check_for_external_cmd_name_conflict) expect(checks.check_for_external_cmd_name_conflict)
.to match("brew-foo") .to match("brew-foo")
end end
end end
@ -138,7 +140,7 @@ describe Homebrew::Diagnostic::Checks do
specify "#check_homebrew_prefix" do specify "#check_homebrew_prefix" do
allow(Homebrew).to receive(:default_prefix?).and_return(false) allow(Homebrew).to receive(:default_prefix?).and_return(false)
expect(subject.check_homebrew_prefix) expect(checks.check_homebrew_prefix)
.to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}") .to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}")
end end
end end

View File

@ -4,7 +4,7 @@
require "download_strategy" require "download_strategy"
describe AbstractDownloadStrategy do describe AbstractDownloadStrategy do
subject { described_class.new(url, name, version, **specs) } subject(:strategy) { described_class.new(url, name, version, **specs) }
let(:specs) { {} } let(:specs) { {} }
let(:name) { "foo" } let(:name) { "foo" }
@ -17,7 +17,7 @@ describe AbstractDownloadStrategy do
FileUtils.touch "foo", mtime: Time.now - 10 FileUtils.touch "foo", mtime: Time.now - 10
FileUtils.touch "bar", mtime: Time.now - 100 FileUtils.touch "bar", mtime: Time.now - 100
FileUtils.ln_s "not-exist", "baz" FileUtils.ln_s "not-exist", "baz"
expect(subject.source_modified_time).to eq(File.mtime("foo")) expect(strategy.source_modified_time).to eq(File.mtime("foo"))
end end
end end
@ -25,13 +25,13 @@ describe AbstractDownloadStrategy do
let(:specs) { { bottle: true } } let(:specs) { { bottle: true } }
it "extends Pourable" do it "extends Pourable" do
expect(subject).to be_a_kind_of(AbstractDownloadStrategy::Pourable) expect(strategy).to be_a_kind_of(AbstractDownloadStrategy::Pourable)
end end
end end
context "without specs[:bottle]" do context "without specs[:bottle]" do
it "is does not extend Pourable" do it "is does not extend Pourable" do
expect(subject).not_to be_a_kind_of(AbstractDownloadStrategy::Pourable) expect(strategy).not_to be_a_kind_of(AbstractDownloadStrategy::Pourable)
end end
end end
end end
@ -50,20 +50,20 @@ describe VCSDownloadStrategy do
end end
describe GitHubGitDownloadStrategy do describe GitHubGitDownloadStrategy do
subject { described_class.new(url, name, version) } subject(:strategy) { described_class.new(url, name, version) }
let(:name) { "brew" } let(:name) { "brew" }
let(:url) { "https://github.com/homebrew/brew.git" } let(:url) { "https://github.com/homebrew/brew.git" }
let(:version) { nil } let(:version) { nil }
it "parses the URL and sets the corresponding instance variables" do it "parses the URL and sets the corresponding instance variables" do
expect(subject.instance_variable_get(:@user)).to eq("homebrew") expect(strategy.instance_variable_get(:@user)).to eq("homebrew")
expect(subject.instance_variable_get(:@repo)).to eq("brew") expect(strategy.instance_variable_get(:@repo)).to eq("brew")
end end
end end
describe GitDownloadStrategy do describe GitDownloadStrategy do
subject { described_class.new(url, name, version) } subject(:strategy) { described_class.new(url, name, version) }
let(:name) { "baz" } let(:name) { "baz" }
let(:url) { "https://github.com/homebrew/foo" } let(:url) { "https://github.com/homebrew/foo" }
@ -93,7 +93,7 @@ describe GitDownloadStrategy do
cached_location.cd do cached_location.cd do
setup_git_repo setup_git_repo
end end
expect(subject.source_modified_time.to_i).to eq(1_485_115_153) expect(strategy.source_modified_time.to_i).to eq(1_485_115_153)
end end
end end
@ -103,7 +103,7 @@ describe GitDownloadStrategy do
FileUtils.touch "LICENSE" FileUtils.touch "LICENSE"
git_commit_all git_commit_all
end end
expect(subject.last_commit).to eq("f68266e") expect(strategy.last_commit).to eq("f68266e")
end end
describe "#fetch_last_commit" do describe "#fetch_last_commit" do
@ -122,13 +122,13 @@ describe GitDownloadStrategy do
git_commit_all git_commit_all
end end
expect(subject.fetch_last_commit).to eq("f68266e") expect(strategy.fetch_last_commit).to eq("f68266e")
end end
end end
end end
describe CurlDownloadStrategy do describe CurlDownloadStrategy do
subject { described_class.new(url, name, version, **specs) } subject(:strategy) { described_class.new(url, name, version, **specs) }
let(:name) { "foo" } let(:name) { "foo" }
let(:url) { "https://example.com/foo.tar.gz" } let(:url) { "https://example.com/foo.tar.gz" }
@ -136,15 +136,15 @@ describe CurlDownloadStrategy do
let(:specs) { { user: "download:123456" } } let(:specs) { { user: "download:123456" } }
it "parses the opts and sets the corresponding args" do it "parses the opts and sets the corresponding args" do
expect(subject.send(:_curl_args)).to eq(["--user", "download:123456"]) expect(strategy.send(:_curl_args)).to eq(["--user", "download:123456"])
end end
describe "#cached_location" do describe "#cached_location" do
subject { described_class.new(url, name, version, **specs).cached_location } subject(:location) { described_class.new(url, name, version, **specs).cached_location }
context "when URL ends with file" do context "when URL ends with file" do
it { it {
expect(subject).to eq( expect(location).to eq(
HOMEBREW_CACHE/"downloads/3d1c0ae7da22be9d83fb1eb774df96b7c4da71d3cf07e1cb28555cf9a5e5af70--foo.tar.gz", HOMEBREW_CACHE/"downloads/3d1c0ae7da22be9d83fb1eb774df96b7c4da71d3cf07e1cb28555cf9a5e5af70--foo.tar.gz",
) )
} }
@ -154,7 +154,7 @@ describe CurlDownloadStrategy do
let(:url) { "https://example.com/foo.tar.gz/from/this/mirror" } let(:url) { "https://example.com/foo.tar.gz/from/this/mirror" }
it { it {
expect(subject).to eq( expect(location).to eq(
HOMEBREW_CACHE/"downloads/1ab61269ba52c83994510b1e28dd04167a2f2e8393a35a9c50c1f7d33fd8f619--foo.tar.gz", HOMEBREW_CACHE/"downloads/1ab61269ba52c83994510b1e28dd04167a2f2e8393a35a9c50c1f7d33fd8f619--foo.tar.gz",
) )
} }
@ -163,12 +163,12 @@ describe CurlDownloadStrategy do
describe "#fetch" do describe "#fetch" do
before do before do
subject.temporary_path.dirname.mkpath strategy.temporary_path.dirname.mkpath
FileUtils.touch subject.temporary_path FileUtils.touch strategy.temporary_path
end end
it "calls curl with default arguments" do it "calls curl with default arguments" do
expect(subject).to receive(:curl).with( expect(strategy).to receive(:curl).with(
"--location", "--location",
"--remote-time", "--remote-time",
"--continue-at", "0", "--continue-at", "0",
@ -177,21 +177,21 @@ describe CurlDownloadStrategy do
an_instance_of(Hash) an_instance_of(Hash)
) )
subject.fetch strategy.fetch
end end
context "with an explicit user agent" do context "with an explicit user agent" do
let(:specs) { { user_agent: "Mozilla/25.0.1" } } let(:specs) { { user_agent: "Mozilla/25.0.1" } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons("--user-agent", "Mozilla/25.0.1")), hash_including(args: array_including_cons("--user-agent", "Mozilla/25.0.1")),
) )
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
@ -201,7 +201,7 @@ describe CurlDownloadStrategy do
let(:specs) { { user_agent: :fake } } let(:specs) { { user_agent: :fake } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons( hash_including(args: array_including_cons(
"--user-agent", "--user-agent",
@ -211,7 +211,7 @@ describe CurlDownloadStrategy do
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
@ -226,14 +226,14 @@ describe CurlDownloadStrategy do
} }
it "adds the appropriate curl args and does not URL-encode the cookies" do it "adds the appropriate curl args and does not URL-encode the cookies" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons("-b", "coo=k/e;mon=ster")), hash_including(args: array_including_cons("-b", "coo=k/e;mon=ster")),
) )
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
@ -241,14 +241,14 @@ describe CurlDownloadStrategy do
let(:specs) { { referer: "https://somehost/also" } } let(:specs) { { referer: "https://somehost/also" } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons("-e", "https://somehost/also")), hash_including(args: array_including_cons("-e", "https://somehost/also")),
) )
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
@ -258,14 +258,14 @@ describe CurlDownloadStrategy do
let(:specs) { { headers: ["foo", "bar"] } } let(:specs) { { headers: ["foo", "bar"] } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons("--header", "foo").and(array_including_cons("--header", "bar"))), hash_including(args: array_including_cons("--header", "foo").and(array_including_cons("--header", "bar"))),
) )
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
end end
@ -315,7 +315,7 @@ describe CurlDownloadStrategy do
end end
describe CurlPostDownloadStrategy do describe CurlPostDownloadStrategy do
subject { described_class.new(url, name, version, **specs) } subject(:strategy) { described_class.new(url, name, version, **specs) }
let(:name) { "foo" } let(:name) { "foo" }
let(:url) { "https://example.com/foo.tar.gz" } let(:url) { "https://example.com/foo.tar.gz" }
@ -324,8 +324,8 @@ describe CurlPostDownloadStrategy do
describe "#fetch" do describe "#fetch" do
before do before do
subject.temporary_path.dirname.mkpath strategy.temporary_path.dirname.mkpath
FileUtils.touch subject.temporary_path FileUtils.touch strategy.temporary_path
end end
context "with :using and :data specified" do context "with :using and :data specified" do
@ -340,14 +340,14 @@ describe CurlPostDownloadStrategy do
} }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons("-d", "form=data").and(array_including_cons("-d", "is=good"))), hash_including(args: array_including_cons("-d", "form=data").and(array_including_cons("-d", "is=good"))),
) )
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
@ -355,21 +355,21 @@ describe CurlPostDownloadStrategy do
let(:specs) { { using: :post } } let(:specs) { { using: :post } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(subject).to receive(:system_command).with( expect(strategy).to receive(:system_command).with(
/curl/, /curl/,
hash_including(args: array_including_cons("-X", "POST")), hash_including(args: array_including_cons("-X", "POST")),
) )
.at_least(:once) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
subject.fetch strategy.fetch
end end
end end
end end
end end
describe SubversionDownloadStrategy do describe SubversionDownloadStrategy do
subject { described_class.new(url, name, version, **specs) } subject(:strategy) { described_class.new(url, name, version, **specs) }
let(:name) { "foo" } let(:name) { "foo" }
let(:url) { "https://example.com/foo.tar.gz" } let(:url) { "https://example.com/foo.tar.gz" }
@ -381,9 +381,9 @@ describe SubversionDownloadStrategy do
let(:specs) { { trust_cert: true } } let(:specs) { { trust_cert: true } }
it "adds the appropriate svn args" do it "adds the appropriate svn args" do
expect(subject).to receive(:system_command!) expect(strategy).to receive(:system_command!)
.with("svn", hash_including(args: array_including("--trust-server-cert", "--non-interactive"))) .with("svn", hash_including(args: array_including("--trust-server-cert", "--non-interactive")))
subject.fetch strategy.fetch
end end
end end
@ -391,10 +391,10 @@ describe SubversionDownloadStrategy do
let(:specs) { { revision: "10" } } let(:specs) { { revision: "10" } }
it "adds svn arguments for :revision" do it "adds svn arguments for :revision" do
expect(subject).to receive(:system_command!) expect(strategy).to receive(:system_command!)
.with("svn", hash_including(args: array_including_cons("-r", "10"))) .with("svn", hash_including(args: array_including_cons("-r", "10")))
subject.fetch strategy.fetch
end end
end end
end end
@ -402,7 +402,7 @@ end
describe DownloadStrategyDetector do describe DownloadStrategyDetector do
describe "::detect" do describe "::detect" do
subject { described_class.detect(url, strategy) } subject(:strategy_detector) { described_class.detect(url, strategy) }
let(:url) { Object.new } let(:url) { Object.new }
let(:strategy) { nil } let(:strategy) { nil }
@ -420,7 +420,7 @@ describe DownloadStrategyDetector do
end end
it "defaults to curl" do it "defaults to curl" do
expect(subject).to eq(CurlDownloadStrategy) expect(strategy_detector).to eq(CurlDownloadStrategy)
end end
it "raises an error when passed an unrecognized strategy" do it "raises an error when passed an unrecognized strategy" do

View File

@ -47,7 +47,7 @@ describe ErrorDuringExecution do
end end
its(:to_s) { its(:to_s) {
expect(subject.to_s).to eq <<~EOS expect(error.to_s).to eq <<~EOS
Failure while executing; `false` exited with 1. Here's the output: Failure while executing; `false` exited with 1. Here's the output:
This still worked. This still worked.
#{Formatter.error("Here something went wrong.\n")} #{Formatter.error("Here something went wrong.\n")}
@ -59,7 +59,7 @@ describe ErrorDuringExecution do
let(:command) { ["env", "PATH=/bin", "cat", "with spaces"] } let(:command) { ["env", "PATH=/bin", "cat", "with spaces"] }
its(:to_s) { its(:to_s) {
expect(subject.to_s) expect(error.to_s)
.to eq 'Failure while executing; `env PATH=/bin cat with\ spaces` exited with 1.' .to eq 'Failure while executing; `env PATH=/bin cat with\ spaces` exited with 1.'
} }
end end

View File

@ -26,29 +26,29 @@ describe NoSuchKegError do
end end
describe FormulaValidationError do describe FormulaValidationError do
subject { described_class.new("foo", "sha257", "magic") } subject(:error) { described_class.new("foo", "sha257", "magic") }
its(:to_s) { its(:to_s) {
expect(subject.to_s).to eq(%q(invalid attribute for formula 'foo': sha257 ("magic"))) expect(error.to_s).to eq(%q(invalid attribute for formula 'foo': sha257 ("magic")))
} }
end end
describe FormulaUnavailableError do describe FormulaUnavailableError do
subject { described_class.new("foo") } subject(:error) { described_class.new("foo") }
describe "#dependent_s" do describe "#dependent_s" do
it "returns nil if there is no dependent" do it "returns nil if there is no dependent" do
expect(subject.dependent_s).to be nil expect(error.dependent_s).to be nil
end end
it "returns nil if it depended on by itself" do it "returns nil if it depended on by itself" do
subject.dependent = "foo" error.dependent = "foo"
expect(subject.dependent_s).to be nil expect(error.dependent_s).to be nil
end end
it "returns a string if there is a dependent" do it "returns a string if there is a dependent" do
subject.dependent = "foobar" error.dependent = "foobar"
expect(subject.dependent_s).to eq(" (dependency of foobar)") expect(error.dependent_s).to eq(" (dependency of foobar)")
end end
end end
@ -58,11 +58,11 @@ describe FormulaUnavailableError do
context "with a dependent" do context "with a dependent" do
before do before do
subject.dependent = "foobar" error.dependent = "foobar"
end end
its(:to_s) { its(:to_s) {
expect(subject.to_s).to eq('No available formula with the name "foo" (dependency of foobar).') expect(error.to_s).to eq('No available formula with the name "foo" (dependency of foobar).')
} }
end end
end end
@ -76,7 +76,7 @@ describe TapFormulaUnavailableError do
end end
describe FormulaClassUnavailableError do describe FormulaClassUnavailableError do
subject { described_class.new("foo", "foo.rb", "Foo", list) } subject(:error) { described_class.new("foo", "foo.rb", "Foo", list) }
let(:mod) do let(:mod) do
Module.new do Module.new do
@ -90,7 +90,7 @@ describe FormulaClassUnavailableError do
let(:list) { [] } let(:list) { [] }
its(:to_s) { its(:to_s) {
expect(subject.to_s).to match(/Expected to find class Foo, but found no classes\./) expect(error.to_s).to match(/Expected to find class Foo, but found no classes\./)
} }
end end
@ -98,7 +98,7 @@ describe FormulaClassUnavailableError do
let(:list) { [mod.const_get(:Bar)] } let(:list) { [mod.const_get(:Bar)] }
its(:to_s) { its(:to_s) {
expect(subject.to_s).to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./) expect(error.to_s).to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./)
} }
end end

View File

@ -6,7 +6,7 @@ require "utils/tty"
describe Formatter do describe Formatter do
describe "::columns" do describe "::columns" do
subject { described_class.columns(input) } subject(:columns) { described_class.columns(input) }
let(:input) { let(:input) {
%w[ %w[
@ -21,7 +21,7 @@ describe Formatter do
allow_any_instance_of(IO).to receive(:tty?).and_return(false) allow_any_instance_of(IO).to receive(:tty?).and_return(false)
allow(Tty).to receive(:width).and_return(10) allow(Tty).to receive(:width).and_return(10)
expect(subject).to eq( expect(columns).to eq(
"aa\n" \ "aa\n" \
"bbb\n" \ "bbb\n" \
"ccc\n" \ "ccc\n" \
@ -34,7 +34,7 @@ describe Formatter do
allow_any_instance_of(IO).to receive(:tty?).and_return(true) allow_any_instance_of(IO).to receive(:tty?).and_return(true)
allow(Tty).to receive(:width).and_return(10) allow(Tty).to receive(:width).and_return(10)
expect(subject).to eq( expect(columns).to eq(
"aa ccc\n" \ "aa ccc\n" \
"bbb dd\n", "bbb dd\n",
) )
@ -44,7 +44,7 @@ describe Formatter do
allow_any_instance_of(IO).to receive(:tty?).and_return(true) allow_any_instance_of(IO).to receive(:tty?).and_return(true)
allow(Tty).to receive(:width).and_return(20) allow(Tty).to receive(:width).and_return(20)
expect(subject).to eq( expect(columns).to eq(
"aa bbb ccc dd\n", "aa bbb ccc dd\n",
) )
end end

View File

@ -4,7 +4,7 @@
require "formula_pin" require "formula_pin"
describe FormulaPin do describe FormulaPin do
subject { described_class.new(formula) } subject(:formula_pin) { described_class.new(formula) }
let(:name) { "double" } let(:name) { "double" }
let(:formula) { double(Formula, name: name, rack: HOMEBREW_CELLAR/name) } let(:formula) { double(Formula, name: name, rack: HOMEBREW_CELLAR/name) }
@ -22,24 +22,24 @@ describe FormulaPin do
end end
it "is not pinnable by default" do it "is not pinnable by default" do
expect(subject).not_to be_pinnable expect(formula_pin).not_to be_pinnable
end end
it "is pinnable if the Keg exists" do it "is pinnable if the Keg exists" do
(formula.rack/"0.1").mkpath (formula.rack/"0.1").mkpath
expect(subject).to be_pinnable expect(formula_pin).to be_pinnable
end end
specify "#pin and #unpin" do specify "#pin and #unpin" do
(formula.rack/"0.1").mkpath (formula.rack/"0.1").mkpath
subject.pin formula_pin.pin
expect(subject).to be_pinned expect(formula_pin).to be_pinned
expect(HOMEBREW_PINNED_KEGS/name).to be_a_directory expect(HOMEBREW_PINNED_KEGS/name).to be_a_directory
expect(HOMEBREW_PINNED_KEGS.children.count).to eq(1) expect(HOMEBREW_PINNED_KEGS.children.count).to eq(1)
subject.unpin formula_pin.unpin
expect(subject).not_to be_pinned expect(formula_pin).not_to be_pinned
expect(HOMEBREW_PINNED_KEGS).not_to be_a_directory expect(HOMEBREW_PINNED_KEGS).not_to be_a_directory
end end
end end

View File

@ -13,16 +13,16 @@ describe Language::Node do
end end
stub_formula_loader(node) stub_formula_loader(node)
expect(ENV).to receive(:prepend_path) expect(ENV).to receive(:prepend_path)
subject.instance_variable_set(:@env_set, false) described_class.instance_variable_set(:@env_set, false)
expect(subject.setup_npm_environment).to be_nil expect(described_class.setup_npm_environment).to be_nil
expect(subject.instance_variable_get(:@env_set)).to eq(true) expect(described_class.instance_variable_get(:@env_set)).to eq(true)
expect(ENV).not_to receive(:prepend_path) expect(ENV).not_to receive(:prepend_path)
expect(subject.setup_npm_environment).to be_nil expect(described_class.setup_npm_environment).to be_nil
end end
it "does not call prepend_path when node formula does not exist" do it "does not call prepend_path when node formula does not exist" do
expect(subject.setup_npm_environment).to be_nil expect(described_class.setup_npm_environment).to be_nil
end end
end end
@ -32,7 +32,7 @@ describe Language::Node do
path = Pathname("package.json") path = Pathname("package.json")
path.atomic_write("{\"scripts\":{\"prepare\": \"ls\", \"prepack\": \"ls\", \"test\": \"ls\"}}") path.atomic_write("{\"scripts\":{\"prepare\": \"ls\", \"prepack\": \"ls\", \"test\": \"ls\"}}")
allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`echo pack.tgz`) allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`echo pack.tgz`)
subject.pack_for_installation described_class.pack_for_installation
expect(path.read).not_to include("prepare") expect(path.read).not_to include("prepare")
expect(path.read).not_to include("prepack") expect(path.read).not_to include("prepack")
expect(path.read).to include("test") expect(path.read).to include("test")
@ -45,25 +45,25 @@ describe Language::Node do
it "raises error with non zero exitstatus" do it "raises error with non zero exitstatus" do
allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`false`) allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`false`)
expect { subject.std_npm_install_args(npm_install_arg) }.to \ expect { described_class.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}") raise_error("npm failed to pack #{Dir.pwd}")
end end
it "raises error with empty npm pack output" do it "raises error with empty npm pack output" do
allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`true`) allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`true`)
expect { subject.std_npm_install_args(npm_install_arg) }.to \ expect { described_class.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}") raise_error("npm failed to pack #{Dir.pwd}")
end end
it "does not raise error with a zero exitstatus" do it "does not raise error with a zero exitstatus" do
allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`echo pack.tgz`) allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`echo pack.tgz`)
resp = subject.std_npm_install_args(npm_install_arg) resp = described_class.std_npm_install_args(npm_install_arg)
expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz") expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz")
end end
end end
specify "#local_npm_install_args" do specify "#local_npm_install_args" do
resp = subject.local_npm_install_args resp = described_class.local_npm_install_args
expect(resp).to include("-ddd", "--build-from-source", "--cache=#{HOMEBREW_CACHE}/npm_cache") expect(resp).to include("-ddd", "--build-from-source", "--cache=#{HOMEBREW_CACHE}/npm_cache")
end end
end end

View File

@ -8,28 +8,28 @@ require "utils/shebang"
describe Language::Python, :needs_python do describe Language::Python, :needs_python do
describe "#major_minor_version" do describe "#major_minor_version" do
it "returns a Version for Python 2" do it "returns a Version for Python 2" do
expect(subject).to receive(:major_minor_version).and_return(Version) expect(described_class).to receive(:major_minor_version).and_return(Version)
subject.major_minor_version("python") described_class.major_minor_version("python")
end end
end end
describe "#site_packages" do describe "#site_packages" do
it "gives a different location between PyPy and Python 2" do it "gives a different location between PyPy and Python 2" do
expect(subject.site_packages("python")).not_to eql(subject.site_packages("pypy")) expect(described_class.site_packages("python")).not_to eql(described_class.site_packages("pypy"))
end end
end end
describe "#homebrew_site_packages" do describe "#homebrew_site_packages" do
it "returns the Homebrew site packages location" do it "returns the Homebrew site packages location" do
expect(subject).to receive(:site_packages).and_return(Pathname) expect(described_class).to receive(:site_packages).and_return(Pathname)
subject.site_packages("python") described_class.site_packages("python")
end end
end end
describe "#user_site_packages" do describe "#user_site_packages" do
it "can determine user site packages location" do it "can determine user site packages location" do
expect(subject).to receive(:user_site_packages).and_return(Pathname) expect(described_class).to receive(:user_site_packages).and_return(Pathname)
subject.user_site_packages("python") described_class.user_site_packages("python")
end end
end end
end end
@ -77,7 +77,7 @@ describe Language::Python::Shebang do
end end
describe Language::Python::Virtualenv::Virtualenv do describe Language::Python::Virtualenv::Virtualenv do
subject { described_class.new(formula, dir, "python") } subject(:virtualenv) { described_class.new(formula, dir, "python") }
let(:dir) { mktmpdir } let(:dir) { mktmpdir }
@ -88,7 +88,7 @@ describe Language::Python::Virtualenv::Virtualenv do
describe "#create" do describe "#create" do
it "creates a venv" do it "creates a venv" do
expect(formula).to receive(:system).with("python", "-m", "venv", dir) expect(formula).to receive(:system).with("python", "-m", "venv", dir)
subject.create virtualenv.create
end end
end end
@ -98,7 +98,7 @@ describe Language::Python::Virtualenv::Virtualenv do
.with(dir/"bin/pip", "install", "-v", "--no-deps", .with(dir/"bin/pip", "install", "-v", "--no-deps",
"--no-binary", ":all:", "--no-user", "--ignore-installed", "foo") "--no-binary", ":all:", "--no-user", "--ignore-installed", "foo")
.and_return(true) .and_return(true)
subject.pip_install "foo" virtualenv.pip_install "foo"
end end
it "accepts a multi-line strings" do it "accepts a multi-line strings" do
@ -107,7 +107,7 @@ describe Language::Python::Virtualenv::Virtualenv do
"--no-binary", ":all:", "--no-user", "--ignore-installed", "foo", "bar") "--no-binary", ":all:", "--no-user", "--ignore-installed", "foo", "bar")
.and_return(true) .and_return(true)
subject.pip_install <<~EOS virtualenv.pip_install <<~EOS
foo foo
bar bar
EOS EOS
@ -124,7 +124,7 @@ describe Language::Python::Virtualenv::Virtualenv do
"--no-binary", ":all:", "--no-user", "--ignore-installed", "bar") "--no-binary", ":all:", "--no-user", "--ignore-installed", "bar")
.and_return(true) .and_return(true)
subject.pip_install ["foo", "bar"] virtualenv.pip_install ["foo", "bar"]
end end
it "accepts a Resource" do it "accepts a Resource" do
@ -136,7 +136,7 @@ describe Language::Python::Virtualenv::Virtualenv do
"--no-binary", ":all:", "--no-user", "--ignore-installed", Pathname.pwd) "--no-binary", ":all:", "--no-user", "--ignore-installed", Pathname.pwd)
.and_return(true) .and_return(true)
subject.pip_install res virtualenv.pip_install res
end end
end end
@ -155,10 +155,10 @@ describe Language::Python::Virtualenv::Virtualenv do
FileUtils.touch src_bin/"kilroy" FileUtils.touch src_bin/"kilroy"
bin_after = Dir.glob(src_bin/"*") bin_after = Dir.glob(src_bin/"*")
expect(subject).to receive(:pip_install).with("foo") expect(virtualenv).to receive(:pip_install).with("foo")
expect(Dir).to receive(:[]).with(src_bin/"*").twice.and_return(bin_before, bin_after) expect(Dir).to receive(:[]).with(src_bin/"*").twice.and_return(bin_before, bin_after)
subject.pip_install_and_link "foo" virtualenv.pip_install_and_link "foo"
expect(src_bin/"kilroy").to exist expect(src_bin/"kilroy").to exist
expect(dest_bin/"kilroy").to exist expect(dest_bin/"kilroy").to exist

View File

@ -4,7 +4,7 @@
require "linkage_cache_store" require "linkage_cache_store"
describe LinkageCacheStore do describe LinkageCacheStore do
subject { described_class.new(keg_name, database) } subject(:linkage_cache) { described_class.new(keg_name, database) }
let(:keg_name) { "keg_name" } let(:keg_name) { "keg_name" }
let(:database) { double("database") } let(:database) { double("database") }
@ -13,14 +13,14 @@ describe LinkageCacheStore do
context "`keg_name` exists in cache" do context "`keg_name` exists in cache" do
it "returns `true`" do it "returns `true`" do
expect(database).to receive(:get).with(keg_name).and_return("") expect(database).to receive(:get).with(keg_name).and_return("")
expect(subject.keg_exists?).to be(true) expect(linkage_cache.keg_exists?).to be(true)
end end
end end
context "`keg_name` does not exist in cache" do context "`keg_name` does not exist in cache" do
it "returns `false`" do it "returns `false`" do
expect(database).to receive(:get).with(keg_name).and_return(nil) expect(database).to receive(:get).with(keg_name).and_return(nil)
expect(subject.keg_exists?).to be(false) expect(linkage_cache.keg_exists?).to be(false)
end end
end end
end end
@ -29,13 +29,13 @@ describe LinkageCacheStore do
context "a `value` is a `Hash`" do context "a `value` is a `Hash`" do
it "sets the cache for the `keg_name`" do it "sets the cache for the `keg_name`" do
expect(database).to receive(:set).with(keg_name, anything) expect(database).to receive(:set).with(keg_name, anything)
subject.update!(keg_files_dylibs: { key: ["value"] }) linkage_cache.update!(keg_files_dylibs: { key: ["value"] })
end end
end end
context "a `value` is not a `Hash`" do context "a `value` is not a `Hash`" do
it "raises a `TypeError` if a `value` is not a `Hash`" do it "raises a `TypeError` if a `value` is not a `Hash`" do
expect { subject.update!(a_value: ["value"]) }.to raise_error(TypeError) expect { linkage_cache.update!(a_value: ["value"]) }.to raise_error(TypeError)
end end
end end
end end
@ -43,7 +43,7 @@ describe LinkageCacheStore do
describe "#delete!" do describe "#delete!" do
it "calls `delete` on the `database` with `keg_name` as parameter" do it "calls `delete` on the `database` with `keg_name` as parameter" do
expect(database).to receive(:delete).with(keg_name) expect(database).to receive(:delete).with(keg_name)
subject.delete! linkage_cache.delete!
end end
end end
@ -51,13 +51,13 @@ describe LinkageCacheStore do
context "`HASH_LINKAGE_TYPES.include?(type)`" do context "`HASH_LINKAGE_TYPES.include?(type)`" do
it "returns a `Hash` of values" do it "returns a `Hash` of values" do
expect(database).to receive(:get).with(keg_name).and_return(nil) expect(database).to receive(:get).with(keg_name).and_return(nil)
expect(subject.fetch(:keg_files_dylibs)).to be_an_instance_of(Hash) expect(linkage_cache.fetch(:keg_files_dylibs)).to be_an_instance_of(Hash)
end end
end end
context "`type` not in `HASH_LINKAGE_TYPES`" do context "`type` not in `HASH_LINKAGE_TYPES`" do
it "raises a `TypeError` if the `type` is not supported" do it "raises a `TypeError` if the `type` is not supported" do
expect { subject.fetch(:bad_type) }.to raise_error(TypeError) expect { linkage_cache.fetch(:bad_type) }.to raise_error(TypeError)
end end
end end
end end

View File

@ -58,11 +58,11 @@ describe Locale do
end end
describe "#eql?" do describe "#eql?" do
subject { described_class.new("zh", "CN", "Hans") } subject(:locale) { described_class.new("zh", "CN", "Hans") }
context "all parts match" do context "all parts match" do
it { is_expected.to eql("zh-CN-Hans") } it { is_expected.to eql("zh-CN-Hans") }
it { is_expected.to eql(subject) } it { is_expected.to eql(locale) }
end end
context "only some parts match" do context "only some parts match" do
@ -74,8 +74,8 @@ describe Locale do
end end
it "does not raise if 'other' cannot be parsed" do it "does not raise if 'other' cannot be parsed" do
expect { subject.eql?("zh_CN_Hans") }.not_to raise_error expect { locale.eql?("zh_CN_Hans") }.not_to raise_error
expect(subject.eql?("zh_CN_Hans")).to be false expect(locale.eql?("zh_CN_Hans")).to be false
end end
end end

View File

@ -4,17 +4,17 @@
require "lock_file" require "lock_file"
describe LockFile do describe LockFile do
subject { described_class.new("foo") } subject(:lock_file) { described_class.new("foo") }
describe "#lock" do describe "#lock" do
it "does not raise an error when already locked" do it "does not raise an error when already locked" do
subject.lock lock_file.lock
expect { subject.lock }.not_to raise_error expect { lock_file.lock }.not_to raise_error
end end
it "raises an error if a lock already exists" do it "raises an error if a lock already exists" do
subject.lock lock_file.lock
expect { expect {
described_class.new("foo").lock described_class.new("foo").lock
@ -24,12 +24,12 @@ describe LockFile do
describe "#unlock" do describe "#unlock" do
it "does not raise an error when already unlocked" do it "does not raise an error when already unlocked" do
expect { subject.unlock }.not_to raise_error expect { lock_file.unlock }.not_to raise_error
end end
it "unlocks when locked" do it "unlocks when locked" do
subject.lock lock_file.lock
subject.unlock lock_file.unlock
expect { described_class.new("foo").lock }.not_to raise_error expect { described_class.new("foo").lock }.not_to raise_error
end end

View File

@ -7,7 +7,7 @@ require "tab"
require "keg" require "keg"
describe Migrator do describe Migrator do
subject { described_class.new(new_formula) } subject(:migrator) { described_class.new(new_formula) }
let(:new_formula) { Testball.new("newname") } let(:new_formula) { Testball.new("newname") }
let(:old_formula) { Testball.new("oldname") } let(:old_formula) { Testball.new("oldname") }
@ -41,7 +41,7 @@ describe Migrator do
old_pin.make_relative_symlink old_keg_record old_pin.make_relative_symlink old_keg_record
subject # needs to be evaluated eagerly migrator # needs to be evaluated eagerly
(HOMEBREW_PREFIX/"bin").mkpath (HOMEBREW_PREFIX/"bin").mkpath
end end
@ -84,7 +84,7 @@ describe Migrator do
specify "#move_to_new_directory" do specify "#move_to_new_directory" do
keg.unlink keg.unlink
subject.move_to_new_directory migrator.move_to_new_directory
expect(new_keg_record).to be_a_directory expect(new_keg_record).to be_a_directory
expect(new_keg_record/"bin").to be_a_directory expect(new_keg_record/"bin").to be_a_directory
@ -97,7 +97,7 @@ describe Migrator do
old_keg_record.parent.rmtree old_keg_record.parent.rmtree
(new_keg_record/"bin").mkpath (new_keg_record/"bin").mkpath
subject.backup_oldname_cellar migrator.backup_oldname_cellar
expect(old_keg_record/"bin").to be_a_directory expect(old_keg_record/"bin").to be_a_directory
expect(old_keg_record/"bin").to be_a_directory expect(old_keg_record/"bin").to be_a_directory
@ -107,18 +107,18 @@ describe Migrator do
(new_keg_record/"bin").mkpath (new_keg_record/"bin").mkpath
expected_relative = new_keg_record.relative_path_from HOMEBREW_PINNED_KEGS expected_relative = new_keg_record.relative_path_from HOMEBREW_PINNED_KEGS
subject.repin migrator.repin
expect(subject.new_pin_record).to be_a_symlink expect(migrator.new_pin_record).to be_a_symlink
expect(subject.new_pin_record.readlink).to eq(expected_relative) expect(migrator.new_pin_record.readlink).to eq(expected_relative)
expect(subject.old_pin_record).not_to exist expect(migrator.old_pin_record).not_to exist
end end
specify "#unlink_oldname" do specify "#unlink_oldname" do
expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1) expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1)
expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1) expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1)
subject.unlink_oldname migrator.unlink_oldname
expect(HOMEBREW_LINKED_KEGS).not_to exist expect(HOMEBREW_LINKED_KEGS).not_to exist
expect(HOMEBREW_LIBRARY/"bin").not_to exist expect(HOMEBREW_LIBRARY/"bin").not_to exist
@ -133,7 +133,7 @@ describe Migrator do
FileUtils.touch new_keg_record/"bin"/file FileUtils.touch new_keg_record/"bin"/file
end end
subject.link_newname migrator.link_newname
expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1) expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1)
expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1) expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1)
@ -141,7 +141,7 @@ describe Migrator do
specify "#link_oldname_opt" do specify "#link_oldname_opt" do
new_keg_record.mkpath new_keg_record.mkpath
subject.link_oldname_opt migrator.link_oldname_opt
expect((HOMEBREW_PREFIX/"opt/oldname").realpath).to eq(new_keg_record.realpath) expect((HOMEBREW_PREFIX/"opt/oldname").realpath).to eq(new_keg_record.realpath)
end end
@ -149,7 +149,7 @@ describe Migrator do
(new_keg_record/"bin").mkpath (new_keg_record/"bin").mkpath
keg.unlink keg.unlink
keg.uninstall keg.uninstall
subject.link_oldname_cellar migrator.link_oldname_cellar
expect((HOMEBREW_CELLAR/"oldname").realpath).to eq(new_keg_record.parent.realpath) expect((HOMEBREW_CELLAR/"oldname").realpath).to eq(new_keg_record.parent.realpath)
end end
@ -159,7 +159,7 @@ describe Migrator do
tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json" tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json"
tab.source["path"] = "/path/that/must/be/changed/by/update_tabs" tab.source["path"] = "/path/that/must/be/changed/by/update_tabs"
tab.write tab.write
subject.update_tabs migrator.update_tabs
expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s) expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s)
end end
@ -169,7 +169,7 @@ describe Migrator do
tab.source["path"] = old_formula.path.to_s tab.source["path"] = old_formula.path.to_s
tab.write tab.write
subject.migrate migrator.migrate
expect(new_keg_record).to exist expect(new_keg_record).to exist
expect(old_keg_record.parent).to be_a_symlink expect(old_keg_record.parent).to be_a_symlink
@ -187,7 +187,7 @@ describe Migrator do
old_opt_record = HOMEBREW_PREFIX/"opt/oldname" old_opt_record = HOMEBREW_PREFIX/"opt/oldname"
old_opt_record.unlink if old_opt_record.symlink? old_opt_record.unlink if old_opt_record.symlink?
old_opt_record.make_relative_symlink(new_keg_record) old_opt_record.make_relative_symlink(new_keg_record)
subject.unlink_oldname_opt migrator.unlink_oldname_opt
expect(old_opt_record).not_to be_a_symlink expect(old_opt_record).not_to be_a_symlink
end end
@ -196,7 +196,7 @@ describe Migrator do
keg.unlink keg.unlink
keg.uninstall keg.uninstall
old_keg_record.parent.make_relative_symlink(new_keg_record.parent) old_keg_record.parent.make_relative_symlink(new_keg_record.parent)
subject.unlink_oldname_cellar migrator.unlink_oldname_cellar
expect(old_keg_record.parent).not_to be_a_symlink expect(old_keg_record.parent).not_to be_a_symlink
end end
@ -204,7 +204,7 @@ describe Migrator do
(new_keg_record/"bin").mkpath (new_keg_record/"bin").mkpath
keg.unlink keg.unlink
keg.uninstall keg.uninstall
subject.backup_oldname_cellar migrator.backup_oldname_cellar
expect(old_keg_record.subdirs).not_to be_empty expect(old_keg_record.subdirs).not_to be_empty
end end
@ -222,7 +222,7 @@ describe Migrator do
describe "#backup_oldname" do describe "#backup_oldname" do
context "when cellar exists" do context "when cellar exists" do
it "backs up the old name" do it "backs up the old name" do
subject.backup_oldname migrator.backup_oldname
expect(old_keg_record.parent).to be_a_directory expect(old_keg_record.parent).to be_a_directory
expect(old_keg_record.parent.subdirs).not_to be_empty expect(old_keg_record.parent.subdirs).not_to be_empty
expect(HOMEBREW_LINKED_KEGS/"oldname").to exist expect(HOMEBREW_LINKED_KEGS/"oldname").to exist
@ -237,7 +237,7 @@ describe Migrator do
(new_keg_record/"bin").mkpath (new_keg_record/"bin").mkpath
keg.unlink keg.unlink
keg.uninstall keg.uninstall
subject.backup_oldname migrator.backup_oldname
expect(old_keg_record.parent).to be_a_directory expect(old_keg_record.parent).to be_a_directory
expect(old_keg_record.parent.subdirs).not_to be_empty expect(old_keg_record.parent.subdirs).not_to be_empty
expect(HOMEBREW_LINKED_KEGS/"oldname").to exist expect(HOMEBREW_LINKED_KEGS/"oldname").to exist
@ -253,7 +253,7 @@ describe Migrator do
keg.unlink keg.unlink
keg.uninstall keg.uninstall
old_keg_record.parent.make_relative_symlink(new_keg_record.parent) old_keg_record.parent.make_relative_symlink(new_keg_record.parent)
subject.backup_oldname migrator.backup_oldname
expect(old_keg_record.parent).to be_a_directory expect(old_keg_record.parent).to be_a_directory
expect(old_keg_record.parent.subdirs).not_to be_empty expect(old_keg_record.parent.subdirs).not_to be_empty
expect(HOMEBREW_LINKED_KEGS/"oldname").to exist expect(HOMEBREW_LINKED_KEGS/"oldname").to exist

View File

@ -4,136 +4,138 @@
require "options" require "options"
describe Option do describe Option do
subject { described_class.new("foo") } subject(:option) { described_class.new("foo") }
specify "#to_s" do specify "#to_s" do
expect(subject.to_s).to eq("--foo") expect(option.to_s).to eq("--foo")
end end
specify "equality" do specify "equality" do
foo = described_class.new("foo") foo = described_class.new("foo")
bar = described_class.new("bar") bar = described_class.new("bar")
expect(subject).to eq(foo) expect(option).to eq(foo)
expect(subject).not_to eq(bar) expect(option).not_to eq(bar)
expect(subject).to eql(foo) expect(option).to eql(foo)
expect(subject).not_to eql(bar) expect(option).not_to eql(bar)
end end
specify "#description" do specify "#description" do
expect(subject.description).to be_empty expect(option.description).to be_empty
expect(described_class.new("foo", "foo").description).to eq("foo") expect(described_class.new("foo", "foo").description).to eq("foo")
end end
specify "#inspect" do specify "#inspect" do
expect(subject.inspect).to eq("#<Option: \"--foo\">") expect(option.inspect).to eq("#<Option: \"--foo\">")
end end
end end
describe DeprecatedOption do describe DeprecatedOption do
subject { described_class.new("foo", "bar") } subject(:option) { described_class.new("foo", "bar") }
specify "#old" do specify "#old" do
expect(subject.old).to eq("foo") expect(option.old).to eq("foo")
end end
specify "#old_flag" do specify "#old_flag" do
expect(subject.old_flag).to eq("--foo") expect(option.old_flag).to eq("--foo")
end end
specify "#current" do specify "#current" do
expect(subject.current).to eq("bar") expect(option.current).to eq("bar")
end end
specify "#current_flag" do specify "#current_flag" do
expect(subject.current_flag).to eq("--bar") expect(option.current_flag).to eq("--bar")
end end
specify "equality" do specify "equality" do
foobar = described_class.new("foo", "bar") foobar = described_class.new("foo", "bar")
boofar = described_class.new("boo", "far") boofar = described_class.new("boo", "far")
expect(foobar).to eq(subject) expect(foobar).to eq(option)
expect(subject).to eq(foobar) expect(option).to eq(foobar)
expect(boofar).not_to eq(subject) expect(boofar).not_to eq(option)
expect(subject).not_to eq(boofar) expect(option).not_to eq(boofar)
end end
end end
describe Options do describe Options do
subject(:options) { described_class.new }
it "removes duplicate options" do it "removes duplicate options" do
subject << Option.new("foo") options << Option.new("foo")
subject << Option.new("foo") options << Option.new("foo")
expect(subject).to include("--foo") expect(options).to include("--foo")
expect(subject.count).to eq(1) expect(options.count).to eq(1)
end end
it "preserves existing member when adding a duplicate" do it "preserves existing member when adding a duplicate" do
a = Option.new("foo", "bar") a = Option.new("foo", "bar")
b = Option.new("foo", "qux") b = Option.new("foo", "qux")
subject << a << b options << a << b
expect(subject.count).to eq(1) expect(options.count).to eq(1)
expect(subject.first).to be(a) expect(options.first).to be(a)
expect(subject.first.description).to eq(a.description) expect(options.first.description).to eq(a.description)
end end
specify "#include?" do specify "#include?" do
subject << Option.new("foo") options << Option.new("foo")
expect(subject).to include("--foo") expect(options).to include("--foo")
expect(subject).to include("foo") expect(options).to include("foo")
expect(subject).to include(Option.new("foo")) expect(options).to include(Option.new("foo"))
end end
describe "#+" do describe "#+" do
it "returns options" do it "returns options" do
expect(subject + described_class.new).to be_an_instance_of(described_class) expect(options + described_class.new).to be_an_instance_of(described_class)
end end
end end
describe "#-" do describe "#-" do
it "returns options" do it "returns options" do
expect(subject - described_class.new).to be_an_instance_of(described_class) expect(options - described_class.new).to be_an_instance_of(described_class)
end end
end end
specify "#&" do specify "#&" do
foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
options = described_class.new << foo << bar other_options = described_class.new << foo << bar
subject << foo << baz options << foo << baz
expect((subject & options).to_a).to eq([foo]) expect((options & other_options).to_a).to eq([foo])
end end
specify "#|" do specify "#|" do
foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
options = described_class.new << foo << bar other_options = described_class.new << foo << bar
subject << foo << baz options << foo << baz
expect((subject | options).sort).to eq([foo, bar, baz].sort) expect((options | other_options).sort).to eq([foo, bar, baz].sort)
end end
specify "#*" do specify "#*" do
subject << Option.new("aa") << Option.new("bb") << Option.new("cc") options << Option.new("aa") << Option.new("bb") << Option.new("cc")
expect((subject * "XX").split("XX").sort).to eq(%w[--aa --bb --cc]) expect((options * "XX").split("XX").sort).to eq(%w[--aa --bb --cc])
end end
describe "<<" do describe "<<" do
it "returns itself" do it "returns itself" do
expect(subject << Option.new("foo")).to be subject expect(options << Option.new("foo")).to be options
end end
end end
specify "#as_flags" do specify "#as_flags" do
subject << Option.new("foo") options << Option.new("foo")
expect(subject.as_flags).to eq(%w[--foo]) expect(options.as_flags).to eq(%w[--foo])
end end
specify "#to_a" do specify "#to_a" do
option = Option.new("foo") option = Option.new("foo")
subject << option options << option
expect(subject.to_a).to eq([option]) expect(options.to_a).to eq([option])
end end
specify "#to_ary" do specify "#to_ary" do
option = Option.new("foo") option = Option.new("foo")
subject << option options << option
expect(subject.to_ary).to eq([option]) expect(options.to_ary).to eq([option])
end end
specify "::create_with_array" do specify "::create_with_array" do
@ -144,8 +146,8 @@ describe Options do
end end
specify "#inspect" do specify "#inspect" do
expect(subject.inspect).to eq("#<Options: []>") expect(options.inspect).to eq("#<Options: []>")
subject << Option.new("foo") options << Option.new("foo")
expect(subject.inspect).to eq("#<Options: [#<Option: \"--foo\">]>") expect(options.inspect).to eq("#<Options: [#<Option: \"--foo\">]>")
end end
end end

View File

@ -6,6 +6,8 @@ require "dependency_collector"
describe DependencyCollector do describe DependencyCollector do
alias_matcher :be_a_build_requirement, :be_build alias_matcher :be_a_build_requirement, :be_build
subject(:collector) { described_class.new }
describe "#add" do describe "#add" do
resource = Resource.new resource = Resource.new
@ -13,19 +15,19 @@ describe DependencyCollector do
it "creates a resource dependency from a '.xz' URL" do it "creates a resource dependency from a '.xz' URL" do
resource.url("https://brew.sh/foo.xz") resource.url("https://brew.sh/foo.xz")
allow_any_instance_of(Object).to receive(:which).with("xz") allow_any_instance_of(Object).to receive(:which).with("xz")
expect(subject.add(resource)).to eq(Dependency.new("xz", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("xz", [:build, :test]))
end end
it "creates a resource dependency from a '.zip' URL" do it "creates a resource dependency from a '.zip' URL" do
resource.url("https://brew.sh/foo.zip") resource.url("https://brew.sh/foo.zip")
allow_any_instance_of(Object).to receive(:which).with("unzip") allow_any_instance_of(Object).to receive(:which).with("unzip")
expect(subject.add(resource)).to eq(Dependency.new("unzip", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("unzip", [:build, :test]))
end end
it "creates a resource dependency from a '.bz2' URL" do it "creates a resource dependency from a '.bz2' URL" do
resource.url("https://brew.sh/foo.tar.bz2") resource.url("https://brew.sh/foo.tar.bz2")
allow_any_instance_of(Object).to receive(:which).with("bzip2") allow_any_instance_of(Object).to receive(:which).with("bzip2")
expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build, :test])) expect(collector.add(resource)).to eq(Dependency.new("bzip2", [:build, :test]))
end end
end end
@ -33,19 +35,19 @@ describe DependencyCollector do
it "does not create a resource dependency from a '.xz' URL" do it "does not create a resource dependency from a '.xz' URL" do
resource.url("https://brew.sh/foo.xz") resource.url("https://brew.sh/foo.xz")
allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo")) allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo"))
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
it "does not create a resource dependency from a '.zip' URL" do it "does not create a resource dependency from a '.zip' URL" do
resource.url("https://brew.sh/foo.zip") resource.url("https://brew.sh/foo.zip")
allow_any_instance_of(Object).to receive(:which).with("unzip").and_return(Pathname.new("foo")) allow_any_instance_of(Object).to receive(:which).with("unzip").and_return(Pathname.new("foo"))
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
it "does not create a resource dependency from a '.bz2' URL" do it "does not create a resource dependency from a '.bz2' URL" do
resource.url("https://brew.sh/foo.tar.bz2") resource.url("https://brew.sh/foo.tar.bz2")
allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo")) allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo"))
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
end end
end end

View File

@ -4,24 +4,26 @@
require "diagnostic" require "diagnostic"
describe Homebrew::Diagnostic::Checks do describe Homebrew::Diagnostic::Checks do
subject(:checks) { described_class.new }
specify "#check_supported_architecture" do specify "#check_supported_architecture" do
allow(Hardware::CPU).to receive(:type).and_return(:arm64) allow(Hardware::CPU).to receive(:type).and_return(:arm64)
expect(subject.check_supported_architecture) expect(checks.check_supported_architecture)
.to match(/Your CPU architecture .+ is not supported/) .to match(/Your CPU architecture .+ is not supported/)
end end
specify "#check_glibc_minimum_version" do specify "#check_glibc_minimum_version" do
allow(OS::Linux::Glibc).to receive(:below_minimum_version?).and_return(true) allow(OS::Linux::Glibc).to receive(:below_minimum_version?).and_return(true)
expect(subject.check_glibc_minimum_version) expect(checks.check_glibc_minimum_version)
.to match(/Your system glibc .+ is too old/) .to match(/Your system glibc .+ is too old/)
end end
specify "#check_kernel_minimum_version" do specify "#check_kernel_minimum_version" do
allow(OS::Linux::Kernel).to receive(:below_minimum_version?).and_return(true) allow(OS::Linux::Kernel).to receive(:below_minimum_version?).and_return(true)
expect(subject.check_kernel_minimum_version) expect(checks.check_kernel_minimum_version)
.to match(/Your Linux kernel .+ is too old/) .to match(/Your Linux kernel .+ is too old/)
end end
end end

View File

@ -6,37 +6,39 @@ require "dependency_collector"
describe DependencyCollector do describe DependencyCollector do
alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency
subject(:collector) { described_class.new }
specify "Resource dependency from a '.xz' URL" do specify "Resource dependency from a '.xz' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.tar.xz") resource.url("https://brew.sh/foo.tar.xz")
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
specify "Resource dependency from a '.zip' URL" do specify "Resource dependency from a '.zip' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.zip") resource.url("https://brew.sh/foo.zip")
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
specify "Resource dependency from a '.bz2' URL" do specify "Resource dependency from a '.bz2' URL" do
resource = Resource.new resource = Resource.new
resource.url("https://brew.sh/foo.tar.bz2") resource.url("https://brew.sh/foo.tar.bz2")
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
specify "Resource dependency from a '.git' URL" do specify "Resource dependency from a '.git' URL" do
resource = Resource.new resource = Resource.new
resource.url("git://brew.sh/foo/bar.git") resource.url("git://brew.sh/foo/bar.git")
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
end end
specify "Resource dependency from a Subversion URL" do specify "Resource dependency from a Subversion URL" do
resource = Resource.new resource = Resource.new
resource.url("svn://brew.sh/foo/bar") resource.url("svn://brew.sh/foo/bar")
if MacOS.version < :catalina if MacOS.version < :catalina
expect(subject.add(resource)).to be nil expect(collector.add(resource)).to be nil
else else
expect(subject.add(resource)).not_to be nil expect(collector.add(resource)).not_to be nil
end end
end end
end end

View File

@ -4,6 +4,8 @@
require "diagnostic" require "diagnostic"
describe Homebrew::Diagnostic::Checks do describe Homebrew::Diagnostic::Checks do
subject(:checks) { described_class.new }
specify "#check_for_unsupported_macos" do specify "#check_for_unsupported_macos" do
ENV.delete("HOMEBREW_DEVELOPER") ENV.delete("HOMEBREW_DEVELOPER")
@ -12,7 +14,7 @@ describe Homebrew::Diagnostic::Checks do
allow(OS::Mac).to receive(:full_version).and_return(macos_version) allow(OS::Mac).to receive(:full_version).and_return(macos_version)
allow(OS::Mac).to receive(:prerelease?).and_return(true) allow(OS::Mac).to receive(:prerelease?).and_return(true)
expect(subject.check_for_unsupported_macos) expect(checks.check_for_unsupported_macos)
.to match("We do not provide support for this pre-release version.") .to match("We do not provide support for this pre-release version.")
end end
@ -24,7 +26,7 @@ describe Homebrew::Diagnostic::Checks do
allow(OS::Mac::Xcode).to receive(:version).and_return("8.0") allow(OS::Mac::Xcode).to receive(:version).and_return("8.0")
allow(OS::Mac::Xcode).to receive(:without_clt?).and_return(true) allow(OS::Mac::Xcode).to receive(:without_clt?).and_return(true)
expect(subject.check_if_xcode_needs_clt_installed) expect(checks.check_if_xcode_needs_clt_installed)
.to match("Xcode alone is not sufficient on El Capitan") .to match("Xcode alone is not sufficient on El Capitan")
end end
@ -34,7 +36,7 @@ describe Homebrew::Diagnostic::Checks do
allow(OS::Mac).to receive(:full_version).and_return(macos_version) allow(OS::Mac).to receive(:full_version).and_return(macos_version)
stub_const("RUBY_VERSION", "1.8.6") stub_const("RUBY_VERSION", "1.8.6")
expect(subject.check_ruby_version) expect(checks.check_ruby_version)
.to match "Ruby version 1.8.6 is unsupported on 10.12" .to match "Ruby version 1.8.6 is unsupported on 10.12"
end end
end end

View File

@ -6,21 +6,21 @@ require "keg"
describe Keg do describe Keg do
include FileUtils include FileUtils
subject { described_class.new(keg_path) } subject(:keg) { described_class.new(keg_path) }
describe "#mach_o_files" do describe "#mach_o_files" do
let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" }
before { (keg_path/"lib").mkpath } before { (keg_path/"lib").mkpath }
after { subject.unlink } after { keg.unlink }
it "skips hardlinks" do it "skips hardlinks" do
cp dylib_path("i386"), keg_path/"lib/i386.dylib" cp dylib_path("i386"), keg_path/"lib/i386.dylib"
ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib"
subject.link keg.link
expect(subject.mach_o_files.count).to eq(1) expect(keg.mach_o_files.count).to eq(1)
end end
it "isn't confused by symlinks" do it "isn't confused by symlinks" do
@ -28,8 +28,8 @@ describe Keg do
ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib"
ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib"
subject.link keg.link
expect(subject.mach_o_files.count).to eq(1) expect(keg.mach_o_files.count).to eq(1)
end end
end end
end end

View File

@ -7,13 +7,13 @@ require "os/mac"
describe OS::Mac do describe OS::Mac do
describe "::languages" do describe "::languages" do
it "returns a list of all languages" do it "returns a list of all languages" do
expect(subject.languages).not_to be_empty expect(described_class.languages).not_to be_empty
end end
end end
describe "::language" do describe "::language" do
it "returns the first item from #languages" do it "returns the first item from #languages" do
expect(subject.language).to eq(subject.languages.first) expect(described_class.language).to eq(described_class.languages.first)
end end
end end

View File

@ -53,26 +53,26 @@ describe Patch do
end end
describe "#patch_files" do describe "#patch_files" do
subject { described_class.create(:p2, nil) } subject(:patch) { described_class.create(:p2, nil) }
context "empty patch" do context "empty patch" do
its(:resource) { is_expected.to be_kind_of Resource::PatchResource } its(:resource) { is_expected.to be_kind_of Resource::PatchResource }
its(:patch_files) { is_expected.to eq(subject.resource.patch_files) } its(:patch_files) { is_expected.to eq(patch.resource.patch_files) }
its(:patch_files) { is_expected.to eq([]) } its(:patch_files) { is_expected.to eq([]) }
end end
it "returns applied patch files" do it "returns applied patch files" do
subject.resource.apply("patch1.diff") patch.resource.apply("patch1.diff")
expect(subject.patch_files).to eq(["patch1.diff"]) expect(patch.patch_files).to eq(["patch1.diff"])
subject.resource.apply("patch2.diff", "patch3.diff") patch.resource.apply("patch2.diff", "patch3.diff")
expect(subject.patch_files).to eq(["patch1.diff", "patch2.diff", "patch3.diff"]) expect(patch.patch_files).to eq(["patch1.diff", "patch2.diff", "patch3.diff"])
subject.resource.apply(["patch4.diff", "patch5.diff"]) patch.resource.apply(["patch4.diff", "patch5.diff"])
expect(subject.patch_files.count).to eq(5) expect(patch.patch_files.count).to eq(5)
subject.resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff") patch.resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff")
expect(subject.patch_files.count).to eq(7) expect(patch.patch_files.count).to eq(7)
end end
end end
end end
@ -86,7 +86,7 @@ describe EmbeddedPatch do
end end
describe ExternalPatch do describe ExternalPatch do
subject { described_class.new(:p1) { url "file:///my.patch" } } subject(:patch) { described_class.new(:p1) { url "file:///my.patch" } }
describe "#url" do describe "#url" do
its(:url) { is_expected.to eq("file:///my.patch") } its(:url) { is_expected.to eq("file:///my.patch") }
@ -98,7 +98,7 @@ describe ExternalPatch do
describe "#cached_download" do describe "#cached_download" do
before do before do
allow(subject.resource).to receive(:cached_download).and_return("/tmp/foo.tar.gz") allow(patch.resource).to receive(:cached_download).and_return("/tmp/foo.tar.gz")
end end
its(:cached_download) { is_expected.to eq("/tmp/foo.tar.gz") } its(:cached_download) { is_expected.to eq("/tmp/foo.tar.gz") }

View File

@ -7,7 +7,7 @@ require "requirement"
describe Requirement do describe Requirement do
alias_matcher :be_a_build_requirement, :be_a_build alias_matcher :be_a_build_requirement, :be_a_build
subject { klass.new } subject(:requirement) { klass.new }
let(:klass) { Class.new(described_class) } let(:klass) { Class.new(described_class) }
@ -111,7 +111,7 @@ describe Requirement do
it "sets up build environment" do it "sets up build environment" do
expect(ENV).to receive(:with_build_environment).and_call_original expect(ENV).to receive(:with_build_environment).and_call_original
subject.satisfied? requirement.satisfied?
end end
end end
@ -126,7 +126,7 @@ describe Requirement do
it "skips setting up build environment" do it "skips setting up build environment" do
expect(ENV).not_to receive(:with_build_environment) expect(ENV).not_to receive(:with_build_environment)
subject.satisfied? requirement.satisfied?
end end
end end
@ -141,8 +141,8 @@ describe Requirement do
it "infers path from #satisfy result" do it "infers path from #satisfy result" do
expect(ENV).to receive(:prepend_path).with("PATH", Pathname.new("/foo/bar")) expect(ENV).to receive(:prepend_path).with("PATH", Pathname.new("/foo/bar"))
subject.satisfied? requirement.satisfied?
subject.modify_build_environment requirement.modify_build_environment
end end
end end
end end
@ -180,53 +180,53 @@ describe Requirement do
let(:klass) { Class.new(described_class) } let(:klass) { Class.new(described_class) }
it "returns nil" do it "returns nil" do
expect(subject.modify_build_environment).to be nil expect(requirement.modify_build_environment).to be nil
end end
end end
end end
describe "#eql? and #==" do describe "#eql? and #==" do
subject { described_class.new } subject(:requirement) { described_class.new }
it "returns true if the names and tags are equal" do it "returns true if the names and tags are equal" do
other = described_class.new other = described_class.new
expect(subject).to eql(other) expect(requirement).to eql(other)
expect(subject).to eq(other) expect(requirement).to eq(other)
end end
it "returns false if names differ" do it "returns false if names differ" do
other = described_class.new other = described_class.new
allow(other).to receive(:name).and_return("foo") allow(other).to receive(:name).and_return("foo")
expect(subject).not_to eql(other) expect(requirement).not_to eql(other)
expect(subject).not_to eq(other) expect(requirement).not_to eq(other)
end end
it "returns false if tags differ" do it "returns false if tags differ" do
other = described_class.new([:optional]) other = described_class.new([:optional])
expect(subject).not_to eql(other) expect(requirement).not_to eql(other)
expect(subject).not_to eq(other) expect(requirement).not_to eq(other)
end end
end end
describe "#hash" do describe "#hash" do
subject { described_class.new } subject(:requirement) { described_class.new }
it "is equal if names and tags are equal" do it "is equal if names and tags are equal" do
other = described_class.new other = described_class.new
expect(subject.hash).to eq(other.hash) expect(requirement.hash).to eq(other.hash)
end end
it "differs if names differ" do it "differs if names differ" do
other = described_class.new other = described_class.new
allow(other).to receive(:name).and_return("foo") allow(other).to receive(:name).and_return("foo")
expect(subject.hash).not_to eq(other.hash) expect(requirement.hash).not_to eq(other.hash)
end end
it "differs if tags differ" do it "differs if tags differ" do
other = described_class.new([:optional]) other = described_class.new([:optional])
expect(subject.hash).not_to eq(other.hash) expect(requirement.hash).not_to eq(other.hash)
end end
end end
end end

View File

@ -4,14 +4,16 @@
require "requirements" require "requirements"
describe Requirements do describe Requirements do
subject(:requirements) { described_class.new }
describe "#<<" do describe "#<<" do
it "returns itself" do it "returns itself" do
expect(subject << Object.new).to be(subject) expect(requirements << Object.new).to be(requirements)
end end
it "merges duplicate requirements" do it "merges duplicate requirements" do
subject << Requirement.new << Requirement.new requirements << Requirement.new << Requirement.new
expect(subject.count).to eq(1) expect(requirements.count).to eq(1)
end end
end end
end end

View File

@ -4,111 +4,111 @@
require "resource" require "resource"
describe Resource do describe Resource do
subject { described_class.new("test") } subject(:resource) { described_class.new("test") }
describe "#url" do describe "#url" do
it "sets the URL" do it "sets the URL" do
subject.url("foo") resource.url("foo")
expect(subject.url).to eq("foo") expect(resource.url).to eq("foo")
end end
it "can set the URL with specifications" do it "can set the URL with specifications" do
subject.url("foo", branch: "master") resource.url("foo", branch: "master")
expect(subject.url).to eq("foo") expect(resource.url).to eq("foo")
expect(subject.specs).to eq(branch: "master") expect(resource.specs).to eq(branch: "master")
end end
it "can set the URL with a custom download strategy class" do it "can set the URL with a custom download strategy class" do
strategy = Class.new(AbstractDownloadStrategy) strategy = Class.new(AbstractDownloadStrategy)
subject.url("foo", using: strategy) resource.url("foo", using: strategy)
expect(subject.url).to eq("foo") expect(resource.url).to eq("foo")
expect(subject.download_strategy).to eq(strategy) expect(resource.download_strategy).to eq(strategy)
end end
it "can set the URL with specifications and a custom download strategy class" do it "can set the URL with specifications and a custom download strategy class" do
strategy = Class.new(AbstractDownloadStrategy) strategy = Class.new(AbstractDownloadStrategy)
subject.url("foo", using: strategy, branch: "master") resource.url("foo", using: strategy, branch: "master")
expect(subject.url).to eq("foo") expect(resource.url).to eq("foo")
expect(subject.specs).to eq(branch: "master") expect(resource.specs).to eq(branch: "master")
expect(subject.download_strategy).to eq(strategy) expect(resource.download_strategy).to eq(strategy)
end end
it "can set the URL with a custom download strategy symbol" do it "can set the URL with a custom download strategy symbol" do
subject.url("foo", using: :git) resource.url("foo", using: :git)
expect(subject.url).to eq("foo") expect(resource.url).to eq("foo")
expect(subject.download_strategy).to eq(GitDownloadStrategy) expect(resource.download_strategy).to eq(GitDownloadStrategy)
end end
it "raises an error if the download strategy class is unknown" do it "raises an error if the download strategy class is unknown" do
expect { subject.url("foo", using: Class.new) }.to raise_error(TypeError) expect { resource.url("foo", using: Class.new) }.to raise_error(TypeError)
end end
it "does not mutate the specifications hash" do it "does not mutate the specifications hash" do
specs = { using: :git, branch: "master" } specs = { using: :git, branch: "master" }
subject.url("foo", specs) resource.url("foo", specs)
expect(subject.specs).to eq(branch: "master") expect(resource.specs).to eq(branch: "master")
expect(subject.using).to eq(:git) expect(resource.using).to eq(:git)
expect(specs).to eq(using: :git, branch: "master") expect(specs).to eq(using: :git, branch: "master")
end end
end end
describe "#version" do describe "#version" do
it "sets the version" do it "sets the version" do
subject.version("1.0") resource.version("1.0")
expect(subject.version).to eq(Version.parse("1.0")) expect(resource.version).to eq(Version.parse("1.0"))
expect(subject.version).not_to be_detected_from_url expect(resource.version).not_to be_detected_from_url
end end
it "can detect the version from a URL" do it "can detect the version from a URL" do
subject.url("https://brew.sh/foo-1.0.tar.gz") resource.url("https://brew.sh/foo-1.0.tar.gz")
expect(subject.version).to eq(Version.parse("1.0")) expect(resource.version).to eq(Version.parse("1.0"))
expect(subject.version).to be_detected_from_url expect(resource.version).to be_detected_from_url
end end
it "can set the version with a scheme" do it "can set the version with a scheme" do
klass = Class.new(Version) klass = Class.new(Version)
subject.version klass.new("1.0") resource.version klass.new("1.0")
expect(subject.version).to eq(Version.parse("1.0")) expect(resource.version).to eq(Version.parse("1.0"))
expect(subject.version).to be_a(klass) expect(resource.version).to be_a(klass)
end end
it "can set the version from a tag" do it "can set the version from a tag" do
subject.url("https://brew.sh/foo-1.0.tar.gz", tag: "v1.0.2") resource.url("https://brew.sh/foo-1.0.tar.gz", tag: "v1.0.2")
expect(subject.version).to eq(Version.parse("1.0.2")) expect(resource.version).to eq(Version.parse("1.0.2"))
expect(subject.version).to be_detected_from_url expect(resource.version).to be_detected_from_url
end end
it "rejects non-string versions" do it "rejects non-string versions" do
expect { subject.version(1) }.to raise_error(TypeError) expect { resource.version(1) }.to raise_error(TypeError)
expect { subject.version(2.0) }.to raise_error(TypeError) expect { resource.version(2.0) }.to raise_error(TypeError)
expect { subject.version(Object.new) }.to raise_error(TypeError) expect { resource.version(Object.new) }.to raise_error(TypeError)
end end
it "returns nil if unset" do it "returns nil if unset" do
expect(subject.version).to be nil expect(resource.version).to be nil
end end
end end
describe "#mirrors" do describe "#mirrors" do
it "is empty by defaults" do it "is empty by defaults" do
expect(subject.mirrors).to be_empty expect(resource.mirrors).to be_empty
end end
it "returns an array of mirrors added with #mirror" do it "returns an array of mirrors added with #mirror" do
subject.mirror("foo") resource.mirror("foo")
subject.mirror("bar") resource.mirror("bar")
expect(subject.mirrors).to eq(%w[foo bar]) expect(resource.mirrors).to eq(%w[foo bar])
end end
end end
describe "#checksum" do describe "#checksum" do
it "returns nil if unset" do it "returns nil if unset" do
expect(subject.checksum).to be nil expect(resource.checksum).to be nil
end end
it "returns the checksum set with #sha256" do it "returns the checksum set with #sha256" do
subject.sha256(TEST_SHA256) resource.sha256(TEST_SHA256)
expect(subject.checksum).to eq(Checksum.new(TEST_SHA256)) expect(resource.checksum).to eq(Checksum.new(TEST_SHA256))
end end
end end
@ -117,23 +117,23 @@ describe Resource do
strategy = Object.new strategy = Object.new
expect(DownloadStrategyDetector) expect(DownloadStrategyDetector)
.to receive(:detect).with("foo", nil).and_return(strategy) .to receive(:detect).with("foo", nil).and_return(strategy)
subject.url("foo") resource.url("foo")
expect(subject.download_strategy).to eq(strategy) expect(resource.download_strategy).to eq(strategy)
end end
end end
describe "#owner" do describe "#owner" do
it "sets the owner" do it "sets the owner" do
owner = Object.new owner = Object.new
subject.owner = owner resource.owner = owner
expect(subject.owner).to eq(owner) expect(resource.owner).to eq(owner)
end end
it "sets its owner to be the patches' owner" do it "sets its owner to be the patches' owner" do
subject.patch(:p1) { url "file:///my.patch" } resource.patch(:p1) { url "file:///my.patch" }
owner = Object.new owner = Object.new
subject.owner = owner resource.owner = owner
subject.patches.each do |p| resource.patches.each do |p|
expect(p.resource.owner).to eq(owner) expect(p.resource.owner).to eq(owner)
end end
end end
@ -141,9 +141,9 @@ describe Resource do
describe "#patch" do describe "#patch" do
it "adds a patch" do it "adds a patch" do
subject.patch(:p1, :DATA) resource.patch(:p1, :DATA)
expect(subject.patches.count).to eq(1) expect(resource.patches.count).to eq(1)
expect(subject.patches.first.strip).to eq(:p1) expect(resource.patches.first.strip).to eq(:p1)
end end
end end
@ -154,18 +154,18 @@ describe Resource do
expect(fn).to receive(:verify_checksum).and_raise(ChecksumMissingError) expect(fn).to receive(:verify_checksum).and_raise(ChecksumMissingError)
expect(fn).to receive(:sha256) expect(fn).to receive(:sha256)
subject.verify_download_integrity(fn) resource.verify_download_integrity(fn)
end end
specify "#verify_download_integrity_mismatch" do specify "#verify_download_integrity_mismatch" do
fn = double(file?: true, basename: "foo") fn = double(file?: true, basename: "foo")
checksum = subject.sha256(TEST_SHA256) checksum = resource.sha256(TEST_SHA256)
expect(fn).to receive(:verify_checksum).with(checksum) expect(fn).to receive(:verify_checksum).with(checksum)
.and_raise(ChecksumMismatchError.new(fn, checksum, Object.new)) .and_raise(ChecksumMismatchError.new(fn, checksum, Object.new))
expect { expect {
subject.verify_download_integrity(fn) resource.verify_download_integrity(fn)
}.to raise_error(ChecksumMismatchError) }.to raise_error(ChecksumMismatchError)
end end
end end

View File

@ -6,6 +6,8 @@ require "sandbox"
describe Sandbox, :needs_macos do describe Sandbox, :needs_macos do
define_negated_matcher :not_matching, :matching define_negated_matcher :not_matching, :matching
subject(:sandbox) { described_class.new }
let(:dir) { mktmpdir } let(:dir) { mktmpdir }
let(:file) { dir/"foo" } let(:file) { dir/"foo" }
@ -14,8 +16,8 @@ describe Sandbox, :needs_macos do
end end
specify "#allow_write" do specify "#allow_write" do
subject.allow_write file sandbox.allow_write file
subject.exec "touch", file sandbox.exec "touch", file
expect(file).to exist expect(file).to exist
end end
@ -23,7 +25,7 @@ describe Sandbox, :needs_macos do
describe "#exec" do describe "#exec" do
it "fails when writing to file not specified with ##allow_write" do it "fails when writing to file not specified with ##allow_write" do
expect { expect {
subject.exec "touch", file sandbox.exec "touch", file
}.to raise_error(ErrorDuringExecution) }.to raise_error(ErrorDuringExecution)
expect(file).not_to exist expect(file).not_to exist
@ -34,7 +36,7 @@ describe Sandbox, :needs_macos do
expect(Utils).to receive(:popen_read).and_return("foo") expect(Utils).to receive(:popen_read).and_return("foo")
expect { subject.exec "false" } expect { sandbox.exec "false" }
.to raise_error(ErrorDuringExecution) .to raise_error(ErrorDuringExecution)
.and output(/foo/).to_stdout .and output(/foo/).to_stdout
end end
@ -49,7 +51,7 @@ describe Sandbox, :needs_macos do
EOS EOS
expect(Utils).to receive(:popen_read).and_return(with_bogus_error) expect(Utils).to receive(:popen_read).and_return(with_bogus_error)
expect { subject.exec "false" } expect { sandbox.exec "false" }
.to raise_error(ErrorDuringExecution) .to raise_error(ErrorDuringExecution)
.and output(a_string_matching(/foo/).and(matching(/bar/).and(not_matching(/Python/)))).to_stdout .and output(a_string_matching(/foo/).and(matching(/bar/).and(not_matching(/Python/)))).to_stdout
end end

View File

@ -4,7 +4,7 @@
require "searchable" require "searchable"
describe Searchable do describe Searchable do
subject { collection.extend(described_class) } subject(:searchable_collection) { collection.extend(described_class) }
let(:collection) { ["with-dashes"] } let(:collection) { ["with-dashes"] }
@ -13,20 +13,20 @@ describe Searchable do
let(:collection) { [["with-dashes", "withdashes"]] } let(:collection) { [["with-dashes", "withdashes"]] }
it "searches by the selected argument" do it "searches by the selected argument" do
expect(subject.search(/withdashes/) { |_, short_name| short_name }).not_to be_empty expect(searchable_collection.search(/withdashes/) { |_, short_name| short_name }).not_to be_empty
expect(subject.search(/withdashes/) { |long_name, _| long_name }).to be_empty expect(searchable_collection.search(/withdashes/) { |long_name, _| long_name }).to be_empty
end end
end end
context "when given a regex" do context "when given a regex" do
it "does not simplify strings" do it "does not simplify strings" do
expect(subject.search(/with-dashes/)).to eq ["with-dashes"] expect(searchable_collection.search(/with-dashes/)).to eq ["with-dashes"]
end end
end end
context "when given a string" do context "when given a string" do
it "simplifies both the query and searched strings" do it "simplifies both the query and searched strings" do
expect(subject.search("with dashes")).to eq ["with-dashes"] expect(searchable_collection.search("with dashes")).to eq ["with-dashes"]
end end
end end
@ -34,14 +34,14 @@ describe Searchable do
let(:collection) { { "foo" => "bar" } } let(:collection) { { "foo" => "bar" } }
it "returns a Hash" do it "returns a Hash" do
expect(subject.search("foo")).to eq "foo" => "bar" expect(searchable_collection.search("foo")).to eq "foo" => "bar"
end end
context "containing nil" do context "containing nil" do
let(:collection) { { "foo" => nil } } let(:collection) { { "foo" => nil } }
it "does not raise an error" do it "does not raise an error" do
expect(subject.search("foo")).to eq "foo" => nil expect(searchable_collection.search("foo")).to eq "foo" => nil
end end
end end
end end

View File

@ -7,182 +7,188 @@ describe SoftwareSpec do
alias_matcher :have_defined_resource, :be_resource_defined alias_matcher :have_defined_resource, :be_resource_defined
alias_matcher :have_defined_option, :be_option_defined alias_matcher :have_defined_option, :be_option_defined
subject(:spec) { described_class.new }
let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") } let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") }
describe "#resource" do describe "#resource" do
it "defines a resource" do it "defines a resource" do
subject.resource("foo") { url "foo-1.0" } spec.resource("foo") { url "foo-1.0" }
expect(subject).to have_defined_resource("foo") expect(spec).to have_defined_resource("foo")
end end
it "sets itself to be the resource's owner" do it "sets itself to be the resource's owner" do
subject.resource("foo") { url "foo-1.0" } spec.resource("foo") { url "foo-1.0" }
subject.owner = owner spec.owner = owner
subject.resources.each_value do |r| spec.resources.each_value do |r|
expect(r.owner).to eq(subject) expect(r.owner).to eq(spec)
end end
end end
it "receives the owner's version if it has no own version" do it "receives the owner's version if it has no own version" do
subject.url("foo-42") spec.url("foo-42")
subject.resource("bar") { url "bar" } spec.resource("bar") { url "bar" }
subject.owner = owner spec.owner = owner
expect(subject.resource("bar").version).to eq("42") expect(spec.resource("bar").version).to eq("42")
end end
it "raises an error when duplicate resources are defined" do it "raises an error when duplicate resources are defined" do
subject.resource("foo") { url "foo-1.0" } spec.resource("foo") { url "foo-1.0" }
expect { expect {
subject.resource("foo") { url "foo-1.0" } spec.resource("foo") { url "foo-1.0" }
}.to raise_error(DuplicateResourceError) }.to raise_error(DuplicateResourceError)
end end
it "raises an error when accessing missing resources" do it "raises an error when accessing missing resources" do
subject.owner = owner spec.owner = owner
expect { expect {
subject.resource("foo") spec.resource("foo")
}.to raise_error(ResourceMissingError) }.to raise_error(ResourceMissingError)
end end
end end
describe "#owner" do describe "#owner" do
it "sets the owner" do it "sets the owner" do
subject.owner = owner spec.owner = owner
expect(subject.owner).to eq(owner) expect(spec.owner).to eq(owner)
end end
it "sets the name" do it "sets the name" do
subject.owner = owner spec.owner = owner
expect(subject.name).to eq(owner.name) expect(spec.name).to eq(owner.name)
end end
end end
describe "#option" do describe "#option" do
it "defines an option" do it "defines an option" do
subject.option("foo") spec.option("foo")
expect(subject).to have_defined_option("foo") expect(spec).to have_defined_option("foo")
end end
it "raises an error when it begins with dashes" do it "raises an error when it begins with dashes" do
expect { expect {
subject.option("--foo") spec.option("--foo")
}.to raise_error(ArgumentError) }.to raise_error(ArgumentError)
end end
it "raises an error when name is empty" do it "raises an error when name is empty" do
expect { expect {
subject.option("") spec.option("")
}.to raise_error(ArgumentError) }.to raise_error(ArgumentError)
end end
it "special cases the cxx11 option" do it "special cases the cxx11 option" do
subject.option(:cxx11) spec.option(:cxx11)
expect(subject).to have_defined_option("c++11") expect(spec).to have_defined_option("c++11")
expect(subject).not_to have_defined_option("cxx11") expect(spec).not_to have_defined_option("cxx11")
end end
it "supports options with descriptions" do it "supports options with descriptions" do
subject.option("bar", "description") spec.option("bar", "description")
expect(subject.options.first.description).to eq("description") expect(spec.options.first.description).to eq("description")
end end
it "defaults to an empty string when no description is given" do it "defaults to an empty string when no description is given" do
subject.option("foo") spec.option("foo")
expect(subject.options.first.description).to eq("") expect(spec.options.first.description).to eq("")
end end
end end
describe "#deprecated_option" do describe "#deprecated_option" do
it "allows specifying deprecated options" do it "allows specifying deprecated options" do
subject.deprecated_option("foo" => "bar") spec.deprecated_option("foo" => "bar")
expect(subject.deprecated_options).not_to be_empty expect(spec.deprecated_options).not_to be_empty
expect(subject.deprecated_options.first.old).to eq("foo") expect(spec.deprecated_options.first.old).to eq("foo")
expect(subject.deprecated_options.first.current).to eq("bar") expect(spec.deprecated_options.first.current).to eq("bar")
end end
it "allows specifying deprecated options as a Hash from an Array/String to an Array/String" do it "allows specifying deprecated options as a Hash from an Array/String to an Array/String" do
subject.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"]) spec.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
expect(subject.deprecated_options).to include(DeprecatedOption.new("foo1", "bar1")) expect(spec.deprecated_options).to include(DeprecatedOption.new("foo1", "bar1"))
expect(subject.deprecated_options).to include(DeprecatedOption.new("foo2", "bar1")) expect(spec.deprecated_options).to include(DeprecatedOption.new("foo2", "bar1"))
expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar2")) expect(spec.deprecated_options).to include(DeprecatedOption.new("foo3", "bar2"))
expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar3")) expect(spec.deprecated_options).to include(DeprecatedOption.new("foo3", "bar3"))
end end
it "raises an error when empty" do it "raises an error when empty" do
expect { expect {
subject.deprecated_option({}) spec.deprecated_option({})
}.to raise_error(ArgumentError) }.to raise_error(ArgumentError)
end end
end end
describe "#depends_on" do describe "#depends_on" do
it "allows specifying dependencies" do it "allows specifying dependencies" do
subject.depends_on("foo") spec.depends_on("foo")
expect(subject.deps.first.name).to eq("foo") expect(spec.deps.first.name).to eq("foo")
end end
it "allows specifying optional dependencies" do it "allows specifying optional dependencies" do
subject.depends_on "foo" => :optional spec.depends_on "foo" => :optional
expect(subject).to have_defined_option("with-foo") expect(spec).to have_defined_option("with-foo")
end end
it "allows specifying recommended dependencies" do it "allows specifying recommended dependencies" do
subject.depends_on "bar" => :recommended spec.depends_on "bar" => :recommended
expect(subject).to have_defined_option("without-bar") expect(spec).to have_defined_option("without-bar")
end end
end end
describe "#uses_from_macos" do describe "#uses_from_macos" do
it "allows specifying dependencies", :needs_linux do it "allows specifying dependencies", :needs_linux do
subject.uses_from_macos("foo") spec.uses_from_macos("foo")
expect(subject.deps.first.name).to eq("foo") expect(spec.deps.first.name).to eq("foo")
end end
it "works with tags", :needs_linux do it "works with tags", :needs_linux do
subject.uses_from_macos("foo" => :build) spec.uses_from_macos("foo" => :build)
expect(subject.deps.first.name).to eq("foo") expect(spec.deps.first.name).to eq("foo")
expect(subject.deps.first.tags).to include(:build) expect(spec.deps.first.tags).to include(:build)
end end
it "ignores OS version specifications", :needs_linux do it "ignores OS version specifications", :needs_linux do
subject.uses_from_macos("foo", since: :mojave) spec.uses_from_macos("foo", since: :mojave)
subject.uses_from_macos("bar" => :build, :since => :mojave) spec.uses_from_macos("bar" => :build, :since => :mojave)
expect(subject.deps.first.name).to eq("foo") expect(spec.deps.first.name).to eq("foo")
expect(subject.deps.last.name).to eq("bar") expect(spec.deps.last.name).to eq("bar")
expect(subject.deps.last.tags).to include(:build) expect(spec.deps.last.tags).to include(:build)
end end
end end
specify "explicit options override defaupt depends_on option description" do specify "explicit options override defaupt depends_on option description" do
subject.option("with-foo", "blah") spec.option("with-foo", "blah")
subject.depends_on("foo" => :optional) spec.depends_on("foo" => :optional)
expect(subject.options.first.description).to eq("blah") expect(spec.options.first.description).to eq("blah")
end end
describe "#patch" do describe "#patch" do
it "adds a patch" do it "adds a patch" do
subject.patch(:p1, :DATA) spec.patch(:p1, :DATA)
expect(subject.patches.count).to eq(1) expect(spec.patches.count).to eq(1)
expect(subject.patches.first.strip).to eq(:p1) expect(spec.patches.first.strip).to eq(:p1)
end end
end end
end end
describe HeadSoftwareSpec do describe HeadSoftwareSpec do
subject(:head_spec) { described_class.new }
specify "#version" do specify "#version" do
expect(subject.version).to eq(Version.create("HEAD")) expect(head_spec.version).to eq(Version.create("HEAD"))
end end
specify "#verify_download_integrity" do specify "#verify_download_integrity" do
expect(subject.verify_download_integrity(Object.new)).to be nil expect(head_spec.verify_download_integrity(Object.new)).to be nil
end end
end end
describe BottleSpecification do describe BottleSpecification do
subject(:bottle_spec) { described_class.new }
describe "#sha256" do describe "#sha256" do
it "works without cellar" do it "works without cellar" do
checksums = { checksums = {
@ -193,8 +199,8 @@ describe BottleSpecification do
} }
checksums.each_pair do |cat, digest| checksums.each_pair do |cat, digest|
subject.sha256(digest => cat) bottle_spec.sha256(digest => cat)
checksum, = subject.checksum_for(cat) checksum, = bottle_spec.checksum_for(cat)
expect(Checksum.new(digest)).to eq(checksum) expect(Checksum.new(digest)).to eq(checksum)
end end
end end
@ -208,8 +214,8 @@ describe BottleSpecification do
] ]
checksums.each do |checksum| checksums.each do |checksum|
subject.sha256(checksum[:tag] => checksum[:digest], cellar: checksum[:cellar]) bottle_spec.sha256(checksum[:tag] => checksum[:digest], cellar: checksum[:cellar])
digest, tag, cellar = subject.checksum_for(checksum[:tag]) digest, tag, cellar = bottle_spec.checksum_for(checksum[:tag])
expect(Checksum.new(checksum[:digest])).to eq(digest) expect(Checksum.new(checksum[:digest])).to eq(digest)
expect(checksum[:tag]).to eq(tag) expect(checksum[:tag]).to eq(tag)
checksum[:cellar] ||= Homebrew::DEFAULT_CELLAR checksum[:cellar] ||= Homebrew::DEFAULT_CELLAR
@ -221,8 +227,8 @@ describe BottleSpecification do
%w[root_url prefix cellar rebuild].each do |method| %w[root_url prefix cellar rebuild].each do |method|
specify "##{method}" do specify "##{method}" do
object = Object.new object = Object.new
subject.public_send(method, object) bottle_spec.public_send(method, object)
expect(subject.public_send(method)).to eq(object) expect(bottle_spec.public_send(method)).to eq(object)
end end
end end
end end

View File

@ -45,7 +45,7 @@ describe SystemCommand::Result do
end end
describe "#plist" do describe "#plist" do
subject { result.plist } subject(:result_plist) { result.plist }
let(:output_array) { [[:stdout, stdout]] } let(:output_array) { [[:stdout, stdout]] }
let(:garbage) { let(:garbage) {
@ -116,7 +116,7 @@ describe SystemCommand::Result do
} }
it "ignores garbage" do it "ignores garbage" do
expect(subject["system-entities"].length).to eq(3) expect(result_plist["system-entities"].length).to eq(3)
end end
context "when verbose" do context "when verbose" do
@ -125,7 +125,7 @@ describe SystemCommand::Result do
end end
it "warns about garbage" do it "warns about garbage" do
expect { subject } expect { result_plist }
.to output(a_string_containing(garbage)).to_stderr .to output(a_string_containing(garbage)).to_stderr
end end
end end
@ -140,7 +140,7 @@ describe SystemCommand::Result do
} }
it "ignores garbage" do it "ignores garbage" do
expect(subject["system-entities"].length).to eq(3) expect(result_plist["system-entities"].length).to eq(3)
end end
context "when verbose" do context "when verbose" do
@ -149,7 +149,7 @@ describe SystemCommand::Result do
end end
it "warns about garbage" do it "warns about garbage" do
expect { subject } expect { result_plist }
.to output(a_string_containing(garbage)).to_stderr .to output(a_string_containing(garbage)).to_stderr
end end
end end
@ -159,9 +159,9 @@ describe SystemCommand::Result do
let(:stdout) { plist } let(:stdout) { plist }
it "successfully parses it" do it "successfully parses it" do
expect(subject.keys).to eq(["system-entities"]) expect(result_plist.keys).to eq(["system-entities"])
expect(subject["system-entities"].length).to eq(3) expect(result_plist["system-entities"].length).to eq(3)
expect(subject["system-entities"].map { |e| e["dev-entry"] }) expect(result_plist["system-entities"].map { |e| e["dev-entry"] })
.to eq(["/dev/disk3s1", "/dev/disk3", "/dev/disk3s2"]) .to eq(["/dev/disk3s1", "/dev/disk3", "/dev/disk3s2"])
end end
end end
@ -170,7 +170,7 @@ describe SystemCommand::Result do
let(:stdout) { "" } let(:stdout) { "" }
it "returns nil" do it "returns nil" do
expect(subject).to be nil expect(result_plist).to be nil
end end
end end
end end

View File

@ -19,7 +19,7 @@ describe Tab do
end end
end end
subject { subject(:tab) {
described_class.new( described_class.new(
"homebrew_version" => HOMEBREW_VERSION, "homebrew_version" => HOMEBREW_VERSION,
"used_options" => used_options.as_flags, "used_options" => used_options.as_flags,
@ -79,15 +79,15 @@ describe Tab do
end end
specify "#include?" do specify "#include?" do
expect(subject).to include("with-foo") expect(tab).to include("with-foo")
expect(subject).to include("without-bar") expect(tab).to include("without-bar")
end end
specify "#with?" do specify "#with?" do
expect(subject).to be_built_with("foo") expect(tab).to be_built_with("foo")
expect(subject).to be_built_with("qux") expect(tab).to be_built_with("qux")
expect(subject).not_to be_built_with("bar") expect(tab).not_to be_built_with("bar")
expect(subject).not_to be_built_with("baz") expect(tab).not_to be_built_with("baz")
end end
specify "#parsed_homebrew_version" do specify "#parsed_homebrew_version" do
@ -146,16 +146,16 @@ describe Tab do
end end
specify "#cxxstdlib" do specify "#cxxstdlib" do
expect(subject.cxxstdlib.compiler).to eq(:clang) expect(tab.cxxstdlib.compiler).to eq(:clang)
expect(subject.cxxstdlib.type).to eq(:libcxx) expect(tab.cxxstdlib.type).to eq(:libcxx)
end end
specify "other attributes" do specify "other attributes" do
expect(subject.HEAD).to eq(TEST_SHA1) expect(tab.HEAD).to eq(TEST_SHA1)
expect(subject.tap.name).to eq("homebrew/core") expect(tab.tap.name).to eq("homebrew/core")
expect(subject.time).to eq(time) expect(tab.time).to eq(time)
expect(subject).not_to be_built_as_bottle expect(tab).not_to be_built_as_bottle
expect(subject).to be_poured_from_bottle expect(tab).to be_poured_from_bottle
end end
describe "::from_file" do describe "::from_file" do
@ -286,19 +286,19 @@ describe Tab do
end end
describe "::for_keg" do describe "::for_keg" do
subject { described_class.for_keg(f.prefix) } subject(:tab_for_keg) { described_class.for_keg(f.prefix) }
it "creates a Tab for a given Keg" do it "creates a Tab for a given Keg" do
f.prefix.mkpath f.prefix.mkpath
f_tab_path.write f_tab_content f_tab_path.write f_tab_content
expect(subject.tabfile).to eq(f_tab_path) expect(tab_for_keg.tabfile).to eq(f_tab_path)
end end
it "can create a Tab for a non-existent Keg" do it "can create a Tab for a non-existent Keg" do
f.prefix.mkpath f.prefix.mkpath
expect(subject.tabfile).to eq(f_tab_path) expect(tab_for_keg.tabfile).to eq(f_tab_path)
end end
end end
@ -359,27 +359,27 @@ describe Tab do
end end
specify "#to_json" do specify "#to_json" do
tab = described_class.new(JSON.parse(subject.to_json)) json_tab = described_class.new(JSON.parse(tab.to_json))
expect(tab.used_options.sort).to eq(subject.used_options.sort) expect(json_tab.used_options.sort).to eq(tab.used_options.sort)
expect(tab.unused_options.sort).to eq(subject.unused_options.sort) expect(json_tab.unused_options.sort).to eq(tab.unused_options.sort)
expect(tab.built_as_bottle).to eq(subject.built_as_bottle) expect(json_tab.built_as_bottle).to eq(tab.built_as_bottle)
expect(tab.poured_from_bottle).to eq(subject.poured_from_bottle) expect(json_tab.poured_from_bottle).to eq(tab.poured_from_bottle)
expect(tab.changed_files).to eq(subject.changed_files) expect(json_tab.changed_files).to eq(tab.changed_files)
expect(tab.tap).to eq(subject.tap) expect(json_tab.tap).to eq(tab.tap)
expect(tab.spec).to eq(subject.spec) expect(json_tab.spec).to eq(tab.spec)
expect(tab.time).to eq(subject.time) expect(json_tab.time).to eq(tab.time)
expect(tab.HEAD).to eq(subject.HEAD) expect(json_tab.HEAD).to eq(tab.HEAD)
expect(tab.compiler).to eq(subject.compiler) expect(json_tab.compiler).to eq(tab.compiler)
expect(tab.stdlib).to eq(subject.stdlib) expect(json_tab.stdlib).to eq(tab.stdlib)
expect(tab.runtime_dependencies).to eq(subject.runtime_dependencies) expect(json_tab.runtime_dependencies).to eq(tab.runtime_dependencies)
expect(tab.stable_version).to eq(subject.stable_version) expect(json_tab.stable_version).to eq(tab.stable_version)
expect(tab.head_version).to eq(subject.head_version) expect(json_tab.head_version).to eq(tab.head_version)
expect(tab.source["path"]).to eq(subject.source["path"]) expect(json_tab.source["path"]).to eq(tab.source["path"])
end end
specify "::remap_deprecated_options" do specify "::remap_deprecated_options" do
deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")] deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")]
remapped_options = described_class.remap_deprecated_options(deprecated_options, subject.used_options) remapped_options = described_class.remap_deprecated_options(deprecated_options, tab.used_options)
expect(remapped_options).to include(Option.new("without-bar")) expect(remapped_options).to include(Option.new("without-bar"))
expect(remapped_options).to include(Option.new("with-foo-new")) expect(remapped_options).to include(Option.new("with-foo-new"))
end end

View File

@ -5,7 +5,7 @@ describe Tap do
alias_matcher :have_formula_file, :be_formula_file alias_matcher :have_formula_file, :be_formula_file
alias_matcher :have_custom_remote, :be_custom_remote alias_matcher :have_custom_remote, :be_custom_remote
subject { described_class.new("Homebrew", "foo") } subject(:homebrew_foo_tap) { described_class.new("Homebrew", "foo") }
let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" }
let(:formula_file) { path/"Formula/foo.rb" } let(:formula_file) { path/"Formula/foo.rb" }
@ -131,13 +131,13 @@ describe Tap do
end end
specify "attributes" do specify "attributes" do
expect(subject.user).to eq("Homebrew") expect(homebrew_foo_tap.user).to eq("Homebrew")
expect(subject.repo).to eq("foo") expect(homebrew_foo_tap.repo).to eq("foo")
expect(subject.name).to eq("homebrew/foo") expect(homebrew_foo_tap.name).to eq("homebrew/foo")
expect(subject.path).to eq(path) expect(homebrew_foo_tap.path).to eq(path)
expect(subject).to be_installed expect(homebrew_foo_tap).to be_installed
expect(subject).to be_official expect(homebrew_foo_tap).to be_official
expect(subject).not_to be_a_core_tap expect(homebrew_foo_tap).not_to be_a_core_tap
end end
specify "#issues_url" do specify "#issues_url" do
@ -150,7 +150,7 @@ describe Tap do
"https://github.com/someone/homebrew-foo" "https://github.com/someone/homebrew-foo"
end end
expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues") expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues")
expect(subject.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues") expect(homebrew_foo_tap.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues")
(Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath
expect(described_class.new("someone", "no-git").issues_url).to be nil expect(described_class.new("someone", "no-git").issues_url).to be nil
@ -161,29 +161,29 @@ describe Tap do
specify "files" do specify "files" do
setup_tap_files setup_tap_files
expect(subject.formula_files).to eq([formula_file]) expect(homebrew_foo_tap.formula_files).to eq([formula_file])
expect(subject.formula_names).to eq(["homebrew/foo/foo"]) expect(homebrew_foo_tap.formula_names).to eq(["homebrew/foo/foo"])
expect(subject.alias_files).to eq([alias_file]) expect(homebrew_foo_tap.alias_files).to eq([alias_file])
expect(subject.aliases).to eq(["homebrew/foo/bar"]) expect(homebrew_foo_tap.aliases).to eq(["homebrew/foo/bar"])
expect(subject.alias_table).to eq("homebrew/foo/bar" => "homebrew/foo/foo") expect(homebrew_foo_tap.alias_table).to eq("homebrew/foo/bar" => "homebrew/foo/foo")
expect(subject.alias_reverse_table).to eq("homebrew/foo/foo" => ["homebrew/foo/bar"]) expect(homebrew_foo_tap.alias_reverse_table).to eq("homebrew/foo/foo" => ["homebrew/foo/bar"])
expect(subject.formula_renames).to eq("oldname" => "foo") expect(homebrew_foo_tap.formula_renames).to eq("oldname" => "foo")
expect(subject.tap_migrations).to eq("removed-formula" => "homebrew/foo") expect(homebrew_foo_tap.tap_migrations).to eq("removed-formula" => "homebrew/foo")
expect(subject.command_files).to eq([cmd_file]) expect(homebrew_foo_tap.command_files).to eq([cmd_file])
expect(subject.to_hash).to be_kind_of(Hash) expect(homebrew_foo_tap.to_hash).to be_kind_of(Hash)
expect(subject).to have_formula_file(formula_file) expect(homebrew_foo_tap).to have_formula_file(formula_file)
expect(subject).to have_formula_file("Formula/foo.rb") expect(homebrew_foo_tap).to have_formula_file("Formula/foo.rb")
expect(subject).not_to have_formula_file("bar.rb") expect(homebrew_foo_tap).not_to have_formula_file("bar.rb")
expect(subject).not_to have_formula_file("Formula/baz.sh") expect(homebrew_foo_tap).not_to have_formula_file("Formula/baz.sh")
end end
describe "#remote" do describe "#remote" do
it "returns the remote URL" do it "returns the remote URL" do
setup_git_repo setup_git_repo
expect(subject.remote).to eq("https://github.com/Homebrew/homebrew-foo") expect(homebrew_foo_tap.remote).to eq("https://github.com/Homebrew/homebrew-foo")
expect { described_class.new("Homebrew", "bar").remote }.to raise_error(TapUnavailableError) expect { described_class.new("Homebrew", "bar").remote }.to raise_error(TapUnavailableError)
expect(subject).not_to have_custom_remote expect(homebrew_foo_tap).not_to have_custom_remote
services_tap = described_class.new("Homebrew", "services") services_tap = described_class.new("Homebrew", "services")
services_tap.path.mkpath services_tap.path.mkpath
@ -195,13 +195,13 @@ describe Tap do
end end
it "returns nil if the Tap is not a Git repository" do it "returns nil if the Tap is not a Git repository" do
expect(subject.remote).to be nil expect(homebrew_foo_tap.remote).to be nil
end end
it "returns nil if Git is not available" do it "returns nil if Git is not available" do
setup_git_repo setup_git_repo
allow(Utils::Git).to receive(:available?).and_return(false) allow(Utils::Git).to receive(:available?).and_return(false)
expect(subject.remote).to be nil expect(homebrew_foo_tap.remote).to be nil
end end
end end
@ -209,15 +209,15 @@ describe Tap do
touch path/"README" touch path/"README"
setup_git_repo setup_git_repo
expect(subject.git_head).to eq("0453e16c8e3fac73104da50927a86221ca0740c2") expect(homebrew_foo_tap.git_head).to eq("0453e16c8e3fac73104da50927a86221ca0740c2")
expect(subject.git_short_head).to eq("0453") expect(homebrew_foo_tap.git_short_head).to eq("0453")
expect(subject.git_last_commit).to match(/\A\d+ .+ ago\Z/) expect(homebrew_foo_tap.git_last_commit).to match(/\A\d+ .+ ago\Z/)
expect(subject.git_last_commit_date).to eq("2017-01-22") expect(homebrew_foo_tap.git_last_commit_date).to eq("2017-01-22")
end end
specify "#private?" do specify "#private?" do
skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials
expect(subject).to be_private expect(homebrew_foo_tap).to be_private
end end
describe "#install" do describe "#install" do
@ -232,7 +232,7 @@ describe Tap do
setup_git_repo setup_git_repo
already_tapped_tap = described_class.new("Homebrew", "foo") already_tapped_tap = described_class.new("Homebrew", "foo")
expect(already_tapped_tap).to be_installed expect(already_tapped_tap).to be_installed
right_remote = subject.remote right_remote = homebrew_foo_tap.remote
expect { already_tapped_tap.install clone_target: right_remote }.to raise_error(TapAlreadyTappedError) expect { already_tapped_tap.install clone_target: right_remote }.to raise_error(TapAlreadyTappedError)
end end
@ -240,7 +240,7 @@ describe Tap do
setup_git_repo setup_git_repo
already_tapped_tap = described_class.new("Homebrew", "foo") already_tapped_tap = described_class.new("Homebrew", "foo")
expect(already_tapped_tap).to be_installed expect(already_tapped_tap).to be_installed
wrong_remote = "#{subject.remote}-oops" wrong_remote = "#{homebrew_foo_tap.remote}-oops"
expect { expect {
already_tapped_tap.install clone_target: wrong_remote already_tapped_tap.install clone_target: wrong_remote
}.to raise_error(TapRemoteMismatchError) }.to raise_error(TapRemoteMismatchError)
@ -297,7 +297,7 @@ describe Tap do
tap = described_class.new("Homebrew", "bar") tap = described_class.new("Homebrew", "bar")
tap.install clone_target: subject.path/".git" tap.install clone_target: homebrew_foo_tap.path/".git"
expect(tap).to be_installed expect(tap).to be_installed
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file
@ -322,7 +322,7 @@ describe Tap do
setup_git_repo setup_git_repo
setup_completion link: true setup_completion link: true
tap = described_class.new("NotHomebrew", "baz") tap = described_class.new("NotHomebrew", "baz")
tap.install clone_target: subject.path/".git" tap.install clone_target: homebrew_foo_tap.path/".git"
(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete (HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete
(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete (HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete
(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete (HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete
@ -343,7 +343,7 @@ describe Tap do
setup_git_repo setup_git_repo
setup_completion link: false setup_completion link: false
tap = described_class.new("NotHomebrew", "baz") tap = described_class.new("NotHomebrew", "baz")
tap.install clone_target: subject.path/".git" tap.install clone_target: homebrew_foo_tap.path/".git"
(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete (HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete
tap.link_completions_and_manpages tap.link_completions_and_manpages
expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file
@ -361,7 +361,7 @@ describe Tap do
setup_git_repo setup_git_repo
setup_completion link: false setup_completion link: false
tap = described_class.new("Homebrew", "baz") tap = described_class.new("Homebrew", "baz")
tap.install clone_target: subject.path/".git" tap.install clone_target: homebrew_foo_tap.path/".git"
(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete (HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete
(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete (HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete
(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete (HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete
@ -380,11 +380,11 @@ describe Tap do
specify "#config" do specify "#config" do
setup_git_repo setup_git_repo
expect(subject.config["foo"]).to be nil expect(homebrew_foo_tap.config["foo"]).to be nil
subject.config["foo"] = "bar" homebrew_foo_tap.config["foo"] = "bar"
expect(subject.config["foo"]).to eq("bar") expect(homebrew_foo_tap.config["foo"]).to eq("bar")
subject.config["foo"] = nil homebrew_foo_tap.config["foo"] = nil
expect(subject.config["foo"]).to be nil expect(homebrew_foo_tap.config["foo"]).to be nil
end end
describe "#each" do describe "#each" do
@ -399,7 +399,7 @@ describe Tap do
setup_tap_files setup_tap_files
expected_result = { "oldname" => "foo" } expected_result = { "oldname" => "foo" }
expect(subject.formula_renames).to eq expected_result expect(homebrew_foo_tap.formula_renames).to eq expected_result
end end
end end
@ -408,7 +408,7 @@ describe Tap do
setup_tap_files setup_tap_files
expected_result = { "removed-formula" => "homebrew/foo" } expected_result = { "removed-formula" => "homebrew/foo" }
expect(subject.tap_migrations).to eq expected_result expect(homebrew_foo_tap.tap_migrations).to eq expected_result
end end
end end
@ -420,7 +420,7 @@ describe Tap do
formula_list: ["foo", "bar"], formula_list: ["foo", "bar"],
formula_hash: { "foo" => "foo1", "bar" => "bar1" }, formula_hash: { "foo" => "foo1", "bar" => "bar1" },
} }
expect(subject.audit_exceptions).to eq expected_result expect(homebrew_foo_tap.audit_exceptions).to eq expected_result
end end
end end
@ -432,7 +432,7 @@ describe Tap do
formula_list: ["foo", "bar"], formula_list: ["foo", "bar"],
formula_hash: { "foo" => "foo1", "bar" => "bar1" }, formula_hash: { "foo" => "foo1", "bar" => "bar1" },
} }
expect(subject.style_exceptions).to eq expected_result expect(homebrew_foo_tap.style_exceptions).to eq expected_result
end end
end end
@ -448,33 +448,35 @@ describe Tap do
"exclude_packages" => ["baz"], "exclude_packages" => ["baz"],
}, },
} }
expect(subject.pypi_formula_mappings).to eq expected_result expect(homebrew_foo_tap.pypi_formula_mappings).to eq expected_result
end end
end end
end end
end end
describe CoreTap do describe CoreTap do
subject(:core_tap) { described_class.new }
specify "attributes" do specify "attributes" do
expect(subject.user).to eq("Homebrew") expect(core_tap.user).to eq("Homebrew")
expect(subject.repo).to eq("core") expect(core_tap.repo).to eq("core")
expect(subject.name).to eq("homebrew/core") expect(core_tap.name).to eq("homebrew/core")
expect(subject.command_files).to eq([]) expect(core_tap.command_files).to eq([])
expect(subject).to be_installed expect(core_tap).to be_installed
expect(subject).not_to be_pinned expect(core_tap).not_to be_pinned
expect(subject).to be_official expect(core_tap).to be_official
expect(subject).to be_a_core_tap expect(core_tap).to be_a_core_tap
end end
specify "forbidden operations" do specify "forbidden operations" do
expect { subject.uninstall }.to raise_error(RuntimeError) expect { core_tap.uninstall }.to raise_error(RuntimeError)
expect { subject.pin }.to raise_error(RuntimeError) expect { core_tap.pin }.to raise_error(RuntimeError)
expect { subject.unpin }.to raise_error(RuntimeError) expect { core_tap.unpin }.to raise_error(RuntimeError)
end end
specify "files" do specify "files" do
path = Tap::TAP_DIRECTORY/"homebrew/homebrew-core" path = Tap::TAP_DIRECTORY/"homebrew/homebrew-core"
formula_file = subject.formula_dir/"foo.rb" formula_file = core_tap.formula_dir/"foo.rb"
formula_file.write <<~RUBY formula_file.write <<~RUBY
class Foo < Formula class Foo < Formula
url "https://brew.sh/foo-1.0.tar.gz" url "https://brew.sh/foo-1.0.tar.gz"
@ -493,21 +495,21 @@ describe CoreTap do
(path/file).write formula_list_file_json (path/file).write formula_list_file_json
end end
alias_file = subject.alias_dir/"bar" alias_file = core_tap.alias_dir/"bar"
alias_file.parent.mkpath alias_file.parent.mkpath
ln_s formula_file, alias_file ln_s formula_file, alias_file
expect(subject.formula_files).to eq([formula_file]) expect(core_tap.formula_files).to eq([formula_file])
expect(subject.formula_names).to eq(["foo"]) expect(core_tap.formula_names).to eq(["foo"])
expect(subject.alias_files).to eq([alias_file]) expect(core_tap.alias_files).to eq([alias_file])
expect(subject.aliases).to eq(["bar"]) expect(core_tap.aliases).to eq(["bar"])
expect(subject.alias_table).to eq("bar" => "foo") expect(core_tap.alias_table).to eq("bar" => "foo")
expect(subject.alias_reverse_table).to eq("foo" => ["bar"]) expect(core_tap.alias_reverse_table).to eq("foo" => ["bar"])
expect(subject.formula_renames).to eq formula_list_file_contents expect(core_tap.formula_renames).to eq formula_list_file_contents
expect(subject.tap_migrations).to eq formula_list_file_contents expect(core_tap.tap_migrations).to eq formula_list_file_contents
expect(subject.audit_exceptions).to eq({ formula_list: formula_list_file_contents }) expect(core_tap.audit_exceptions).to eq({ formula_list: formula_list_file_contents })
expect(subject.style_exceptions).to eq({ formula_hash: formula_list_file_contents }) expect(core_tap.style_exceptions).to eq({ formula_hash: formula_list_file_contents })
expect(subject.pypi_formula_mappings).to eq formula_list_file_contents expect(core_tap.pypi_formula_mappings).to eq formula_list_file_contents
end end
end end

View File

@ -28,14 +28,14 @@ describe "globally-scoped helper methods" do
end end
describe "#pretty_installed" do describe "#pretty_installed" do
subject { pretty_installed("foo") } subject(:pretty_installed_output) { pretty_installed("foo") }
context "when $stdout is a TTY" do context "when $stdout is a TTY" do
before { allow($stdout).to receive(:tty?).and_return(true) } before { allow($stdout).to receive(:tty?).and_return(true) }
context "with HOMEBREW_NO_EMOJI unset" do context "with HOMEBREW_NO_EMOJI unset" do
it "returns a string with a colored checkmark" do it "returns a string with a colored checkmark" do
expect(subject) expect(pretty_installed_output)
.to match(/#{esc 1}foo #{esc 32}#{esc 0}/) .to match(/#{esc 1}foo #{esc 32}#{esc 0}/)
end end
end end
@ -44,7 +44,7 @@ describe "globally-scoped helper methods" do
before { ENV["HOMEBREW_NO_EMOJI"] = "1" } before { ENV["HOMEBREW_NO_EMOJI"] = "1" }
it "returns a string with colored info" do it "returns a string with colored info" do
expect(subject) expect(pretty_installed_output)
.to match(/#{esc 1}foo \(installed\)#{esc 0}/) .to match(/#{esc 1}foo \(installed\)#{esc 0}/)
end end
end end
@ -54,20 +54,20 @@ describe "globally-scoped helper methods" do
before { allow($stdout).to receive(:tty?).and_return(false) } before { allow($stdout).to receive(:tty?).and_return(false) }
it "returns plain text" do it "returns plain text" do
expect(subject).to eq("foo") expect(pretty_installed_output).to eq("foo")
end end
end end
end end
describe "#pretty_uninstalled" do describe "#pretty_uninstalled" do
subject { pretty_uninstalled("foo") } subject(:pretty_uninstalled_output) { pretty_uninstalled("foo") }
context "when $stdout is a TTY" do context "when $stdout is a TTY" do
before { allow($stdout).to receive(:tty?).and_return(true) } before { allow($stdout).to receive(:tty?).and_return(true) }
context "with HOMEBREW_NO_EMOJI unset" do context "with HOMEBREW_NO_EMOJI unset" do
it "returns a string with a colored checkmark" do it "returns a string with a colored checkmark" do
expect(subject) expect(pretty_uninstalled_output)
.to match(/#{esc 1}foo #{esc 31}#{esc 0}/) .to match(/#{esc 1}foo #{esc 31}#{esc 0}/)
end end
end end
@ -76,7 +76,7 @@ describe "globally-scoped helper methods" do
before { ENV["HOMEBREW_NO_EMOJI"] = "1" } before { ENV["HOMEBREW_NO_EMOJI"] = "1" }
it "returns a string with colored info" do it "returns a string with colored info" do
expect(subject) expect(pretty_uninstalled_output)
.to match(/#{esc 1}foo \(uninstalled\)#{esc 0}/) .to match(/#{esc 1}foo \(uninstalled\)#{esc 0}/)
end end
end end
@ -86,7 +86,7 @@ describe "globally-scoped helper methods" do
before { allow($stdout).to receive(:tty?).and_return(false) } before { allow($stdout).to receive(:tty?).and_return(false) }
it "returns plain text" do it "returns plain text" do
expect(subject).to eq("foo") expect(pretty_uninstalled_output).to eq("foo")
end end
end end
end end

View File

@ -72,14 +72,14 @@ end
describe Version do describe Version do
describe "::NULL_TOKEN" do describe "::NULL_TOKEN" do
subject { described_class::NULL_TOKEN } subject(:null_version) { described_class::NULL_TOKEN }
specify "#inspect" do specify "#inspect" do
expect(subject.inspect).to eq("#<Version::NullToken>") expect(null_version.inspect).to eq("#<Version::NullToken>")
end end
it "is equal to itself" do it "is equal to itself" do
expect(subject).to be == described_class::NULL_TOKEN expect(null_version).to be == described_class::NULL_TOKEN
end end
end end