Autofix RuboCop RSpec failures

This commit is contained in:
Mike McQuaid 2018-09-20 09:07:56 +01:00
parent da404fcb4e
commit 78eba5b815
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
26 changed files with 115 additions and 96 deletions

View File

@ -18,6 +18,7 @@ describe Bottle::Filename do
context "when rebuild is 1" do context "when rebuild is 1" do
let(:rebuild) { 1 } let(:rebuild) { 1 }
its(:extname) { is_expected.to eq ".tag.bottle.1.tar.gz" } its(:extname) { is_expected.to eq ".tag.bottle.1.tar.gz" }
end end
end end

View File

@ -1,23 +1,23 @@
require "cache_store" require "cache_store"
describe CacheStoreDatabase do describe CacheStoreDatabase do
subject { CacheStoreDatabase.new(:sample) } subject { described_class.new(:sample) }
describe "self.use" do describe "self.use" do
let(:type) { :test } let(:type) { :test }
it "creates a new `DatabaseCache` instance" do it "creates a new `DatabaseCache` instance" do
cache_store = double("cache_store", close_if_open!: nil) cache_store = double("cache_store", close_if_open!: nil)
expect(CacheStoreDatabase).to receive(:new).with(type).and_return(cache_store) expect(described_class).to receive(:new).with(type).and_return(cache_store)
expect(cache_store).to receive(:close_if_open!) expect(cache_store).to receive(:close_if_open!)
CacheStoreDatabase.use(type) { |_db| } described_class.use(type) { |_db| }
end end
end end
describe "#set" do describe "#set" do
let(:db) { double("db", :[]= => nil) } let(:db) { double("db", :[]= => nil) }
before(:each) do before do
allow(File).to receive(:write) allow(File).to receive(:write)
allow(subject).to receive(:created?).and_return(true) allow(subject).to receive(:created?).and_return(true)
expect(db).to receive(:has_key?).with(:foo).and_return(false) expect(db).to receive(:has_key?).with(:foo).and_return(false)
@ -25,7 +25,7 @@ describe CacheStoreDatabase do
end end
it "sets the value in the `CacheStoreDatabase`" do it "sets the value in the `CacheStoreDatabase`" do
expect(db).to_not have_key(:foo) expect(db).not_to have_key(:foo)
subject.set(:foo, "bar") subject.set(:foo, "bar")
end end
end end
@ -34,7 +34,7 @@ describe CacheStoreDatabase do
context "database created" do context "database created" do
let(:db) { double("db", :[] => "bar") } let(:db) { double("db", :[] => "bar") }
before(:each) do before do
allow(subject).to receive(:created?).and_return(true) allow(subject).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(subject).to receive(:db).and_return(db)
@ -49,13 +49,13 @@ describe CacheStoreDatabase do
context "database not created" do context "database not created" do
let(:db) { double("db", :[] => nil) } let(:db) { double("db", :[] => nil) }
before(:each) do before do
allow(subject).to receive(:created?).and_return(false) allow(subject).to receive(:created?).and_return(false)
allow(subject).to receive(:db).and_return(db) allow(subject).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)).to_not be("bar") expect(subject.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
@ -69,7 +69,7 @@ describe CacheStoreDatabase do
context "database created" do context "database created" do
let(:db) { double("db", :[] => { foo: "bar" }) } let(:db) { double("db", :[] => { foo: "bar" }) }
before(:each) do before do
allow(subject).to receive(:created?).and_return(true) allow(subject).to receive(:created?).and_return(true)
allow(subject).to receive(:db).and_return(db) allow(subject).to receive(:db).and_return(db)
end end
@ -83,7 +83,7 @@ describe CacheStoreDatabase do
context "database not created" do context "database not created" do
let(:db) { double("db", delete: nil) } let(:db) { double("db", delete: nil) }
before(:each) do before do
allow(subject).to receive(:created?).and_return(false) allow(subject).to receive(:created?).and_return(false)
allow(subject).to receive(:db).and_return(db) allow(subject).to receive(:db).and_return(db)
end end
@ -97,22 +97,22 @@ describe CacheStoreDatabase do
describe "#close_if_open!" do describe "#close_if_open!" do
context "database open" do context "database open" do
before(:each) do before do
subject.instance_variable_set(:@db, instance_double(DBM, close: nil)) subject.instance_variable_set(:@db, instance_double(DBM, close: 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.close_if_open! }.to_not raise_error(NoMethodError) expect { subject.close_if_open! }.not_to raise_error(NoMethodError)
end end
end end
context "database not open" do context "database not open" do
before(:each) do before do
subject.instance_variable_set(:@db, nil) subject.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.close_if_open! }.to_not raise_error(NoMethodError) expect { subject.close_if_open! }.not_to raise_error(NoMethodError)
end end
end end
end end
@ -120,13 +120,13 @@ describe CacheStoreDatabase do
describe "#created?" do describe "#created?" do
let(:cache_path) { Pathname("path/to/homebrew/cache/sample.db") } let(:cache_path) { Pathname("path/to/homebrew/cache/sample.db") }
before(:each) do before do
allow(subject).to receive(:cache_path).and_return(cache_path) allow(subject).to receive(:cache_path).and_return(cache_path)
end end
context "`cache_path.exist?` returns `true`" do context "`File.exist?(cache_path)` returns `true`" do
before(:each) do before do
allow(cache_path).to receive(:exist?).and_return(true) allow(File).to receive(:exist?).with(cache_path).and_return(true)
end end
it "returns `true`" do it "returns `true`" do
@ -134,9 +134,9 @@ describe CacheStoreDatabase do
end end
end end
context "`cache_path.exist?` returns `false`" do context "`File.exist?(cache_path)` returns `false`" do
before(:each) do before do
allow(cache_path).to receive(:exist?).and_return(false) allow(File).to receive(:exist?).with(cache_path).and_return(false)
end end
it "returns `false`" do it "returns `false`" do

View File

@ -112,6 +112,10 @@ describe Cask::Artifact::App, :cask do
FileUtils.chmod 0555, target_path FileUtils.chmod 0555, target_path
end end
after do
FileUtils.chmod 0755, target_path
end
it "overwrites the existing app" do it "overwrites the existing app" do
expect(command).to receive(:run).with( expect(command).to receive(:run).with(
"/bin/chmod", args: [ "/bin/chmod", args: [
@ -148,10 +152,6 @@ describe Cask::Artifact::App, :cask do
contents_path = target_path.join("Contents/Info.plist") contents_path = target_path.join("Contents/Info.plist")
expect(contents_path).to exist expect(contents_path).to exist
end end
after do
FileUtils.chmod 0755, target_path
end
end end
end end
end end

View File

@ -1,7 +1,9 @@
describe Cask::Artifact::Installer, :cask do describe Cask::Artifact::Installer, :cask do
subject(:installer) { described_class.new(cask, **args) }
let(:staged_path) { mktmpdir } let(:staged_path) { mktmpdir }
let(:cask) { instance_double(Cask::Cask, staged_path: staged_path, config: nil) } let(:cask) { instance_double(Cask::Cask, staged_path: staged_path, config: nil) }
subject(:installer) { described_class.new(cask, **args) }
let(:command) { SystemCommand } let(:command) { SystemCommand }
let(:args) { {} } let(:args) { {} }
@ -21,7 +23,7 @@ describe Cask::Artifact::Installer, :cask do
let(:executable) { staged_path/"executable" } let(:executable) { staged_path/"executable" }
let(:args) { { script: { executable: "executable" } } } let(:args) { { script: { executable: "executable" } } }
before(:each) do before do
FileUtils.touch executable FileUtils.touch executable
end end

View File

@ -104,7 +104,7 @@ describe Cask::Cask, :cask do
allow(cask).to receive(:versions).and_return(installed_versions) allow(cask).to receive(:versions).and_return(installed_versions)
allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version)) allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version))
expect(cask).to receive(:outdated_versions).and_call_original expect(cask).to receive(:outdated_versions).and_call_original
is_expected.to eq expected_output expect(subject).to eq expected_output
} }
end end
end end
@ -138,7 +138,7 @@ describe Cask::Cask, :cask do
allow(cask).to receive(:versions).and_return(installed_version) allow(cask).to receive(:versions).and_return(installed_version)
allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version)) allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version))
expect(cask).to receive(:outdated_versions).and_call_original expect(cask).to receive(:outdated_versions).and_call_original
is_expected.to eq expected_output expect(subject).to eq expected_output
} }
end end
end end

View File

@ -20,7 +20,7 @@ describe Cask::Cmd::Info, :cask do
EOS EOS
end end
it "it prints auto_updates if the Cask has `auto_updates true`" do it "prints auto_updates if the Cask has `auto_updates true`" do
expect { expect {
described_class.run("with-auto-updates") described_class.run("with-auto-updates")
}.to output(<<~EOS).to_stdout }.to output(<<~EOS).to_stdout

View File

@ -93,7 +93,7 @@ describe Cask::Cmd::Style, :cask do
end end
it { it {
is_expected.to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask/Casks"), expect(subject).to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask/Casks"),
a_path_ending_with("/third-party/homebrew-tap/Casks")) a_path_ending_with("/third-party/homebrew-tap/Casks"))
} }
end end

View File

@ -12,7 +12,7 @@ describe "Satisfy Dependencies and Requirements", :cask do
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-cask-cyclic")) } let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-cask-cyclic")) }
it { it {
is_expected.to raise_error( expect(subject).to raise_error(
Cask::CaskCyclicDependencyError, Cask::CaskCyclicDependencyError,
"Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies "\ "Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies "\
"on other Casks: with-depends-on-cask-cyclic-helper", "on other Casks: with-depends-on-cask-cyclic-helper",

View File

@ -130,7 +130,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("local-transmission")), Cask::CaskLoader.load(cask_path("local-transmission")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("Transmission.app")).to_not be_quarantined expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined
end end
it "does not quarantine Cask fetches" do it "does not quarantine Cask fetches" do
@ -138,7 +138,7 @@ describe Cask::Quarantine, :cask do
local_transmission = Cask::CaskLoader.load(cask_path("local-transmission")) local_transmission = Cask::CaskLoader.load(cask_path("local-transmission"))
cached_location = Cask::Download.new(local_transmission).perform cached_location = Cask::Download.new(local_transmission).perform
expect(cached_location).to_not be_quarantined expect(cached_location).not_to be_quarantined
end end
it "does not quarantine Cask audits" do it "does not quarantine Cask audits" do
@ -147,7 +147,7 @@ describe Cask::Quarantine, :cask do
local_transmission = Cask::CaskLoader.load(cask_path("local-transmission")) local_transmission = Cask::CaskLoader.load(cask_path("local-transmission"))
cached_location = Cask::Download.new(local_transmission).perform cached_location = Cask::Download.new(local_transmission).perform
expect(cached_location).to_not be_quarantined expect(cached_location).not_to be_quarantined
end end
it "does not quarantine Cask installs even if the fetch was" do it "does not quarantine Cask installs even if the fetch was" do
@ -159,7 +159,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("local-transmission")), Cask::CaskLoader.load(cask_path("local-transmission")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("Transmission.app")).to_not be_quarantined expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined
end end
it "does not quarantine dmg-based Casks" do it "does not quarantine dmg-based Casks" do
@ -169,7 +169,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("container-dmg")), Cask::CaskLoader.load(cask_path("container-dmg")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
end end
it "does not quarantine tar-gz-based Casks" do it "does not quarantine tar-gz-based Casks" do
@ -179,7 +179,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("container-tar-gz")), Cask::CaskLoader.load(cask_path("container-tar-gz")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
end end
it "does not quarantine xar-based Casks" do it "does not quarantine xar-based Casks" do
@ -189,7 +189,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("container-xar")), Cask::CaskLoader.load(cask_path("container-xar")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
end end
it "does not quarantine pure bzip2-based Casks" do it "does not quarantine pure bzip2-based Casks" do
@ -199,7 +199,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("container-bzip2")), Cask::CaskLoader.load(cask_path("container-bzip2")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
end end
it "does not quarantine pure gzip-based Casks" do it "does not quarantine pure gzip-based Casks" do
@ -209,7 +209,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("container-gzip")), Cask::CaskLoader.load(cask_path("container-gzip")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined
end end
it "does not quarantine the pkg in naked-pkg-based Casks" do it "does not quarantine the pkg in naked-pkg-based Casks" do
@ -221,7 +221,7 @@ describe Cask::Quarantine, :cask do
expect( expect(
Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg"), Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg"),
).to_not be_quarantined ).not_to be_quarantined
end end
it "does not quarantine a nested container" do it "does not quarantine a nested container" do
@ -231,7 +231,7 @@ describe Cask::Quarantine, :cask do
Cask::CaskLoader.load(cask_path("nested-app")), Cask::CaskLoader.load(cask_path("nested-app")),
).to be_installed ).to be_installed
expect(Cask::Config.global.appdir.join("MyNestedApp.app")).to_not be_quarantined expect(Cask::Config.global.appdir.join("MyNestedApp.app")).not_to be_quarantined
end end
end end
end end

