| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | require_relative "../../rubocops/components_order_cop" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 11:33:00 +05:30
										 |  |  | describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "When auditing formula components order" do | 
					
						
							|  |  |  |     it "When url precedes homepage" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "http://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  |           homepage "http://example.com" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `homepage` (line 3) should be put before `url` (line 2) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "When `resource` precedes `depends_on`" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "https://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           resource "foo2" do | 
					
						
							|  |  |  |             url "https://example.com/foo-2.0.tgz" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           depends_on "openssl" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^ `depends_on` (line 8) should be put before `resource` (line 4) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "When `test` precedes `plist`" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "https://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           test do | 
					
						
							|  |  |  |             expect(shell_output("./dogs")).to match("Dogs are terrific") | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def plist | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^ `plist` (line 8) should be put before `test` (line 4) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "When only one of many `depends_on` precedes `conflicts_with`" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "autoconf" => :build | 
					
						
							|  |  |  |           conflicts_with "visionmedia-watch" | 
					
						
							|  |  |  |           depends_on "automake" => :build | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `depends_on` (line 4) should be put before `conflicts_with` (line 3) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |           depends_on "libtool" => :build | 
					
						
							|  |  |  |           depends_on "pkg-config" => :build | 
					
						
							|  |  |  |           depends_on "gettext" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   context "When auditing formula components order with autocorrect" do | 
					
						
							|  |  |  |     it "When url precedes homepage" do | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       source = <<~EOS | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "http://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  |           homepage "http://example.com" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       correct_source = <<~EOS | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "http://example.com" | 
					
						
							|  |  |  |           url "http://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-07 22:31:23 +02:00
										 |  |  |       corrected_source = autocorrect_source(source) | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  |       expect(corrected_source).to eq(correct_source) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "When `resource` precedes `depends_on`" do | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       source = <<~EOS | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "https://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           resource "foo2" do | 
					
						
							|  |  |  |             url "https://example.com/foo-2.0.tgz" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           depends_on "openssl" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       correct_source = <<~EOS | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url "https://example.com/foo-1.0.tgz" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           depends_on "openssl" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           resource "foo2" do | 
					
						
							|  |  |  |             url "https://example.com/foo-2.0.tgz" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-07 22:31:23 +02:00
										 |  |  |       corrected_source = autocorrect_source(source) | 
					
						
							| 
									
										
										
										
											2017-05-08 18:47:50 +05:30
										 |  |  |       expect(corrected_source).to eq(correct_source) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | end |