| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:41:14 +01:00
										 |  |  | require "rubocops/class" | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAudit::ClassName do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |   it "reports an offense when using ScriptFileFormula" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < ScriptFileFormula | 
					
						
							|  |  |  |                   ^^^^^^^^^^^^^^^^^ ScriptFileFormula is deprecated, use Formula instead | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |   it "reports an offense when using GithubGistFormula" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < GithubGistFormula | 
					
						
							|  |  |  |                   ^^^^^^^^^^^^^^^^^ GithubGistFormula is deprecated, use Formula instead | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |   it "reports an offense when using AmazonWebServicesFormula" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < AmazonWebServicesFormula | 
					
						
							|  |  |  |                   ^^^^^^^^^^^^^^^^^^^^^^^^ AmazonWebServicesFormula is deprecated, use Formula instead | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |   it "supports auto-correcting deprecated parent classes" do | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     source = <<~RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       class Foo < AmazonWebServicesFormula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     corrected_source = <<~RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |     new_source = autocorrect_source(source) | 
					
						
							|  |  |  |     expect(new_source).to eq(corrected_source) | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::Test do | 
					
						
							| 
									
										
										
										
											2018-08-15 19:43:57 -04:00
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "reports an offense when /usr/local/bin is found in test calls" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-08-15 19:43:57 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test do | 
					
						
							|  |  |  |           system "/usr/local/bin/test" | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^^^^^^^^^^ use \#{bin} instead of /usr/local/bin in system | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "reports an offense when passing 0 as the second parameter to shell_output" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-08-15 19:43:57 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test do | 
					
						
							|  |  |  |           shell_output("\#{bin}/test", 0) | 
					
						
							|  |  |  |                                       ^ Passing 0 to shell_output() is redundant | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |   it "reports an offense when there is an empty test block" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test do | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |         ^^^^^^^ `test do` should not be empty | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |   it "reports an offense when test is falsely true" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test do | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |         ^^^^^^^ `test do` should contain a real test | 
					
						
							|  |  |  |           true | 
					
						
							| 
									
										
										
										
											2018-08-16 12:42:45 -04:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |   it "supports auto-correcting test calls" do | 
					
						
							|  |  |  |     source = <<~RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test do | 
					
						
							|  |  |  |           shell_output("/usr/local/sbin/test", 0) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |     corrected_source = <<~RUBY | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         test do | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |           shell_output("\#{sbin}/test") | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     new_source = autocorrect_source(source) | 
					
						
							|  |  |  |     expect(new_source).to eq(corrected_source) | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  | describe RuboCop::Cop::FormulaAuditStrict::TestPresent do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "reports an offense when there is no test block" do | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       class Foo < Formula | 
					
						
							| 
									
										
										
										
											2020-04-13 14:34:05 +01:00
										 |  |  |       ^^^^^^^^^^^^^^^^^^^ A `test do` test block should be added | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-08-07 03:39:47 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-09-04 13:47:05 +05:30
										 |  |  | end |