| 
									
										
										
										
											2023-12-17 16:46:48 -05:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/rubocop-cask" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe RuboCop::Cop::Cask::Discontinued, :config do | 
					
						
							| 
									
										
										
										
											2023-12-17 16:46:48 -05:00
										 |  |  |   it "reports no offenses when there is no `caveats` stanza" do | 
					
						
							|  |  |  |     expect_no_offenses <<~CASK | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com/download/" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "reports no offenses when there is a `caveats` stanza without `discontinued`" do | 
					
						
							|  |  |  |     expect_no_offenses <<~CASK | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com/download/" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         caveats do | 
					
						
							|  |  |  |           files_in_usr_local | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "reports an offense when there is a `caveats` stanza with `discontinued` and other caveats" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com/download/" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         caveats do | 
					
						
							|  |  |  |           discontinued | 
					
						
							|  |  |  |           ^^^^^^^^^^^^ Use `deprecate!` instead of `caveats { discontinued }`. | 
					
						
							|  |  |  |           files_in_usr_local | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "corrects `caveats { discontinued }` to `deprecate!`" do | 
					
						
							|  |  |  |     expect_offense <<~CASK | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com/download/" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         caveats do | 
					
						
							|  |  |  |         ^^^^^^^^^^ Use `deprecate!` instead of `caveats { discontinued }`. | 
					
						
							|  |  |  |           discontinued | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction <<~CASK | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/download/foo-v1.2.0.dmg", | 
					
						
							|  |  |  |             verified: "example.com/download/" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         deprecate! date: "#{Date.today}", because: :discontinued | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |