aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb21
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/--version.rb18
-rw-r--r--Library/Homebrew/test/cask/cli/--version_spec.rb13
-rw-r--r--Library/Homebrew/test/cask/cli/version_spec.rb9
-rw-r--r--Library/Homebrew/test/cask/cli_spec.rb6
-rw-r--r--Library/Homebrew/test/spec_helper.rb1
-rw-r--r--Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb1
7 files changed, 46 insertions, 23 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index 3176489cb..27bea06ef 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -19,6 +19,7 @@ require "hbc/cli/reinstall"
require "hbc/cli/search"
require "hbc/cli/style"
require "hbc/cli/uninstall"
+require "hbc/cli/--version"
require "hbc/cli/zap"
require "hbc/cli/internal_use_base"
@@ -116,7 +117,7 @@ module Hbc
elsif command.to_s.include?("/") && require?(command.to_s)
# external command as Ruby library with literal path, useful
# for development and troubleshooting
- sym = Pathname.new(command.to_s).basename(".rb").to_s.capitalize
+ sym = File.basename(command.to_s, ".rb").capitalize
klass = begin
const_get(sym)
rescue NameError
@@ -247,16 +248,14 @@ module Hbc
@attempted_verb = attempted_verb
end
- def run(*args)
- if args.include?("--version") || @attempted_verb == "--version"
- puts Hbc.full_version
- else
- purpose
- usage
- unless @attempted_verb.to_s.strip.empty? || @attempted_verb == "help"
- raise CaskError, "Unknown command: #{@attempted_verb}"
- end
- end
+ def run(*_args)
+ purpose
+ usage
+
+ return if @attempted_verb.to_s.strip.empty?
+ return if @attempted_verb == "help"
+
+ raise ArgumentError, "Unknown command: #{@attempted_verb}"
end
def purpose
diff --git a/Library/Homebrew/cask/lib/hbc/cli/--version.rb b/Library/Homebrew/cask/lib/hbc/cli/--version.rb
new file mode 100644
index 000000000..bbc719c3b
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/--version.rb
@@ -0,0 +1,18 @@
+module Hbc
+ class CLI
+ class Version < Base
+ def self.command_name
+ "--#{super}"
+ end
+
+ def self.run(*args)
+ raise ArgumentError, "#{command_name} does not take arguments." unless args.empty?
+ puts Hbc.full_version
+ end
+
+ def self.help
+ "displays the Homebrew-Cask version"
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cask/cli/--version_spec.rb b/Library/Homebrew/test/cask/cli/--version_spec.rb
new file mode 100644
index 000000000..2e5737c9f
--- /dev/null
+++ b/Library/Homebrew/test/cask/cli/--version_spec.rb
@@ -0,0 +1,13 @@
+describe Hbc::CLI::Version, :cask do
+ describe "::run" do
+ it "outputs the current Hombrew-Cask version" do
+ expect { described_class.run }
+ .to output(/\AHomebrew-Cask.*\d+\.\d+\.\d+/).to_stdout
+ .and not_to_output.to_stderr
+ end
+
+ it "does not support arguments" do
+ expect { described_class.run(:foo, :bar) }.to raise_error(ArgumentError)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cask/cli/version_spec.rb b/Library/Homebrew/test/cask/cli/version_spec.rb
deleted file mode 100644
index 2091496fc..000000000
--- a/Library/Homebrew/test/cask/cli/version_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe "brew cask --version", :cask do
- it "respects the --version argument" do
- expect {
- expect {
- Hbc::CLI::NullCommand.new("--version").run
- }.not_to output.to_stderr
- }.to output(Hbc.full_version).to_stdout
- end
-end
diff --git a/Library/Homebrew/test/cask/cli_spec.rb b/Library/Homebrew/test/cask/cli_spec.rb
index 0a4559ff2..0dac89b0e 100644
--- a/Library/Homebrew/test/cask/cli_spec.rb
+++ b/Library/Homebrew/test/cask/cli_spec.rb
@@ -27,8 +27,10 @@ describe Hbc::CLI, :cask do
end
it "passes `--version` along to the subcommand" do
- expect(described_class).to receive(:run_command).with(noop_command, "--version")
- described_class.process(%w[noop --version])
+ version_command = double("CLI::Version")
+ allow(described_class).to receive(:lookup_command).with("--version").and_return(version_command)
+ expect(described_class).to receive(:run_command).with(version_command)
+ described_class.process(["--version"])
end
it "prints help output when subcommand receives `--help` flag" do
diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb
index c8e5cc0f8..2f6274fd1 100644
--- a/Library/Homebrew/test/spec_helper.rb
+++ b/Library/Homebrew/test/spec_helper.rb
@@ -112,4 +112,5 @@ RSpec.configure do |config|
end
end
+RSpec::Matchers.define_negated_matcher :not_to_output, :output
RSpec::Matchers.alias_matcher :have_failed, :be_failed
diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
index a82098a0e..b037068d2 100644
--- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
+++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
@@ -1,6 +1,5 @@
require "open3"
-RSpec::Matchers.define_negated_matcher :not_to_output, :output
RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success
RSpec.shared_context "integration test" do