| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | require "rubocops/rubocop-cask" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  | describe RuboCop::Cop::Cask::StanzaGrouping, :config do | 
					
						
							|  |  |  |   it "accepts a sole stanza" do | 
					
						
							|  |  |  |     expect_no_offenses <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "accepts correctly grouped stanzas" do | 
					
						
							|  |  |  |     expect_no_offenses <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "accepts correctly grouped stanzas and variable assignments" do | 
					
						
							|  |  |  |     expect_no_offenses <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense when a stanza is grouped incorrectly" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for an incorrectly grouped `arch` stanza" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for an incorrectly grouped variable assignment" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for multiple incorrectly grouped stanzas" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |         homepage 'https://foo.brew.sh' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							|  |  |  |         uninstall :quit => 'com.example.foo', | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |                   :kext => 'com.example.foo.kextextension' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							|  |  |  |         homepage 'https://foo.brew.sh' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         uninstall :quit => 'com.example.foo', | 
					
						
							|  |  |  |                   :kext => 'com.example.foo.kextextension' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for multiple incorrectly grouped stanzas and variable assignments" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |         platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |         homepage 'https://foo.brew.sh' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							|  |  |  |         uninstall :quit => 'com.example.foo', | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |                   :kext => 'com.example.foo.kextextension' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							|  |  |  |         platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							|  |  |  |         homepage 'https://foo.brew.sh' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         uninstall :quit => 'com.example.foo', | 
					
						
							|  |  |  |                   :kext => 'com.example.foo.kextextension' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   shared_examples "caveats" do | 
					
						
							|  |  |  |     it "reports an offense for an incorrectly grouped `caveats` stanza" do | 
					
						
							|  |  |  |       # Indent all except the first line. | 
					
						
							|  |  |  |       interpolated_caveats = caveats.strip | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect_offense <<~CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         cask 'foo' do | 
					
						
							|  |  |  |           version :latest | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://foo.brew.sh/foo.zip' | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |           name 'Foo' | 
					
						
							|  |  |  |           app 'Foo.app' | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |           #{interpolated_caveats} | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |       CASK | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Remove offense annotations. | 
					
						
							|  |  |  |       corrected_caveats = interpolated_caveats.gsub(/\n\s*\^+\s+.*$/, "") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect_correction <<~CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         cask 'foo' do | 
					
						
							|  |  |  |           version :latest | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://foo.brew.sh/foo.zip' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |           name 'Foo' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           app 'Foo.app' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |           #{corrected_caveats} | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |       CASK | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   context "when `caveats` is a one-line string" do | 
					
						
							|  |  |  |     let(:caveats) do | 
					
						
							|  |  |  |       <<~CAVEATS | 
					
						
							|  |  |  |           caveats 'This is a one-line caveat.' | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |       CAVEATS | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     include_examples "caveats" | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   context "when `caveats` is a heredoc" do | 
					
						
							|  |  |  |     let(:caveats) do | 
					
						
							|  |  |  |       <<~CAVEATS | 
					
						
							|  |  |  |           caveats <<~EOS | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |             This is a multiline caveat. | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |             Let's hope it doesn't cause any problems! | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |       CAVEATS | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     include_examples "caveats" | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   context "when `caveats` is a block" do | 
					
						
							|  |  |  |     let(:caveats) do | 
					
						
							|  |  |  |       <<~CAVEATS | 
					
						
							|  |  |  |           caveats do | 
					
						
							|  |  |  |         ^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |             puts 'This is a multiline caveat.' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |             puts "Let's hope it doesn't cause any problems!" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |       CAVEATS | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     include_examples "caveats" | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for an incorrectly grouped `postflight` stanza" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							|  |  |  |         app 'Foo.app' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         postflight do | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |           puts 'We have liftoff!' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         postflight do | 
					
						
							|  |  |  |           puts 'We have liftoff!' | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for incorrectly grouped comments" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  |         # comment with an empty line between | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # comment directly above | 
					
						
							|  |  |  |         postflight do | 
					
						
							|  |  |  |           puts 'We have liftoff!' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							|  |  |  |         app 'Foo.app' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         # comment with an empty line between | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         # comment directly above | 
					
						
							|  |  |  |         postflight do | 
					
						
							|  |  |  |           puts 'We have liftoff!' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for incorrectly grouped comments and variable assignments" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							|  |  |  |         # comment with an empty line between | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # comment directly above | 
					
						
							|  |  |  |         postflight do | 
					
						
							|  |  |  |           puts 'We have liftoff!' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							|  |  |  |         app 'Foo.app' | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         arch arm: "arm64", intel: "x86_64" | 
					
						
							|  |  |  |         folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         # comment with an empty line between | 
					
						
							|  |  |  |         version :latest | 
					
						
							|  |  |  |         sha256 :no_check | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         # comment directly above | 
					
						
							|  |  |  |         postflight do | 
					
						
							|  |  |  |           puts 'We have liftoff!' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |         name 'Foo' | 
					
						
							| 
									
										
										
										
											2022-08-05 15:35:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |         app 'Foo.app' | 
					
						
							| 
									
										
										
										
											2023-04-12 17:34:03 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for incorrectly grouped stanzas in `on_*` blocks" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         on_arm do | 
					
						
							|  |  |  |           version "1.0.2" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         on_intel do | 
					
						
							|  |  |  |           version "0.9.8" | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							|  |  |  |           url "https://foo.brew.sh/foo-intel.zip" | 
					
						
							|  |  |  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-04-12 17:34:03 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2023-04-12 17:34:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         on_arm do | 
					
						
							|  |  |  |           version "1.0.2" | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         on_intel do | 
					
						
							|  |  |  |           version "0.9.8" | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |           url "https://foo.brew.sh/foo-intel.zip" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-04-12 23:14:43 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-04-12 23:14:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |   it "reports an offense for incorrectly grouped stanzas with comments in `on_*` blocks" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         on_arm do | 
					
						
							|  |  |  |           version "1.0.2" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ^{} stanzas within the same group should have no lines between them | 
					
						
							|  |  |  |           sha256 :no_check # comment on same line | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         on_intel do | 
					
						
							|  |  |  |           version "0.9.8" | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-04-12 23:14:43 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2023-04-12 23:14:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-08 11:02:44 +02:00
										 |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask 'foo' do | 
					
						
							|  |  |  |         on_arm do | 
					
						
							|  |  |  |           version "1.0.2" | 
					
						
							|  |  |  |           sha256 :no_check # comment on same line | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         on_intel do | 
					
						
							|  |  |  |           version "0.9.8" | 
					
						
							|  |  |  |           sha256 :no_check | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |