| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:41:14 +01:00
										 |  |  | require "rubocops/components_redundancy" | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |   context "when auditing formula components" do | 
					
						
							|  |  |  |     it "reports an offense if `url` is outside `stable` block" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsRedundancy: `url` should be put inside `stable` block | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |           stable do | 
					
						
							|  |  |  |             # stuff | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 10:34:22 +01:00
										 |  |  |           head do | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  |             # stuff | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |     it "reports an offense if both `head` and `head do` are present" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           head "https://brew.sh/foo.git" | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |           head do | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head` and `head do` should not be simultaneously present | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |             # stuff | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |     it "reports an offense if both `bottle :modifier` and `bottle do` are present" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |           bottle do | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^ FormulaAudit/ComponentsRedundancy: `bottle :modifier` and `bottle do` should not be simultaneously present | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |             # bottles go here | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           bottle :unneeded | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |     it "reports no offenses if `stable do` is present with a `head` method" do | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           head "https://brew.sh/foo.git" | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |           stable do | 
					
						
							|  |  |  |             # stuff | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |     it "reports no offenses if `stable do` is present with a `head do` block" do | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           stable do | 
					
						
							|  |  |  |             # stuff | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           head do | 
					
						
							|  |  |  |             # stuff | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-12-30 12:30:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "reports an offense if `stable do` or `head do` is present with only `url`" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           stable do | 
					
						
							|  |  |  |           ^^^^^^^^^ FormulaAudit/ComponentsRedundancy: `stable do` should not be present with only url/sha256/mirror/version | 
					
						
							|  |  |  |             url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           head do | 
					
						
							|  |  |  |           ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only `url` | 
					
						
							|  |  |  |             url "https://brew.sh/foo.git" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports no offenses if `stable do` is present with `url` and `depends_on`" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           head "https://brew.sh/foo.git" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           stable do | 
					
						
							|  |  |  |             url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |             depends_on "bar" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "reports no offenses if `head do` is present with `url` and `depends_on`" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           head do | 
					
						
							|  |  |  |             url "https://brew.sh/foo.git" | 
					
						
							|  |  |  |             depends_on "bar" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end |