brew/Library/Homebrew/test/cask/cli/options_spec.rb

139 lines
3.8 KiB
Ruby
Raw Normal View History

2017-03-05 19:26:56 +01:00
describe Hbc::CLI, :cask do
2016-08-18 22:11:42 +03:00
it "supports setting the appdir" do
Hbc::CLI.process_options %w[help --appdir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the appdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the prefpanedir" do
Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the prefpanedir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the qlplugindir" do
Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the qlplugindir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the colorpickerdir" do
Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the colorpickerdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
2016-08-18 22:11:42 +03:00
end
2016-10-23 17:32:19 +02:00
it "supports setting the dictionarydir" do
Hbc::CLI.process_options %w[help --dictionarydir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo"))
2016-10-23 17:32:19 +02:00
end
it "supports setting the dictionarydir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar"))
2016-10-23 17:32:19 +02:00
end
2016-08-18 22:11:42 +03:00
it "supports setting the fontdir" do
Hbc::CLI.process_options %w[help --fontdir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the fontdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the servicedir" do
Hbc::CLI.process_options %w[help --servicedir=/some/path/foo]
2017-02-08 13:25:10 +01:00
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo"))
2016-08-18 22:11:42 +03:00
end
it "supports setting the servicedir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"
Hbc::CLI.process_options %w[help]
2017-02-08 13:25:10 +01:00
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar"))
2016-08-18 22:11:42 +03:00
end
it "allows additional options to be passed through" do
rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux]
2017-02-08 13:25:10 +01:00
expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux"))
expect(rest).to eq(%w[edit foo --create])
2016-08-18 22:11:42 +03:00
end
describe "when a mandatory argument is missing" do
it "shows a user-friendly error message" do
2017-02-08 13:25:10 +01:00
expect {
2016-08-18 22:11:42 +03:00
Hbc::CLI.process_options %w[install -f]
2017-02-08 13:25:10 +01:00
}.to raise_error(Hbc::CaskError)
2016-08-18 22:11:42 +03:00
end
end
describe "given an ambiguous option" do
it "shows a user-friendly error message" do
2017-02-08 13:25:10 +01:00
expect {
2016-08-18 22:11:42 +03:00
Hbc::CLI.process_options %w[edit -c]
2017-02-08 13:25:10 +01:00
}.to raise_error(Hbc::CaskError)
2016-08-18 22:11:42 +03:00
end
end
describe "--debug" do
it "sets the Cask debug method to true" do
Hbc::CLI.process_options %w[help --debug]
2017-02-08 13:25:10 +01:00
expect(Hbc.debug).to be true
2016-08-18 22:11:42 +03:00
Hbc.debug = false
end
end
describe "--help" do
it "sets the Cask help method to true" do
Hbc::CLI.process_options %w[foo --help]
2017-02-08 13:25:10 +01:00
expect(Hbc.help).to be true
2016-08-18 22:11:42 +03:00
Hbc.help = false
end
end
end