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

79 lines
2.1 KiB
Ruby
Raw Normal View History

2017-05-19 21:20:51 +02:00
describe Hbc::CLI::Create, :cask do
around(:each) do |example|
begin
example.run
ensure
%w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
FileUtils.rm_f Hbc::CaskLoader.path(cask)
2016-09-24 13:52:43 +02:00
end
end
2016-08-18 22:11:42 +03:00
end
2017-02-08 12:05:42 +01:00
before(:each) 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
it "opens the editor for the specified Cask" do
2017-05-19 21:20:51 +02:00
command = described_class.new("new-cask")
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask"))
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")
template = File.read(Hbc::CaskLoader.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
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")
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
2017-05-19 21:20:51 +02:00
command = described_class.new("local-caff")
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff"))
command.run
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 {
2017-05-19 21:20:51 +02:00
described_class.run
2017-02-08 12:05:42 +01:00
}.to raise_error(Hbc::CaskUnspecifiedError)
2016-08-18 22:11:42 +03:00
end
end
2017-05-21 02:32:46 +02:00
context "when an invalid option is specified" do
it "raises an exception when no Cask is specified" do
2017-02-08 12:05:42 +01:00
expect {
2017-05-19 21:20:51 +02:00
described_class.run("--notavalidoption")
2017-05-21 02:32:46 +02:00
}.to raise_error(/invalid option/)
end
it "raises an exception" do
expect {
described_class.run("--notavalidoption", "yet-another-cask")
}.to raise_error(/invalid option/)
2016-08-18 22:11:42 +03:00
end
end
end