View File

@ -2,6 +2,7 @@ module Cask
describe Verify, :cask do describe Verify, :cask do
describe "::all" do describe "::all" do
subject(:verification) { described_class.all(cask, downloaded_path) } subject(:verification) { described_class.all(cask, downloaded_path) }
let(:cask) { instance_double(Cask, token: "cask", sha256: expected_sha256) } let(:cask) { instance_double(Cask, token: "cask", sha256: expected_sha256) }
let(:cafebabe) { "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" } let(:cafebabe) { "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" }
let(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" } let(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }

View File

@ -137,7 +137,7 @@ describe Homebrew::Cleanup do
end end
describe "#cleanup_cask", :cask do describe "#cleanup_cask", :cask do
before(:each) do before do
Cask::Cache.path.mkpath Cask::Cache.path.mkpath
end end

View File

@ -2,11 +2,6 @@ require_relative "../cli_parser"
describe Homebrew::CLI::Parser do describe Homebrew::CLI::Parser do
describe "test switch options" do describe "test switch options" do
before do
allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_VERBOSE")
end
subject(:parser) { subject(:parser) {
described_class.new do described_class.new do
switch :verbose, description: "Flag for verbosity" switch :verbose, description: "Flag for verbosity"
@ -15,6 +10,11 @@ describe Homebrew::CLI::Parser do
end end
} }
before do
allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1")
allow(ENV).to receive(:[]).with("HOMEBREW_VERBOSE")
end
it "parses short option" do it "parses short option" do
parser.parse(["-v"]) parser.parse(["-v"])
expect(Homebrew.args).to be_verbose expect(Homebrew.args).to be_verbose

View File

@ -235,7 +235,7 @@ describe CurlDownloadStrategy do
context "when URL ends with file" do context "when URL ends with file" do
it { it {
is_expected.to eq( expect(subject).to eq(
HOMEBREW_CACHE/"downloads/3d1c0ae7da22be9d83fb1eb774df96b7c4da71d3cf07e1cb28555cf9a5e5af70--foo.tar.gz", HOMEBREW_CACHE/"downloads/3d1c0ae7da22be9d83fb1eb774df96b7c4da71d3cf07e1cb28555cf9a5e5af70--foo.tar.gz",
) )
} }
@ -245,7 +245,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 {
is_expected.to eq( expect(subject).to eq(
HOMEBREW_CACHE/"downloads/1ab61269ba52c83994510b1e28dd04167a2f2e8393a35a9c50c1f7d33fd8f619--foo.tar.gz", HOMEBREW_CACHE/"downloads/1ab61269ba52c83994510b1e28dd04167a2f2e8393a35a9c50c1f7d33fd8f619--foo.tar.gz",
) )
} }
@ -253,7 +253,7 @@ describe CurlDownloadStrategy do
end end
describe "#fetch" do describe "#fetch" do
before(:each) do before do
subject.temporary_path.dirname.mkpath subject.temporary_path.dirname.mkpath
FileUtils.touch subject.temporary_path FileUtils.touch subject.temporary_path
end end
@ -337,16 +337,19 @@ describe CurlDownloadStrategy do
describe "#cached_location" do describe "#cached_location" do
context "with a file name trailing the URL path" do context "with a file name trailing the URL path" do
let(:url) { "https://example.com/cask.dmg" } let(:url) { "https://example.com/cask.dmg" }
its("cached_location.extname") { is_expected.to eq(".dmg") } its("cached_location.extname") { is_expected.to eq(".dmg") }
end end
context "with a file name trailing the first query parameter" do context "with a file name trailing the first query parameter" do
let(:url) { "https://example.com/download?file=cask.zip&a=1" } let(:url) { "https://example.com/download?file=cask.zip&a=1" }
its("cached_location.extname") { is_expected.to eq(".zip") } its("cached_location.extname") { is_expected.to eq(".zip") }
end end
context "with a file name trailing the second query parameter" do context "with a file name trailing the second query parameter" do
let(:url) { "https://example.com/dl?a=1&file=cask.zip&b=2" } let(:url) { "https://example.com/dl?a=1&file=cask.zip&b=2" }
its("cached_location.extname") { is_expected.to eq(".zip") } its("cached_location.extname") { is_expected.to eq(".zip") }
end end
@ -384,7 +387,7 @@ describe CurlPostDownloadStrategy do
let(:specs) { {} } let(:specs) { {} }
describe "#fetch" do describe "#fetch" do
before(:each) do before do
subject.temporary_path.dirname.mkpath subject.temporary_path.dirname.mkpath
FileUtils.touch subject.temporary_path FileUtils.touch subject.temporary_path
end end
@ -426,6 +429,7 @@ end
describe ScpDownloadStrategy do describe ScpDownloadStrategy do
subject { described_class.new(url, name, version) } subject { described_class.new(url, name, version) }
let(:name) { "foo" } let(:name) { "foo" }
let(:url) { "scp://example.com/foo.tar.gz" } let(:url) { "scp://example.com/foo.tar.gz" }
let(:version) { nil } let(:version) { nil }
@ -456,6 +460,7 @@ describe ScpDownloadStrategy do
context "when given a valid URL" do context "when given a valid URL" do
let(:url) { "scp://example.com/foo.tar.gz" } let(:url) { "scp://example.com/foo.tar.gz" }
it "copies the file via scp" do it "copies the file via scp" do
expect(subject) expect(subject)
.to receive(:system_command!) .to receive(:system_command!)
@ -468,6 +473,7 @@ describe ScpDownloadStrategy do
context "when given a URL with a username" do context "when given a URL with a username" do
let(:url) { "scp://user@example.com/foo.tar.gz" } let(:url) { "scp://user@example.com/foo.tar.gz" }
it "copies the file via scp" do it "copies the file via scp" do
expect(subject) expect(subject)
.to receive(:system_command!) .to receive(:system_command!)
@ -480,6 +486,7 @@ describe ScpDownloadStrategy do
context "when given a URL with a port" do context "when given a URL with a port" do
let(:url) { "scp://example.com:1234/foo.tar.gz" } let(:url) { "scp://example.com:1234/foo.tar.gz" }
it "copies the file via scp" do it "copies the file via scp" do
expect(subject) expect(subject)
.to receive(:system_command!) .to receive(:system_command!)
@ -492,6 +499,7 @@ describe ScpDownloadStrategy do
context "when given a URL with /~/" do context "when given a URL with /~/" do
let(:url) { "scp://example.com/~/foo.tar.gz" } let(:url) { "scp://example.com/~/foo.tar.gz" }
it "treats the path as relative to the home directory" do it "treats the path as relative to the home directory" do
expect(subject) expect(subject)
.to receive(:system_command!) .to receive(:system_command!)
@ -562,7 +570,7 @@ describe DownloadStrategyDetector do
it "returns S3DownloadStrategy" do it "returns S3DownloadStrategy" do
allow(described_class).to receive(:require_aws_sdk).and_return(true) allow(described_class).to receive(:require_aws_sdk).and_return(true)
is_expected.to eq(S3DownloadStrategy) expect(subject).to eq(S3DownloadStrategy)
end end
end end
@ -572,12 +580,13 @@ describe DownloadStrategyDetector do
it "requires aws-sdk-s3" do it "requires aws-sdk-s3" do
allow(described_class).to receive(:require_aws_sdk).and_return(true) allow(described_class).to receive(:require_aws_sdk).and_return(true)
is_expected.to eq(S3DownloadStrategy) expect(subject).to eq(S3DownloadStrategy)
end end
end end
context "when given an scp URL" do context "when given an scp URL" do
let(:url) { "scp://example.com/brew.tar.gz" } let(:url) { "scp://example.com/brew.tar.gz" }
it { is_expected.to eq(ScpDownloadStrategy) } it { is_expected.to eq(ScpDownloadStrategy) }
end end

