| 
									
										
										
										
											2023-03-04 22:23:32 +00:00
										 |  |  | # typed: false | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/rubocop-cask" | 
					
						
							|  |  |  | require "test/rubocops/cask/shared_examples/cask_cop" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::Cask::Url do | 
					
						
							|  |  |  |   include CaskCop | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "when url 'verified' value does not start with a protocol" do | 
					
						
							|  |  |  |     let(:source) do | 
					
						
							|  |  |  |       <<~CASK | 
					
						
							|  |  |  |         cask "foo" do | 
					
						
							|  |  |  |           url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       CASK | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     include_examples "does not report any offenses" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "when url 'verified' value starts with a protocol" do | 
					
						
							|  |  |  |     let(:source) do | 
					
						
							|  |  |  |       <<~CASK | 
					
						
							|  |  |  |         cask "foo" do | 
					
						
							|  |  |  |           url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "https://example.com" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       CASK | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let(:expected_offenses) do | 
					
						
							|  |  |  |       [{ | 
					
						
							|  |  |  |         message:  "Verified URL parameter value should not start with https:// or http://.", | 
					
						
							|  |  |  |         severity: :convention, | 
					
						
							|  |  |  |         line:     3, | 
					
						
							|  |  |  |         column:   14, | 
					
						
							| 
									
										
										
										
											2023-03-05 16:55:47 +00:00
										 |  |  |         source:   "\"https://example.com\"", | 
					
						
							| 
									
										
										
										
											2023-03-04 22:23:32 +00:00
										 |  |  |       }] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-05 17:08:43 +00:00
										 |  |  |     let(:correct_source) do | 
					
						
							|  |  |  |       <<~CASK | 
					
						
							|  |  |  |         cask "foo" do | 
					
						
							|  |  |  |           url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       CASK | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-04 22:23:32 +00:00
										 |  |  |     include_examples "reports offenses" | 
					
						
							| 
									
										
										
										
											2023-03-05 17:08:43 +00:00
										 |  |  |     include_examples "autocorrects source" | 
					
						
							| 
									
										
										
										
											2023-03-04 22:23:32 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | end |