Merge pull request #2293 from reitermarkus/cask-version

Move `brew cask --version` into separate file.
This commit is contained in:
Markus Reiter 2017-03-08 19:34:24 +01:00 committed by GitHub
commit 6ec55a93eb
7 changed files with 46 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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