View File

@ -1,5 +1,6 @@
describe ErrorDuringExecution do describe ErrorDuringExecution do
subject(:error) { described_class.new(command, status: status, output: output) } subject(:error) { described_class.new(command, status: status, output: output) }
let(:command) { ["false"] } let(:command) { ["false"] }
let(:status) { instance_double(Process::Status, exitstatus: exitstatus) } let(:status) { instance_double(Process::Status, exitstatus: exitstatus) }
let(:exitstatus) { 1 } let(:exitstatus) { 1 }
@ -43,7 +44,7 @@ describe ErrorDuringExecution do
end end
its(:to_s) { its(:to_s) {
is_expected.to eq <<~EOS expect(subject).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")}
@ -55,7 +56,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) {
is_expected expect(subject)
.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

@ -16,7 +16,7 @@ describe FormulaValidationError do
subject { described_class.new("foo", "sha257", "magic") } subject { described_class.new("foo", "sha257", "magic") }
its(:to_s) { its(:to_s) {
is_expected.to eq(%q(invalid attribute for formula 'foo': sha257 ("magic"))) expect(subject).to eq(%q(invalid attribute for formula 'foo': sha257 ("magic")))
} }
end end
@ -49,7 +49,7 @@ describe FormulaUnavailableError do
end end
its(:to_s) { its(:to_s) {
is_expected.to eq('No available formula with the name "foo" (dependency of foobar)') expect(subject).to eq('No available formula with the name "foo" (dependency of foobar)')
} }
end end
end end
@ -76,7 +76,7 @@ describe FormulaClassUnavailableError do
let(:list) { [] } let(:list) { [] }
its(:to_s) { its(:to_s) {
is_expected.to match(/Expected to find class Foo, but found no classes\./) expect(subject).to match(/Expected to find class Foo, but found no classes\./)
} }
end end
@ -84,7 +84,7 @@ describe FormulaClassUnavailableError do
let(:list) { [mod.const_get(:Bar)] } let(:list) { [mod.const_get(:Bar)] }
its(:to_s) { its(:to_s) {
is_expected.to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./) expect(subject).to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./)
} }
end end
@ -184,6 +184,7 @@ end
describe ErrorDuringExecution do describe ErrorDuringExecution do
subject { described_class.new(["badprg", "arg1", "arg2"], status: status) } subject { described_class.new(["badprg", "arg1", "arg2"], status: status) }
let(:status) { instance_double(Process::Status, exitstatus: 17) } let(:status) { instance_double(Process::Status, exitstatus: 17) }
its(:to_s) { is_expected.to eq("Failure while executing; `badprg arg1 arg2` exited with 17.") } its(:to_s) { is_expected.to eq("Failure while executing; `badprg arg1 arg2` exited with 17.") }

