| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/keg_only" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe RuboCop::Cop::FormulaAudit::KegOnly do | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |   it "reports and corrects an offense when the `keg_only` reason is capitalized" do | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |         homepage "https://brew.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         keg_only "Because why not" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^ FormulaAudit/KegOnly: 'Because' from the `keg_only` reason should be 'because'. | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |     expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |       class Foo < Formula | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:35:32 -04:00
										 |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |         homepage "https://brew.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         keg_only "because why not" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |   it "reports and corrects an offense when the `keg_only` reason ends with a period" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-03 14:35:32 -04:00
										 |  |  |       class Foo < Formula | 
					
						
							|  |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |         homepage "https://brew.sh" | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:35:32 -04:00
										 |  |  |         keg_only "ending with a period." | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/KegOnly: `keg_only` reason should not end with a period. | 
					
						
							| 
									
										
										
										
											2020-07-03 14:35:32 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |     expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-03 14:35:32 -04:00
										 |  |  |       class Foo < Formula | 
					
						
							|  |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |         homepage "https://brew.sh" | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:35:32 -04:00
										 |  |  |         keg_only "ending with a period" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |   it "reports no offenses when a `keg_only` reason is a block" do | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							|  |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |         homepage "https://brew.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         keg_only <<~EOF | 
					
						
							|  |  |  |           this line starts with a lowercase word. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           This line does not but that shouldn't be a | 
					
						
							|  |  |  |           problem | 
					
						
							|  |  |  |         EOF | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |   it "reports no offenses if a capitalized `keg-only` reason is an exempt proper noun" do | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							|  |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |         homepage "https://brew.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         keg_only "Apple ships foo in the CLT package" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |   it "reports no offenses if a capitalized `keg_only` reason is the formula's name" do | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							|  |  |  |         url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 17:02:48 +11:00
										 |  |  |         keg_only "Foo is the formula name hence downcasing is not required" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2020-04-28 22:35:47 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end |