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

63 lines
1.7 KiB
Ruby
Raw Normal View History

# 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
around do |example|
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
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")
}.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