2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
require_relative "shared_examples/requires_cask_token"
|
|
|
|
require_relative "shared_examples/invalid_option"
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
describe Cask::Cmd::Create, :cask do
|
2018-03-25 13:30:37 +01:00
|
|
|
around do |example|
|
2019-10-13 10:03:26 +01:00
|
|
|
example.run
|
|
|
|
ensure
|
|
|
|
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
|
|
|
|
FileUtils.rm_f Cask::CaskLoader.path(cask)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2018-03-25 13:30:37 +01:00
|
|
|
before do
|
2017-05-19 21:20:51 +02:00
|
|
|
allow_any_instance_of(described_class).to receive(:exec_editor)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
it_behaves_like "a command that requires a Cask token"
|
|
|
|
it_behaves_like "a command that handles invalid options"
|
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
it "opens the editor for the specified Cask" do
|
2017-05-19 21:20:51 +02:00
|
|
|
command = described_class.new("new-cask")
|
2018-09-06 08:29:14 +02:00
|
|
|
expect(command).to receive(:exec_editor).with(Cask::CaskLoader.path("new-cask"))
|
2017-05-19 21:20:51 +02:00
|
|
|
command.run
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "drops a template down for the specified Cask" do
|
2017-05-19 21:20:51 +02:00
|
|
|
described_class.run("new-cask")
|
2018-09-06 08:29:14 +02:00
|
|
|
template = File.read(Cask::CaskLoader.path("new-cask"))
|
2018-07-11 15:17:40 +02:00
|
|
|
expect(template).to eq <<~RUBY
|
2016-08-18 22:11:42 +03:00
|
|
|
cask 'new-cask' do
|
|
|
|
version ''
|
|
|
|
sha256 ''
|
|
|
|
|
2019-04-07 02:10:01 +02:00
|
|
|
url "https://"
|
2016-08-18 22:11:42 +03:00
|
|
|
name ''
|
|
|
|
homepage ''
|
|
|
|
|
|
|
|
app ''
|
|
|
|
end
|
2018-07-11 15:17:40 +02:00
|
|
|
RUBY
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-05-21 02:32:46 +02:00
|
|
|
it "raises an exception when more than one Cask is given" do
|
|
|
|
expect {
|
|
|
|
described_class.run("additional-cask", "another-cask")
|
2017-09-11 08:37:15 +02:00
|
|
|
}.to raise_error(/Only one Cask can be created at a time\./)
|
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 {
|
2017-05-19 21:20:51 +02:00
|
|
|
described_class.run("basic-cask")
|
2018-09-06 08:29:14 +02:00
|
|
|
}.to raise_error(Cask::CaskAlreadyCreatedError)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows creating Casks that are substrings of existing Casks" do
|
2017-05-19 21:20:51 +02:00
|
|
|
command = described_class.new("local-caff")
|
2018-09-06 08:29:14 +02:00
|
|
|
expect(command).to receive(:exec_editor).with(Cask::CaskLoader.path("local-caff"))
|
2017-05-19 21:20:51 +02:00
|
|
|
command.run
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|