2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
describe Cask::Cmd, :cask do
|
2020-08-01 02:30:46 +02:00
|
|
|
context "when no subcommand is given" do
|
|
|
|
it "raises an error" do
|
|
|
|
expect { subject.run }.to raise_error(UsageError, /subcommand/)
|
2017-05-24 20:34:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-21 02:32:46 +02:00
|
|
|
context "::run" do
|
2020-04-07 08:32:30 +02:00
|
|
|
let(:noop_command) { double("Cmd::Noop", run: nil) }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
it "prints help output when subcommand receives `--help` flag" do
|
2020-08-01 02:30:46 +02:00
|
|
|
expect {
|
|
|
|
described_class.run("info", "--help")
|
|
|
|
}.to output(/Displays information about the given cask/).to_stdout
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "exits with a status of 1 when something goes wrong" do
|
2018-09-06 08:29:14 +02:00
|
|
|
allow(described_class).to receive(:lookup_command).and_raise(Cask::CaskError)
|
2017-06-14 13:23:16 +02:00
|
|
|
command = described_class.new("noop")
|
2017-05-21 02:32:46 +02:00
|
|
|
expect(command).to receive(:exit).with(1)
|
|
|
|
command.run
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
2017-03-16 09:00:57 +01:00
|
|
|
|
2020-04-07 08:32:30 +02:00
|
|
|
it "provides a help message for all commands" do
|
|
|
|
described_class.command_classes.each do |command_class|
|
2017-03-16 09:00:57 +01:00
|
|
|
expect(command_class.help).to match(/\w+/), command_class.name
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|