View File

@ -137,7 +137,7 @@ describe Formulary do
context "with installed Formula" do context "with installed Formula" do
before do before do
allow(Formulary).to receive(:loader_for).and_call_original allow(described_class).to receive(:loader_for).and_call_original
stub_formula_loader formula("patchelf") { url "patchelf-1.0" } stub_formula_loader formula("patchelf") { url "patchelf-1.0" }
allow(Formula["patchelf"]).to receive(:installed?).and_return(true) allow(Formula["patchelf"]).to receive(:installed?).and_return(true)
end end

View File

@ -1,14 +1,14 @@
require "linkage_cache_store" require "linkage_cache_store"
describe LinkageCacheStore do describe LinkageCacheStore do
subject { described_class.new(keg_name, database) }
let(:keg_name) { "keg_name" } let(:keg_name) { "keg_name" }
let(:database) { double("database") } let(:database) { double("database") }
subject { LinkageCacheStore.new(keg_name, database) }
describe "#keg_exists?" do describe "#keg_exists?" do
context "`keg_name` exists in cache" do context "`keg_name` exists in cache" do
before(:each) do before do
expect(database).to receive(:get).with(keg_name).and_return("") expect(database).to receive(:get).with(keg_name).and_return("")
end end
@ -18,7 +18,7 @@ describe LinkageCacheStore do
end end
context "`keg_name` does not exist in cache" do context "`keg_name` does not exist in cache" do
before(:each) do before do
expect(database).to receive(:get).with(keg_name).and_return(nil) expect(database).to receive(:get).with(keg_name).and_return(nil)
end end
@ -52,7 +52,7 @@ describe LinkageCacheStore do
describe "#fetch_type" do describe "#fetch_type" do
context "`HASH_LINKAGE_TYPES.include?(type)`" do context "`HASH_LINKAGE_TYPES.include?(type)`" do
before(:each) do before do
expect(database).to receive(:get).with(keg_name).and_return(nil) expect(database).to receive(:get).with(keg_name).and_return(nil)
end end

