Fix tests for CLI::Options DSL.
This commit is contained in:
parent
df1864ee43
commit
02a1e2781f
@ -1,69 +1,64 @@
|
|||||||
describe Hbc::CLI::Audit, :cask do
|
describe Hbc::CLI::Audit, :cask do
|
||||||
let(:auditor) { double }
|
|
||||||
let(:cask) { double }
|
let(:cask) { double }
|
||||||
|
|
||||||
describe "selection of Casks to audit" do
|
describe "selection of Casks to audit" do
|
||||||
it "audits all Casks if no tokens are given" do
|
it "audits all Casks if no tokens are given" do
|
||||||
allow(Hbc).to receive(:all).and_return([cask, cask])
|
allow(Hbc).to receive(:all).and_return([cask, cask])
|
||||||
|
|
||||||
expect(auditor).to receive(:audit).twice.and_return(true)
|
expect(Hbc::Auditor).to receive(:audit).twice.and_return(true)
|
||||||
|
|
||||||
run_audit
|
Hbc::CLI::Audit.run
|
||||||
end
|
end
|
||||||
|
|
||||||
it "audits specified Casks if tokens are given" do
|
it "audits specified Casks if tokens are given" do
|
||||||
cask_token = "nice-app"
|
cask_token = "nice-app"
|
||||||
expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask)
|
expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask)
|
||||||
|
|
||||||
expect(auditor).to receive(:audit)
|
expect(Hbc::Auditor).to receive(:audit)
|
||||||
.with(cask, audit_download: false, check_token_conflicts: false)
|
.with(cask, audit_download: false, check_token_conflicts: false)
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
run_audit(cask_token)
|
Hbc::CLI::Audit.run(cask_token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "rules for downloading a Cask" do
|
describe "rules for downloading a Cask" do
|
||||||
it "does not download the Cask per default" do
|
it "does not download the Cask per default" do
|
||||||
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
||||||
expect(auditor).to receive(:audit)
|
expect(Hbc::Auditor).to receive(:audit)
|
||||||
.with(cask, audit_download: false, check_token_conflicts: false)
|
.with(cask, audit_download: false, check_token_conflicts: false)
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
run_audit("casktoken")
|
Hbc::CLI::Audit.run("casktoken")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "download a Cask if --download flag is set" do
|
it "download a Cask if --download flag is set" do
|
||||||
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
||||||
expect(auditor).to receive(:audit)
|
expect(Hbc::Auditor).to receive(:audit)
|
||||||
.with(cask, audit_download: true, check_token_conflicts: false)
|
.with(cask, audit_download: true, check_token_conflicts: false)
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
run_audit("casktoken", "--download")
|
Hbc::CLI::Audit.run("casktoken", "--download")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "rules for checking token conflicts" do
|
describe "rules for checking token conflicts" do
|
||||||
it "does not check for token conflicts per default" do
|
it "does not check for token conflicts per default" do
|
||||||
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
||||||
expect(auditor).to receive(:audit)
|
expect(Hbc::Auditor).to receive(:audit)
|
||||||
.with(cask, audit_download: false, check_token_conflicts: false)
|
.with(cask, audit_download: false, check_token_conflicts: false)
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
run_audit("casktoken")
|
Hbc::CLI::Audit.run("casktoken")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "checks for token conflicts if --token-conflicts flag is set" do
|
it "checks for token conflicts if --token-conflicts flag is set" do
|
||||||
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
|
||||||
expect(auditor).to receive(:audit)
|
expect(Hbc::Auditor).to receive(:audit)
|
||||||
.with(cask, audit_download: false, check_token_conflicts: true)
|
.with(cask, audit_download: false, check_token_conflicts: true)
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
run_audit("casktoken", "--token-conflicts")
|
Hbc::CLI::Audit.run("casktoken", "--token-conflicts")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_audit(*args)
|
|
||||||
Hbc::CLI::Audit.new(*args, auditor: auditor).run
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
describe Hbc::CLI::Cat, :cask do
|
describe Hbc::CLI::Cat, :cask do
|
||||||
describe "given a basic Cask" do
|
describe "given a basic Cask" do
|
||||||
let(:expected_output) {
|
let(:basic_cask_content) {
|
||||||
<<-EOS.undent
|
<<-EOS.undent
|
||||||
cask 'basic-cask' do
|
cask 'basic-cask' do
|
||||||
version '1.2.3'
|
version '1.2.3'
|
||||||
@ -17,19 +17,19 @@ describe Hbc::CLI::Cat, :cask do
|
|||||||
it "displays the Cask file content about the specified Cask" do
|
it "displays the Cask file content about the specified Cask" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Cat.run("basic-cask")
|
Hbc::CLI::Cat.run("basic-cask")
|
||||||
}.to output(expected_output).to_stdout
|
}.to output(basic_cask_content).to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
it "throws away additional Cask arguments and uses the first" do
|
it "can display multiple Casks" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Cat.run("basic-cask", "local-caffeine")
|
Hbc::CLI::Cat.run("basic-cask", "basic-cask")
|
||||||
}.to output(expected_output).to_stdout
|
}.to output(basic_cask_content * 2).to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
it "throws away stray options" do
|
it "fails when option is unknown" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Cat.run("--notavalidoption", "basic-cask")
|
Hbc::CLI::Cat.run("--notavalidoption", "basic-cask")
|
||||||
}.to output(expected_output).to_stdout
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ describe Hbc::CLI::Cat, :cask do
|
|||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Cat.run("--notavalidoption")
|
Hbc::CLI::Cat.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,11 @@ describe Hbc::CLI::Cleanup, :cask do
|
|||||||
let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath }
|
let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath }
|
||||||
let(:outdated_only) { false }
|
let(:outdated_only) { false }
|
||||||
|
|
||||||
subject { described_class.new(*cask_tokens, cache_location: cache_location, outdated_only: outdated_only) }
|
subject { described_class.new(*cask_tokens, cache_location: cache_location) }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
allow_any_instance_of(described_class).to receive(:outdated_only?).and_return(outdated_only)
|
||||||
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
cache_location.rmtree
|
cache_location.rmtree
|
||||||
|
|||||||
@ -36,16 +36,10 @@ describe Hbc::CLI::Create, :cask do
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "throws away additional Cask arguments and uses the first" do
|
it "raises an exception when more than one Cask is given" do
|
||||||
command = described_class.new("additional-cask", "another-cask")
|
expect {
|
||||||
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("additional-cask"))
|
described_class.run("additional-cask", "another-cask")
|
||||||
command.run
|
}.to raise_error(/Only one Cask can be created at a time./)
|
||||||
end
|
|
||||||
|
|
||||||
it "throws away stray options" do
|
|
||||||
command = described_class.new("--notavalidoption", "yet-another-cask")
|
|
||||||
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("yet-another-cask"))
|
|
||||||
command.run
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an exception when the Cask already exists" do
|
it "raises an exception when the Cask already exists" do
|
||||||
@ -68,11 +62,17 @@ describe Hbc::CLI::Create, :cask do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when no Cask is specified, but an invalid option" do
|
context "when an invalid option is specified" do
|
||||||
it "raises an exception" do
|
it "raises an exception when no Cask is specified" do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("--notavalidoption")
|
described_class.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an exception" do
|
||||||
|
expect {
|
||||||
|
described_class.run("--notavalidoption", "yet-another-cask")
|
||||||
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,10 +9,10 @@ describe Hbc::CLI::Edit, :cask do
|
|||||||
command.run
|
command.run
|
||||||
end
|
end
|
||||||
|
|
||||||
it "throws away additional arguments and uses the first" do
|
it "raises an error when given more than one argument" do
|
||||||
command = described_class.new("local-caffeine", "local-transmission")
|
expect {
|
||||||
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine"))
|
described_class.new("local-caffeine", "local-transmission")
|
||||||
command.run
|
}.to raise_error(/Only one Cask can be created at a time./)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an exception when the Cask doesnt exist" do
|
it "raises an exception when the Cask doesnt exist" do
|
||||||
@ -33,7 +33,7 @@ describe Hbc::CLI::Edit, :cask do
|
|||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
expect {
|
expect {
|
||||||
described_class.run("--notavalidoption")
|
described_class.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -69,7 +69,7 @@ describe Hbc::CLI::Fetch, :cask do
|
|||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Fetch.run("--notavalidoption")
|
Hbc::CLI::Fetch.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -45,7 +45,7 @@ describe Hbc::CLI::Info, :cask do
|
|||||||
it "throws away stray options" do
|
it "throws away stray options" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission")
|
Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission")
|
||||||
}.to output(expected_output).to_stdout
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ describe Hbc::CLI::Info, :cask do
|
|||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Info.run("--notavalidoption")
|
Hbc::CLI::Info.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -40,7 +40,7 @@ describe Hbc::CLI::Install, :cask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Install.run("local-transmission", "")
|
Hbc::CLI::Install.run("local-transmission")
|
||||||
}.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr
|
}.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,7 +115,11 @@ describe Hbc::CLI::Install, :cask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "with an invalid option" do
|
describe "with an invalid option" do
|
||||||
with_options.call(["--notavalidoption"])
|
it "raises an error" do
|
||||||
|
expect {
|
||||||
|
Hbc::CLI::Install.run("--notavalidoption")
|
||||||
|
}.to raise_error(/invalid option/)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
describe Hbc::CLI, :cask do
|
describe Hbc::CLI, :cask do
|
||||||
it "supports setting the appdir" do
|
it "supports setting the appdir" do
|
||||||
Hbc::CLI.process_options %w[help --appdir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--appdir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -8,13 +8,13 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the appdir from ENV" do
|
it "supports setting the appdir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports setting the prefpanedir" do
|
it "supports setting the prefpanedir" do
|
||||||
Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--prefpanedir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -22,13 +22,13 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the prefpanedir from ENV" do
|
it "supports setting the prefpanedir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports setting the qlplugindir" do
|
it "supports setting the qlplugindir" do
|
||||||
Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--qlplugindir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -36,13 +36,13 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the qlplugindir from ENV" do
|
it "supports setting the qlplugindir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports setting the colorpickerdir" do
|
it "supports setting the colorpickerdir" do
|
||||||
Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--colorpickerdir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -50,13 +50,13 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the colorpickerdir from ENV" do
|
it "supports setting the colorpickerdir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports setting the dictionarydir" do
|
it "supports setting the dictionarydir" do
|
||||||
Hbc::CLI.process_options %w[help --dictionarydir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--dictionarydir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -64,13 +64,13 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the dictionarydir from ENV" do
|
it "supports setting the dictionarydir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports setting the fontdir" do
|
it "supports setting the fontdir" do
|
||||||
Hbc::CLI.process_options %w[help --fontdir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--fontdir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -78,13 +78,13 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the fontdir from ENV" do
|
it "supports setting the fontdir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "supports setting the servicedir" do
|
it "supports setting the servicedir" do
|
||||||
Hbc::CLI.process_options %w[help --servicedir=/some/path/foo]
|
Hbc::CLI.new.process_options("help", "--servicedir=/some/path/foo")
|
||||||
|
|
||||||
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo"))
|
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo"))
|
||||||
end
|
end
|
||||||
@ -92,42 +92,22 @@ describe Hbc::CLI, :cask do
|
|||||||
it "supports setting the servicedir from ENV" do
|
it "supports setting the servicedir from ENV" do
|
||||||
ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"
|
ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"
|
||||||
|
|
||||||
Hbc::CLI.process_options %w[help]
|
Hbc::CLI.new.process_options("help")
|
||||||
|
|
||||||
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar"))
|
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows additional options to be passed through" do
|
it "allows additional options to be passed through" do
|
||||||
rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux]
|
rest = Hbc::CLI.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux")
|
||||||
|
|
||||||
expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux"))
|
expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux"))
|
||||||
expect(rest).to eq(%w[edit foo --create])
|
expect(rest).to eq(%w[edit foo --create])
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when a mandatory argument is missing" do
|
|
||||||
it "shows a user-friendly error message" do
|
|
||||||
expect {
|
|
||||||
Hbc::CLI.process_options %w[install -f]
|
|
||||||
}.to raise_error(ArgumentError)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "given an ambiguous option" do
|
|
||||||
it "shows a user-friendly error message" do
|
|
||||||
expect {
|
|
||||||
Hbc::CLI.process_options %w[edit -c]
|
|
||||||
}.to raise_error(ArgumentError)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "--help" do
|
describe "--help" do
|
||||||
it "sets the Cask help method to true" do
|
it "sets the Cask help method to true" do
|
||||||
begin
|
command = Hbc::CLI.new("foo", "--help")
|
||||||
Hbc::CLI.process_options %w[foo --help]
|
expect(command.help?).to be true
|
||||||
expect(Hbc::CLI.help?).to be true
|
|
||||||
ensure
|
|
||||||
Hbc::CLI.help = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,13 +13,13 @@ describe Hbc::CLI::Outdated, :cask do
|
|||||||
shutup do
|
shutup do
|
||||||
installed.each { |cask| InstallHelper.install_with_caskfile(cask) }
|
installed.each { |cask| InstallHelper.install_with_caskfile(cask) }
|
||||||
end
|
end
|
||||||
allow(Hbc::CLI).to receive(:verbose?).and_return(true)
|
allow_any_instance_of(described_class).to receive(:verbose?).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'without --greedy it ignores the Casks with "vesion latest" or "auto_updates true"' do
|
describe 'without --greedy it ignores the Casks with "vesion latest" or "auto_updates true"' do
|
||||||
it "checks all the installed Casks when no token is provided" do
|
it "checks all the installed Casks when no token is provided" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Outdated.run
|
described_class.run
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
local-caffeine (1.2.2) != 1.2.3
|
local-caffeine (1.2.2) != 1.2.3
|
||||||
local-transmission (2.60) != 2.61
|
local-transmission (2.60) != 2.61
|
||||||
@ -28,7 +28,7 @@ describe Hbc::CLI::Outdated, :cask do
|
|||||||
|
|
||||||
it "checks only the tokens specified in the command line" do
|
it "checks only the tokens specified in the command line" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Outdated.run("local-caffeine")
|
described_class.run("local-caffeine")
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
local-caffeine (1.2.2) != 1.2.3
|
local-caffeine (1.2.2) != 1.2.3
|
||||||
EOS
|
EOS
|
||||||
@ -36,26 +36,32 @@ describe Hbc::CLI::Outdated, :cask do
|
|||||||
|
|
||||||
it 'ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do
|
it 'ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Outdated.run("local-caffeine", "auto-updates", "version-latest-string")
|
described_class.run("local-caffeine", "auto-updates", "version-latest-string")
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
local-caffeine (1.2.2) != 1.2.3
|
local-caffeine (1.2.2) != 1.2.3
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "--quiet overrides --verbose" do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(described_class).to receive(:verbose?).and_call_original
|
||||||
|
end
|
||||||
|
|
||||||
it "lists only the names (no versions) of the outdated Casks with --quiet" do
|
it "lists only the names (no versions) of the outdated Casks with --quiet" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Outdated.run("--quiet")
|
described_class.run("--verbose", "--quiet")
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
local-caffeine
|
local-caffeine
|
||||||
local-transmission
|
local-transmission
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "with --greedy it checks additional Casks" do
|
describe "with --greedy it checks additional Casks" do
|
||||||
it 'includes the Casks with "auto_updates true" or "version latest" with --greedy' do
|
it 'includes the Casks with "auto_updates true" or "version latest" with --greedy' do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Outdated.run("--greedy")
|
described_class.run("--greedy")
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
auto-updates (2.57) != 2.61
|
auto-updates (2.57) != 2.61
|
||||||
local-caffeine (1.2.2) != 1.2.3
|
local-caffeine (1.2.2) != 1.2.3
|
||||||
@ -69,7 +75,7 @@ describe Hbc::CLI::Outdated, :cask do
|
|||||||
InstallHelper.install_with_caskfile(cask)
|
InstallHelper.install_with_caskfile(cask)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Outdated.run("--greedy")
|
described_class.run("--greedy")
|
||||||
}.to output(<<-EOS.undent).to_stdout
|
}.to output(<<-EOS.undent).to_stdout
|
||||||
local-caffeine (1.2.2) != 1.2.3
|
local-caffeine (1.2.2) != 1.2.3
|
||||||
local-transmission (2.60) != 2.61
|
local-transmission (2.60) != 2.61
|
||||||
|
|||||||
@ -77,7 +77,7 @@ describe Hbc::CLI::Style, :cask do
|
|||||||
subject { cli.cask_paths }
|
subject { cli.cask_paths }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(described_class).to receive(:cask_tokens_from).and_return(tokens)
|
allow(cli).to receive(:args).and_return(tokens)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when no cask tokens are given" do
|
context "when no cask tokens are given" do
|
||||||
@ -147,33 +147,4 @@ describe Hbc::CLI::Style, :cask do
|
|||||||
expect(subject).to include("--auto-correct", *default_args)
|
expect(subject).to include("--auto-correct", *default_args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#fix?" do
|
|
||||||
subject { cli.fix? }
|
|
||||||
|
|
||||||
context "when --fix is passed as an argument" do
|
|
||||||
let(:args) { ["adium", "--fix"] }
|
|
||||||
it { is_expected.to be_truthy }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when --correct is passed as an argument" do
|
|
||||||
let(:args) { ["adium", "--correct"] }
|
|
||||||
it { is_expected.to be_truthy }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when --auto-correct is passed as an argument" do
|
|
||||||
let(:args) { ["adium", "--auto-correct"] }
|
|
||||||
it { is_expected.to be_truthy }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when --auto-correct is misspelled as --autocorrect" do
|
|
||||||
let(:args) { ["adium", "--autocorrect"] }
|
|
||||||
it { is_expected.to be_truthy }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when no flag equivalent to --fix is passed as an argument" do
|
|
||||||
let(:args) { ["adium"] }
|
|
||||||
it { is_expected.to be_falsey }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -203,7 +203,7 @@ describe Hbc::CLI::Uninstall, :cask do
|
|||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Uninstall.run("--notavalidoption")
|
Hbc::CLI::Uninstall.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -18,8 +18,7 @@ describe Hbc::CLI::Zap, :cask do
|
|||||||
expect(transmission).to be_installed
|
expect(transmission).to be_installed
|
||||||
|
|
||||||
shutup do
|
shutup do
|
||||||
Hbc::CLI::Zap.run("--notavalidoption",
|
Hbc::CLI::Zap.run("local-caffeine", "local-transmission")
|
||||||
"local-caffeine", "local-transmission")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(caffeine).not_to be_installed
|
expect(caffeine).not_to be_installed
|
||||||
@ -67,7 +66,7 @@ describe Hbc::CLI::Zap, :cask do
|
|||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
expect {
|
expect {
|
||||||
Hbc::CLI::Zap.run("--notavalidoption")
|
Hbc::CLI::Zap.run("--notavalidoption")
|
||||||
}.to raise_error(Hbc::CaskUnspecifiedError)
|
}.to raise_error(/invalid option/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,7 +13,7 @@ describe Hbc::CLI, :cask do
|
|||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".process" do
|
context "::run" do
|
||||||
let(:noop_command) { double("CLI::Noop") }
|
let(:noop_command) { double("CLI::Noop") }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@ -30,37 +30,35 @@ describe Hbc::CLI, :cask do
|
|||||||
version_command = double("CLI::Version")
|
version_command = double("CLI::Version")
|
||||||
allow(described_class).to receive(:lookup_command).with("--version").and_return(version_command)
|
allow(described_class).to receive(:lookup_command).with("--version").and_return(version_command)
|
||||||
expect(described_class).to receive(:run_command).with(version_command)
|
expect(described_class).to receive(:run_command).with(version_command)
|
||||||
described_class.process(["--version"])
|
described_class.run("--version")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prints help output when subcommand receives `--help` flag" do
|
it "prints help output when subcommand receives `--help` flag" do
|
||||||
begin
|
command = Hbc::CLI.new("noop", "--help")
|
||||||
expect(described_class).to receive(:run_command).with("help")
|
expect(described_class).to receive(:run_command).with("help")
|
||||||
described_class.process(%w[noop --help])
|
command.run
|
||||||
expect(Hbc::CLI.help?).to eq(true)
|
expect(command.help?).to eq(true)
|
||||||
ensure
|
|
||||||
Hbc::CLI.help = false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "respects the env variable when choosing what appdir to create" do
|
it "respects the env variable when choosing what appdir to create" do
|
||||||
allow(ENV).to receive(:[])
|
allow(ENV).to receive(:[])
|
||||||
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--appdir=/custom/appdir")
|
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--appdir=/custom/appdir")
|
||||||
expect(Hbc).to receive(:appdir=).with(Pathname.new("/custom/appdir"))
|
expect(Hbc).to receive(:appdir=).with(Pathname.new("/custom/appdir"))
|
||||||
described_class.process("noop")
|
described_class.run("noop")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "respects the env variable when choosing a non-default Caskroom location" do
|
it "respects the env variable when choosing a non-default Caskroom location" do
|
||||||
allow(ENV).to receive(:[])
|
allow(ENV).to receive(:[])
|
||||||
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--caskroom=/custom/caskdir")
|
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--caskroom=/custom/caskdir")
|
||||||
expect(Hbc).to receive(:caskroom=).with(Pathname.new("/custom/caskdir"))
|
expect(Hbc).to receive(:caskroom=).with(Pathname.new("/custom/caskdir"))
|
||||||
described_class.process("noop")
|
described_class.run("noop")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "exits with a status of 1 when something goes wrong" do
|
it "exits with a status of 1 when something goes wrong" do
|
||||||
allow(described_class).to receive(:lookup_command).and_raise(Hbc::CaskError)
|
allow(described_class).to receive(:lookup_command).and_raise(Hbc::CaskError)
|
||||||
expect(described_class).to receive(:exit).with(1)
|
command = Hbc::CLI.new("noop")
|
||||||
described_class.process("noop")
|
expect(command).to receive(:exit).with(1)
|
||||||
|
command.run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user