From 7b2d8ed4b3a1a71da59b1aa1859e844c37ba24c2 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 8 Feb 2017 13:25:10 +0100 Subject: Convert Options test to spec. --- .../Homebrew/cask/spec/cask/cli/options_spec.rb | 140 ++++++++++++++++++++ Library/Homebrew/cask/spec/spec_helper.rb | 32 ++++- .../Homebrew/cask/test/cask/cli/options_test.rb | 144 --------------------- 3 files changed, 167 insertions(+), 149 deletions(-) create mode 100644 Library/Homebrew/cask/spec/cask/cli/options_spec.rb delete mode 100644 Library/Homebrew/cask/test/cask/cli/options_test.rb (limited to 'Library') diff --git a/Library/Homebrew/cask/spec/cask/cli/options_spec.rb b/Library/Homebrew/cask/spec/cask/cli/options_spec.rb new file mode 100644 index 000000000..a4381213a --- /dev/null +++ b/Library/Homebrew/cask/spec/cask/cli/options_spec.rb @@ -0,0 +1,140 @@ +require "spec_helper" + +describe Hbc::CLI do + it "supports setting the appdir" do + Hbc::CLI.process_options %w[help --appdir=/some/path/foo] + + expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the appdir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar")) + end + + it "supports setting the prefpanedir" do + Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo] + + expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the prefpanedir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar")) + end + + it "supports setting the qlplugindir" do + Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo] + + expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the qlplugindir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar")) + end + + it "supports setting the colorpickerdir" do + Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo] + + expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the colorpickerdir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar")) + end + + it "supports setting the dictionarydir" do + Hbc::CLI.process_options %w[help --dictionarydir=/some/path/foo] + + expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the dictionarydir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar")) + end + + it "supports setting the fontdir" do + Hbc::CLI.process_options %w[help --fontdir=/some/path/foo] + + expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the fontdir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar")) + end + + it "supports setting the servicedir" do + Hbc::CLI.process_options %w[help --servicedir=/some/path/foo] + + expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo")) + end + + it "supports setting the servicedir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar")) + end + + it "allows additional options to be passed through" do + rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux] + + expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux")) + expect(rest).to eq(%w[edit foo --create]) + 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(Hbc::CaskError) + 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(Hbc::CaskError) + end + end + + describe "--debug" do + it "sets the Cask debug method to true" do + Hbc::CLI.process_options %w[help --debug] + expect(Hbc.debug).to be true + Hbc.debug = false + end + end + + describe "--help" do + it "sets the Cask help method to true" do + Hbc::CLI.process_options %w[foo --help] + expect(Hbc.help).to be true + Hbc.help = false + end + end +end diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb index 059d13a3a..13ed746b5 100644 --- a/Library/Homebrew/cask/spec/spec_helper.rb +++ b/Library/Homebrew/cask/spec/spec_helper.rb @@ -37,11 +37,33 @@ FileUtils.ln_s Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "h RSpec.configure do |config| config.order = :random config.include(Test::Helper::Shutup) - config.after(:each) do - FileUtils.rm_rf [ - Hbc.appdir.children, - Hbc.caskroom.children, - ] + config.around(:each) do |example| + begin + @__appdir = Hbc.appdir + @__caskroom = Hbc.caskroom + @__prefpanedir = Hbc.prefpanedir + @__qlplugindir = Hbc.qlplugindir + @__servicedir = Hbc.servicedir + + @__argv = ARGV.dup + @__env = ENV.to_hash # dup doesn't work on ENV + + example.run + ensure + ARGV.replace(@__argv) + ENV.replace(@__env) + + Hbc.appdir = @__appdir + Hbc.caskroom = @__caskroom + Hbc.prefpanedir = @__prefpanedir + Hbc.qlplugindir = @__qlplugindir + Hbc.servicedir = @__servicedir + + FileUtils.rm_rf [ + Hbc.appdir.children, + Hbc.caskroom.children, + ] + end end end diff --git a/Library/Homebrew/cask/test/cask/cli/options_test.rb b/Library/Homebrew/cask/test/cask/cli/options_test.rb deleted file mode 100644 index d49e7827b..000000000 --- a/Library/Homebrew/cask/test/cask/cli/options_test.rb +++ /dev/null @@ -1,144 +0,0 @@ -require "test_helper" - -describe Hbc::CLI do - it "supports setting the appdir" do - Hbc::CLI.process_options %w[help --appdir=/some/path/foo] - - Hbc.appdir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the appdir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.appdir.must_equal Pathname("/some/path/bar") - end - - it "supports setting the prefpanedir" do - Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo] - - Hbc.prefpanedir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the prefpanedir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.prefpanedir.must_equal Pathname("/some/path/bar") - end - - it "supports setting the qlplugindir" do - Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo] - - Hbc.qlplugindir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the qlplugindir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.qlplugindir.must_equal Pathname("/some/path/bar") - end - - it "supports setting the colorpickerdir" do - Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo] - - Hbc.colorpickerdir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the colorpickerdir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.colorpickerdir.must_equal Pathname("/some/path/bar") - end - - it "supports setting the dictionarydir" do - Hbc::CLI.process_options %w[help --dictionarydir=/some/path/foo] - - Hbc.dictionarydir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the dictionarydir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.dictionarydir.must_equal Pathname("/some/path/bar") - end - - it "supports setting the fontdir" do - Hbc::CLI.process_options %w[help --fontdir=/some/path/foo] - - Hbc.fontdir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the fontdir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.fontdir.must_equal Pathname("/some/path/bar") - end - - it "supports setting the servicedir" do - Hbc::CLI.process_options %w[help --servicedir=/some/path/foo] - - Hbc.servicedir.must_equal Pathname("/some/path/foo") - end - - it "supports setting the servicedir from ENV" do - ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" - - Hbc::CLI.process_options %w[help] - - Hbc.servicedir.must_equal Pathname("/some/path/bar") - end - - it "allows additional options to be passed through" do - rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux] - - Hbc.appdir.must_equal Pathname("/some/path/qux") - rest.must_equal %w[edit foo --create] - end - - describe "when a mandatory argument is missing" do - it "shows a user-friendly error message" do - lambda { - Hbc::CLI.process_options %w[install -f] - }.must_raise Hbc::CaskError - end - end - - describe "given an ambiguous option" do - it "shows a user-friendly error message" do - lambda { - Hbc::CLI.process_options %w[edit -c] - }.must_raise Hbc::CaskError - end - end - - describe "--debug" do - it "sets the Cask debug method to true" do - Hbc::CLI.process_options %w[help --debug] - Hbc.debug.must_equal true - Hbc.debug = false - end - end - - describe "--help" do - it "sets the Cask help method to true" do - Hbc::CLI.process_options %w[foo --help] - Hbc.help.must_equal true - Hbc.help = false - end - end - - after do - ENV["HOMEBREW_CASK_OPTS"] = nil - end -end -- cgit v1.2.3