View File

@ -2,7 +2,7 @@ require "messages"
require "spec_helper" require "spec_helper"
describe Messages do describe Messages do
let(:messages) { Messages.new } let(:messages) { described_class.new }
let(:test_formula) { formula("foo") { url("https://example.com/foo-0.1.tgz") } } let(:test_formula) { formula("foo") { url("https://example.com/foo-0.1.tgz") } }
let(:elapsed_time) { 1.1 } let(:elapsed_time) { 1.1 }
@ -18,7 +18,7 @@ describe Messages do
it "increases the formula count" do it "increases the formula count" do
expect { expect {
messages.formula_installed(test_formula, elapsed_time) messages.formula_installed(test_formula, elapsed_time)
}.to change { messages.formula_count }.by(1) }.to change(messages, :formula_count).by(1)
end end
it "adds to install_times" do it "adds to install_times" do

View File

@ -24,24 +24,24 @@ describe OS::Mac do
it "calls sdk_path on Xcode-only systems" do it "calls sdk_path on Xcode-only systems" do
allow(OS::Mac::Xcode).to receive(:installed?).and_return(true) allow(OS::Mac::Xcode).to receive(:installed?).and_return(true)
allow(OS::Mac::CLT).to receive(:installed?).and_return(false) allow(OS::Mac::CLT).to receive(:installed?).and_return(false)
expect(OS::Mac).to receive(:sdk_path) expect(described_class).to receive(:sdk_path)
OS::Mac.sdk_path_if_needed described_class.sdk_path_if_needed
end end
it "does not call sdk_path on Xcode-and-CLT systems with system headers" do it "does not call sdk_path on Xcode-and-CLT systems with system headers" do
allow(OS::Mac::Xcode).to receive(:installed?).and_return(true) allow(OS::Mac::Xcode).to receive(:installed?).and_return(true)
allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(true)
allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(false) allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(false)
expect(OS::Mac).not_to receive(:sdk_path) expect(described_class).not_to receive(:sdk_path)
OS::Mac.sdk_path_if_needed described_class.sdk_path_if_needed
end end
it "does not call sdk_path on CLT-only systems with no CLT SDK" do it "does not call sdk_path on CLT-only systems with no CLT SDK" do
allow(OS::Mac::Xcode).to receive(:installed?).and_return(false) allow(OS::Mac::Xcode).to receive(:installed?).and_return(false)
allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(true)
allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(false) allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(false)
expect(OS::Mac).not_to receive(:sdk_path) expect(described_class).not_to receive(:sdk_path)
OS::Mac.sdk_path_if_needed described_class.sdk_path_if_needed
end end
it "does not call sdk_path on CLT-only systems with a CLT SDK if the system provides headers" do it "does not call sdk_path on CLT-only systems with a CLT SDK if the system provides headers" do
@ -49,8 +49,8 @@ describe OS::Mac do
allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(true)
allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(true) allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(true)
allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(false) allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(false)
expect(OS::Mac).not_to receive(:sdk_path) expect(described_class).not_to receive(:sdk_path)
OS::Mac.sdk_path_if_needed described_class.sdk_path_if_needed
end end
it "calls sdk_path on CLT-only systems with a CLT SDK if the system does not provide headers" do it "calls sdk_path on CLT-only systems with a CLT SDK if the system does not provide headers" do
@ -58,8 +58,8 @@ describe OS::Mac do
allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(true)
allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(true) allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(true)
allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(true) allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(true)
expect(OS::Mac).to receive(:sdk_path) expect(described_class).to receive(:sdk_path)
OS::Mac.sdk_path_if_needed described_class.sdk_path_if_needed
end end
end end
end end

