| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | describe Cask::Cmd, :cask do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   it "lists the taps for Casks that show up in two taps" do | 
					
						
							| 
									
										
										
										
											2017-06-14 13:23:16 +02:00
										 |  |  |     listing = described_class.nice_listing(%w[
 | 
					
						
							| 
									
										
										
										
											2018-05-25 18:03:16 +02:00
										 |  |  |                                              homebrew/cask/adium | 
					
						
							|  |  |  |                                              homebrew/cask/google-chrome | 
					
						
							| 
									
										
										
										
											2017-06-14 13:23:16 +02:00
										 |  |  |                                              passcod/homebrew-cask/adium | 
					
						
							|  |  |  |                                            ]) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(listing).to eq(%w[
 | 
					
						
							|  |  |  |                             google-chrome | 
					
						
							| 
									
										
										
										
											2018-05-25 18:03:16 +02:00
										 |  |  |                             homebrew/cask/adium | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |                             passcod/cask/adium | 
					
						
							|  |  |  |                           ]) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 13:23:16 +02:00
										 |  |  |   it "ignores the `--language` option, which is handled in `OS::Mac`" do | 
					
						
							|  |  |  |     cli = described_class.new("--language=en") | 
					
						
							| 
									
										
										
										
											2020-04-07 08:32:30 +02:00
										 |  |  |     expect(cli).to receive(:detect_internal_command).with(no_args) | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     cli.run | 
					
						
							| 
									
										
										
										
											2017-06-14 13:23:16 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-24 14:56:07 +00:00
										 |  |  |   context "when given no arguments" do | 
					
						
							|  |  |  |     it "exits successfully" do | 
					
						
							|  |  |  |       expect(subject).not_to receive(:exit).with(be_nonzero) | 
					
						
							|  |  |  |       subject.run | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-24 20:34:20 +02:00
										 |  |  |   context "when no option is specified" do | 
					
						
							|  |  |  |     it "--binaries is true by default" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       command = Cask::Cmd::Install.new("some-cask") | 
					
						
							| 
									
										
										
										
											2017-05-24 20:34:20 +02:00
										 |  |  |       expect(command.binaries?).to be true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |   context "::run" do | 
					
						
							| 
									
										
										
										
											2020-04-07 08:32:30 +02:00
										 |  |  |     let(:noop_command) { double("Cmd::Noop", run: nil) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "prints help output when subcommand receives `--help` flag" do | 
					
						
							| 
									
										
										
										
											2020-04-07 08:32:30 +02:00
										 |  |  |       command = described_class.new("info", "--help") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect { command.run }.to output(/displays information about the given Cask/).to_stdout | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(command.help?).to eq(true) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "respects the env variable when choosing what appdir to create" do | 
					
						
							| 
									
										
										
										
											2020-04-07 08:32:30 +02:00
										 |  |  |       allow(described_class).to receive(:lookup_command).with("noop").and_return(noop_command) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 02:40:27 +01:00
										 |  |  |       ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/custom/appdir" | 
					
						
							| 
									
										
										
										
											2017-12-03 09:06:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       described_class.run("noop") | 
					
						
							| 
									
										
										
										
											2017-12-03 09:06:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Config.global.appdir).to eq(Pathname.new("/custom/appdir")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 08:32:30 +02:00
										 |  |  |     it "overrides the env variable when passing --appdir directly" do | 
					
						
							|  |  |  |       allow(described_class).to receive(:lookup_command).with("noop").and_return(noop_command) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/custom/appdir" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("noop", "--appdir=/even/more/custom/appdir") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(Cask::Config.global.appdir).to eq(Pathname.new("/even/more/custom/appdir")) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     it "exits with a status of 1 when something goes wrong" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       allow(described_class).to receive(:lookup_command).and_raise(Cask::CaskError) | 
					
						
							| 
									
										
										
										
											2017-06-14 13:23:16 +02:00
										 |  |  |       command = described_class.new("noop") | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(command).to receive(:exit).with(1) | 
					
						
							|  |  |  |       command.run | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-03-16 09:00:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 08:32:30 +02:00
										 |  |  |   it "provides a help message for all commands" do | 
					
						
							|  |  |  |     described_class.command_classes.each do |command_class| | 
					
						
							| 
									
										
										
										
											2017-03-16 09:00:57 +01:00
										 |  |  |       expect(command_class.help).to match(/\w+/), command_class.name | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | end |