| 
									
										
										
										
											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") | 
					
						
							| 
									
										
										
										
											2017-03-13 01:01:17 +01:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "throws away additional Cask arguments and uses the first" do | 
					
						
							| 
									
										
										
										
											2017-05-19 21:20:51 +02:00
										 |  |  |     command = described_class.new("additional-cask", "another-cask") | 
					
						
							|  |  |  |     expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("additional-cask")) | 
					
						
							|  |  |  |     command.run | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "throws away stray options" do | 
					
						
							| 
									
										
										
										
											2017-05-19 21:20:51 +02:00
										 |  |  |     command = described_class.new("--notavalidoption", "yet-another-cask") | 
					
						
							|  |  |  |     expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("yet-another-cask")) | 
					
						
							|  |  |  |     command.run | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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 { | 
					
						
							| 
									
										
										
										
											2017-05-19 21:20:51 +02:00
										 |  |  |         described_class.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 |