View File

@ -1,15 +1,16 @@
require "system_command" require "system_command"
describe SystemCommand::Result do describe SystemCommand::Result do
subject(:result) {
described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true))
}
let(:output_array) { let(:output_array) {
[ [
[:stdout, "output\n"], [:stdout, "output\n"],
[:stderr, "error\n"], [:stderr, "error\n"],
] ]
} }
subject(:result) {
described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true))
}
describe "#to_ary" do describe "#to_ary" do
it "can be destructed like `Open3.capture3`" do it "can be destructed like `Open3.capture3`" do
@ -41,6 +42,7 @@ describe SystemCommand::Result do
describe "#plist" do describe "#plist" do
subject { result.plist } subject { result.plist }
let(:output_array) { [[:stdout, stdout]] } let(:output_array) { [[:stdout, stdout]] }
let(:garbage) { let(:garbage) {
<<~EOS <<~EOS
@ -114,7 +116,7 @@ describe SystemCommand::Result do
end end
context "when verbose" do context "when verbose" do
before(:each) do before do
allow(ARGV).to receive(:verbose?).and_return(true) allow(ARGV).to receive(:verbose?).and_return(true)
end end
@ -138,7 +140,7 @@ describe SystemCommand::Result do
end end
context "when verbose" do context "when verbose" do
before(:each) do before do
allow(ARGV).to receive(:verbose?).and_return(true) allow(ARGV).to receive(:verbose?).and_return(true)
end end

View File

@ -1,9 +1,5 @@
describe SystemCommand do describe SystemCommand do
describe "#initialize" do describe "#initialize" do
let(:env_args) { ["bash", "-c", 'printf "%s" "${A?}" "${B?}" "${C?}"'] }
let(:env) { { "A" => "1", "B" => "2", "C" => "3" } }
let(:sudo) { false }
subject(:command) { subject(:command) {
described_class.new( described_class.new(
"env", "env",
@ -14,6 +10,10 @@ describe SystemCommand do
) )
} }
let(:env_args) { ["bash", "-c", 'printf "%s" "${A?}" "${B?}" "${C?}"'] }
let(:env) { { "A" => "1", "B" => "2", "C" => "3" } }
let(:sudo) { false }
context "when given some environment variables" do context "when given some environment variables" do
its("run!.stdout") { is_expected.to eq("123") } its("run!.stdout") { is_expected.to eq("123") }
@ -237,7 +237,7 @@ describe SystemCommand do
context "when given an executable with spaces and no arguments" do context "when given an executable with spaces and no arguments" do
let(:executable) { mktmpdir/"App Uninstaller" } let(:executable) { mktmpdir/"App Uninstaller" }
before(:each) do before do
executable.write <<~SH executable.write <<~SH
#!/usr/bin/env bash #!/usr/bin/env bash
true true

View File

@ -1,13 +1,15 @@
require_relative "shared_examples" require_relative "shared_examples"
describe UnpackStrategy::Directory do describe UnpackStrategy::Directory do
subject(:strategy) { described_class.new(path) }
let(:path) { let(:path) {
mktmpdir.tap do |path| mktmpdir.tap do |path|
FileUtils.touch path/"file" FileUtils.touch path/"file"
FileUtils.ln_s "file", path/"symlink" FileUtils.ln_s "file", path/"symlink"
end end
} }
subject(:strategy) { described_class.new(path) }
let(:unpack_dir) { mktmpdir } let(:unpack_dir) { mktmpdir }
it "does not follow symlinks" do it "does not follow symlinks" do

View File

@ -5,7 +5,7 @@ describe UnpackStrategy::Subversion, :needs_svn do
let(:working_copy) { mktmpdir } let(:working_copy) { mktmpdir }
let(:path) { working_copy } let(:path) { working_copy }
before(:each) do before do
system "svnadmin", "create", repo system "svnadmin", "create", repo
system "svn", "checkout", "file://#{repo}", working_copy system "svn", "checkout", "file://#{repo}", working_copy

View File

@ -12,7 +12,7 @@ describe UpdateMigrator do
let(:old_cache_file) { HOMEBREW_CACHE/"#{formula_name}-1.2.3.tar.gz" } let(:old_cache_file) { HOMEBREW_CACHE/"#{formula_name}-1.2.3.tar.gz" }
let(:new_cache_file) { HOMEBREW_CACHE/"#{formula_name}--1.2.3.tar.gz" } let(:new_cache_file) { HOMEBREW_CACHE/"#{formula_name}--1.2.3.tar.gz" }
before(:each) do before do
FileUtils.touch old_cache_file FileUtils.touch old_cache_file
allow(Formula).to receive(:each).and_yield(f) allow(Formula).to receive(:each).and_yield(f)
end end
@ -58,7 +58,7 @@ describe UpdateMigrator do
HOMEBREW_CACHE/"downloads/5994e3a27baa3f448a001fb071ab1f0bf25c87aebcb254d91a6d0b02f46eef86--foo-1.2.3.tar.gz" HOMEBREW_CACHE/"downloads/5994e3a27baa3f448a001fb071ab1f0bf25c87aebcb254d91a6d0b02f46eef86--foo-1.2.3.tar.gz"
} }
before(:each) do before do
old_cache_file.dirname.mkpath old_cache_file.dirname.mkpath
FileUtils.touch old_cache_file FileUtils.touch old_cache_file
allow(Formula).to receive(:[]).and_return(f) allow(Formula).to receive(:[]).and_return(f)

