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

99 lines
2.3 KiB
Ruby
Raw Normal View History

2016-08-18 22:11:42 +03:00
# monkeypatch for testing
2016-09-24 13:52:43 +02:00
module Hbc
class CLI
class Create
def self.exec_editor(*command)
editor_commands << command
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.reset!
@editor_commands = []
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.editor_commands
@editor_commands ||= []
end
end
2016-08-18 22:11:42 +03:00
end
end
2017-03-05 19:26:56 +01:00
describe Hbc::CLI::Create, :cask do
2017-02-08 12:05:42 +01:00
before(:each) do
2016-08-18 22:11:42 +03:00
Hbc::CLI::Create.reset!
end
2017-02-08 12:05:42 +01:00
after(:each) do
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
2016-08-18 22:11:42 +03:00
path = Hbc.path(cask)
path.delete if path.exist?
end
end
it "opens the editor for the specified Cask" do
Hbc::CLI::Create.run("new-cask")
2017-02-08 12:05:42 +01:00
expect(Hbc::CLI::Create.editor_commands).to eq [
2016-10-14 20:33:16 +02:00
[Hbc.path("new-cask")],
]
2016-08-18 22:11:42 +03:00
end
it "drops a template down for the specified Cask" do
Hbc::CLI::Create.run("new-cask")
template = File.read(Hbc.path("new-cask"))
2017-02-08 12:05:42 +01:00
expect(template).to eq <<-EOS.undent
2016-08-18 22:11:42 +03:00
cask 'new-cask' do
version ''
sha256 ''
url 'https://'
name ''
homepage ''
app ''
end
2016-08-24 13:23:27 +02:00
EOS
2016-08-18 22:11:42 +03:00
end
it "throws away additional Cask arguments and uses the first" do
Hbc::CLI::Create.run("additional-cask", "another-cask")
2017-02-08 12:05:42 +01:00
expect(Hbc::CLI::Create.editor_commands).to eq [
2016-10-14 20:33:16 +02:00
[Hbc.path("additional-cask")],
]
2016-08-18 22:11:42 +03:00
end
it "throws away stray options" do
Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask")
2017-02-08 12:05:42 +01:00
expect(Hbc::CLI::Create.editor_commands).to eq [
2016-10-14 20:33:16 +02:00
[Hbc.path("yet-another-cask")],
]
2016-08-18 22:11:42 +03:00
end
it "raises an exception when the Cask already exists" do
2017-02-08 12:05:42 +01:00
expect {
Hbc::CLI::Create.run("basic-cask")
2017-02-08 12:05:42 +01:00
}.to raise_error(Hbc::CaskAlreadyCreatedError)
2016-08-18 22:11:42 +03:00
end
it "allows creating Casks that are substrings of existing Casks" do
Hbc::CLI::Create.run("local-caff")
2017-02-08 12:05:42 +01:00
expect(Hbc::CLI::Create.editor_commands).to eq [
[Hbc.path("local-caff")],
2016-10-14 20:33:16 +02:00
]
2016-08-18 22:11:42 +03:00
end
describe "when no Cask is specified" do
it "raises an exception" do
2017-02-08 12:05:42 +01:00
expect {
2016-08-18 22:11:42 +03:00
Hbc::CLI::Create.run
2017-02-08 12:05:42 +01:00
}.to raise_error(Hbc::CaskUnspecifiedError)
2016-08-18 22:11:42 +03:00
end
end
describe "when no Cask is specified, but an invalid option" do
it "raises an exception" do
2017-02-08 12:05:42 +01:00
expect {
2016-08-18 22:11:42 +03:00
Hbc::CLI::Create.run("--notavalidoption")
2017-02-08 12:05:42 +01:00
}.to raise_error(Hbc::CaskUnspecifiedError)
2016-08-18 22:11:42 +03:00
end
end
end