| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  | require_relative "shared_examples/invalid_option" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::CLI::Search, :cask do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |   before do | 
					
						
							| 
									
										
										
										
											2017-07-08 00:57:08 +02:00
										 |  |  |     allow(Tty).to receive(:width).and_return(0) | 
					
						
							| 
									
										
										
										
											2017-07-06 01:08:59 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |   it_behaves_like "a command that handles invalid options" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   it "lists the available Casks that match the search term" do | 
					
						
							| 
									
										
										
										
											2017-09-10 21:56:12 +02:00
										 |  |  |     allow(GitHub).to receive(:search_code).and_return([]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       Hbc::CLI::Search.run("local") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2018-06-02 02:47:23 +02:00
										 |  |  |       ==> Matches | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       local-caffeine | 
					
						
							|  |  |  |       local-transmission | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-08 18:26:46 +02:00
										 |  |  |   it "outputs a plain list when stdout is not a TTY" do | 
					
						
							| 
									
										
										
										
											2017-09-10 21:56:12 +02:00
										 |  |  |     allow(GitHub).to receive(:search_code).and_return([]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-08 18:26:46 +02:00
										 |  |  |     expect { | 
					
						
							|  |  |  |       Hbc::CLI::Search.run("local") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout | 
					
						
							| 
									
										
										
										
											2017-07-08 18:26:46 +02:00
										 |  |  |       local-caffeine | 
					
						
							|  |  |  |       local-transmission | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 01:54:24 +02:00
										 |  |  |   it "returns matches even when online search failed" do | 
					
						
							|  |  |  |     allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) | 
					
						
							| 
									
										
										
										
											2017-09-10 21:56:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 01:54:24 +02:00
										 |  |  |     expect { | 
					
						
							|  |  |  |       Hbc::CLI::Search.run("local") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout | 
					
						
							| 
									
										
										
										
											2017-08-26 01:54:24 +02:00
										 |  |  |       local-caffeine | 
					
						
							|  |  |  |       local-transmission | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2017-08-31 03:03:00 +02:00
										 |  |  |     .and output(/^Warning: Error searching on GitHub: reason/).to_stderr | 
					
						
							| 
									
										
										
										
											2017-08-26 01:54:24 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   it "shows that there are no Casks matching a search term that did not result in anything" do | 
					
						
							|  |  |  |     expect { | 
					
						
							|  |  |  |       Hbc::CLI::Search.run("foo-bar-baz") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2017-08-26 02:01:08 +02:00
										 |  |  |       No Cask found for "foo-bar-baz". | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 02:05:35 +02:00
										 |  |  |   it "doesn't output anything to non-TTY stdout when there are no matches" do | 
					
						
							| 
									
										
										
										
											2018-06-05 15:39:09 +02:00
										 |  |  |     allow(GitHub).to receive(:search_code).and_return([]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-02 02:29:56 +02:00
										 |  |  |     expect { Hbc::CLI::Search.run("foo-bar-baz") } | 
					
						
							|  |  |  |       .to not_to_output.to_stdout | 
					
						
							|  |  |  |       .and not_to_output.to_stderr | 
					
						
							| 
									
										
										
										
											2017-08-26 02:05:35 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 01:54:24 +02:00
										 |  |  |   it "lists all Casks available offline with no search term" do | 
					
						
							|  |  |  |     allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) | 
					
						
							| 
									
										
										
										
											2017-09-02 02:29:56 +02:00
										 |  |  |     expect { Hbc::CLI::Search.run } | 
					
						
							|  |  |  |       .to output(/local-caffeine/).to_stdout.as_tty | 
					
						
							|  |  |  |       .and not_to_output.to_stderr | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "ignores hyphens in search terms" do | 
					
						
							|  |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       Hbc::CLI::Search.run("lo-cal-caffeine") | 
					
						
							| 
									
										
										
										
											2017-07-08 00:57:08 +02:00
										 |  |  |     }.to output(/local-caffeine/).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "ignores hyphens in Cask tokens" do | 
					
						
							|  |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       Hbc::CLI::Search.run("localcaffeine") | 
					
						
							| 
									
										
										
										
											2017-07-08 00:57:08 +02:00
										 |  |  |     }.to output(/local-caffeine/).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "accepts multiple arguments" do | 
					
						
							|  |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       Hbc::CLI::Search.run("local caffeine") | 
					
						
							| 
									
										
										
										
											2017-07-08 00:57:08 +02:00
										 |  |  |     }.to output(/local-caffeine/).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "accepts a regexp argument" do | 
					
						
							|  |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2018-06-07 14:42:58 +02:00
										 |  |  |       ==> Matches | 
					
						
							| 
									
										
										
										
											2017-08-26 02:01:08 +02:00
										 |  |  |       local-caffeine | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-26 02:01:08 +02:00
										 |  |  |   it "returns both exact and partial matches" do | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-03-04 21:42:09 +01:00
										 |  |  |       Hbc::CLI::Search.run("test-opera") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2018-06-02 02:47:23 +02:00
										 |  |  |       ==> Matches | 
					
						
							| 
									
										
										
										
											2017-08-26 02:01:08 +02:00
										 |  |  |       test-opera | 
					
						
							|  |  |  |       test-opera-mail | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not search the Tap name" do | 
					
						
							|  |  |  |     expect { | 
					
						
							|  |  |  |       Hbc::CLI::Search.run("caskroom") | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     }.to output(<<~EOS).to_stdout.as_tty | 
					
						
							| 
									
										
										
										
											2017-08-26 02:01:08 +02:00
										 |  |  |       No Cask found for "caskroom". | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-03-13 17:52:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it "highlights installed packages" do | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     Hbc::CLI::Install.run("local-caffeine") | 
					
						
							| 
									
										
										
										
											2017-03-13 17:52:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 14:42:58 +02:00
										 |  |  |     expect { | 
					
						
							|  |  |  |       Hbc::CLI::Search.run("local-caffeine") | 
					
						
							|  |  |  |     }.to output(<<~EOS).to_stdout.as_tty | 
					
						
							|  |  |  |       ==> Matches | 
					
						
							|  |  |  |       local-caffeine ✔ | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2017-03-13 17:52:32 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-08 13:34:26 +01:00
										 |  |  | end |