View File

@ -10,7 +10,7 @@ describe Utils::Analytics do
it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do
stub_const("HOMEBREW_PREFIX", "blah") stub_const("HOMEBREW_PREFIX", "blah")
expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, #{Utils::Analytics.custom_prefix_label}") expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, #{described_class.custom_prefix_label}")
end end
it "includes CI when ENV['CI'] is set" do it "includes CI when ENV['CI'] is set" do
@ -20,7 +20,7 @@ describe Utils::Analytics do
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
stub_const("HOMEBREW_PREFIX", Homebrew::DEFAULT_PREFIX) stub_const("HOMEBREW_PREFIX", Homebrew::DEFAULT_PREFIX)
expect(described_class.os_prefix_ci).not_to include(Utils::Analytics.custom_prefix_label) expect(described_class.os_prefix_ci).not_to include(described_class.custom_prefix_label)
end end
end end
end end

View File

@ -9,7 +9,7 @@ describe "curl" do
it "doesn't return -q as the first argument when HOMEBREW_CURLRC is set" do it "doesn't return -q as the first argument when HOMEBREW_CURLRC is set" do
ENV["HOMEBREW_CURLRC"] = "1" ENV["HOMEBREW_CURLRC"] = "1"
expect(curl_args("foo").first).to_not eq("-q") expect(curl_args("foo").first).not_to eq("-q")
end end
end end
end end