| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-31 00:10:46 +05:30
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  | require "livecheck" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe Livecheck do | 
					
						
							| 
									
										
										
										
											2020-05-31 00:10:46 +05:30
										 |  |  |   let(:f) do | 
					
						
							|  |  |  |     formula do | 
					
						
							| 
									
										
										
										
											2021-01-13 09:30:50 -05:00
										 |  |  |       homepage "https://brew.sh" | 
					
						
							|  |  |  |       url "https://brew.sh/test-0.0.1.tgz" | 
					
						
							|  |  |  |       head "https://github.com/Homebrew/brew.git" | 
					
						
							| 
									
										
										
										
											2020-05-31 00:10:46 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |   let(:livecheckable_f) { described_class.new(f) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:c) do | 
					
						
							|  |  |  |     Cask::CaskLoader.load(+<<-RUBY)
 | 
					
						
							|  |  |  |       cask "test" do | 
					
						
							|  |  |  |         version "0.0.1,2" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 09:30:50 -05:00
										 |  |  |         url "https://brew.sh/test-0.0.1.dmg" | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |         name "Test" | 
					
						
							|  |  |  |         desc "Test cask" | 
					
						
							| 
									
										
										
										
											2021-01-13 09:30:50 -05:00
										 |  |  |         homepage "https://brew.sh" | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   let(:livecheckable_c) { described_class.new(c) } | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 11:21:29 -04:00
										 |  |  |   describe "#formula" do | 
					
						
							|  |  |  |     it "returns nil if not set" do | 
					
						
							|  |  |  |       expect(livecheckable_f.formula).to be nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns the String if set" do | 
					
						
							|  |  |  |       livecheckable_f.formula("other-formula") | 
					
						
							|  |  |  |       expect(livecheckable_f.formula).to eq("other-formula") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises a TypeError if the argument isn't a String" do | 
					
						
							|  |  |  |       expect { | 
					
						
							|  |  |  |         livecheckable_f.formula(123) | 
					
						
							|  |  |  |       }.to raise_error(TypeError, "Livecheck#formula expects a String") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#cask" do | 
					
						
							|  |  |  |     it "returns nil if not set" do | 
					
						
							|  |  |  |       expect(livecheckable_c.cask).to be nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns the String if set" do | 
					
						
							|  |  |  |       livecheckable_c.cask("other-cask") | 
					
						
							|  |  |  |       expect(livecheckable_c.cask).to eq("other-cask") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises a TypeError if the argument isn't a String" do | 
					
						
							|  |  |  |       expect { | 
					
						
							|  |  |  |         livecheckable_c.cask(123) | 
					
						
							|  |  |  |       }.to raise_error(TypeError, "Livecheck#cask expects a String") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |   describe "#regex" do | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     it "returns nil if not set" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.regex).to be nil | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     it "returns the Regexp if set" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       livecheckable_f.regex(/foo/) | 
					
						
							|  |  |  |       expect(livecheckable_f.regex).to eq(/foo/) | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "raises a TypeError if the argument isn't a Regexp" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |         livecheckable_f.regex("foo") | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  |       }.to raise_error(TypeError, "Livecheck#regex expects a Regexp") | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#skip" do | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     it "sets @skip to true when no argument is provided" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.skip).to be true | 
					
						
							|  |  |  |       expect(livecheckable_f.instance_variable_get(:@skip)).to be true | 
					
						
							|  |  |  |       expect(livecheckable_f.instance_variable_get(:@skip_msg)).to be nil | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     it "sets @skip to true and @skip_msg to the provided String" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.skip("foo")).to be true | 
					
						
							|  |  |  |       expect(livecheckable_f.instance_variable_get(:@skip)).to be true | 
					
						
							|  |  |  |       expect(livecheckable_f.instance_variable_get(:@skip_msg)).to eq("foo") | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "raises a TypeError if the argument isn't a String" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |         livecheckable_f.skip(/foo/) | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  |       }.to raise_error(TypeError, "Livecheck#skip expects a String") | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#skip?" do | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     it "returns the value of @skip" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.skip?).to be false | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       livecheckable_f.skip | 
					
						
							|  |  |  |       expect(livecheckable_f.skip?).to be true | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-05 11:54:37 -04:00
										 |  |  |   describe "#strategy" do | 
					
						
							|  |  |  |     it "returns nil if not set" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.strategy).to be nil | 
					
						
							| 
									
										
										
										
											2020-08-05 11:54:37 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns the Symbol if set" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       livecheckable_f.strategy(:page_match) | 
					
						
							|  |  |  |       expect(livecheckable_f.strategy).to eq(:page_match) | 
					
						
							| 
									
										
										
										
											2020-08-05 11:54:37 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises a TypeError if the argument isn't a Symbol" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |         livecheckable_f.strategy("page_match") | 
					
						
							| 
									
										
										
										
											2020-08-05 11:54:37 -04:00
										 |  |  |       }.to raise_error(TypeError, "Livecheck#strategy expects a Symbol") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |   describe "#url" do | 
					
						
							| 
									
										
										
										
											2021-01-13 09:30:50 -05:00
										 |  |  |     let(:url_string) { "https://brew.sh" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     it "returns nil if not set" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.url).to be nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns a string when set to a string" do | 
					
						
							| 
									
										
										
										
											2021-01-13 09:30:50 -05:00
										 |  |  |       livecheckable_f.url(url_string) | 
					
						
							|  |  |  |       expect(livecheckable_f.url).to eq(url_string) | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |     it "returns the URL symbol if valid" do | 
					
						
							|  |  |  |       livecheckable_f.url(:head) | 
					
						
							|  |  |  |       expect(livecheckable_f.url).to eq(:head) | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       livecheckable_f.url(:homepage) | 
					
						
							|  |  |  |       expect(livecheckable_f.url).to eq(:homepage) | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       livecheckable_f.url(:stable) | 
					
						
							|  |  |  |       expect(livecheckable_f.url).to eq(:stable) | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       livecheckable_c.url(:url) | 
					
						
							|  |  |  |       expect(livecheckable_c.url).to eq(:url) | 
					
						
							| 
									
										
										
										
											2020-08-07 17:26:55 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |     it "raises a TypeError if the argument isn't a String or valid Symbol" do | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |         livecheckable_f.url(/foo/) | 
					
						
							| 
									
										
										
										
											2020-08-07 17:25:08 -04:00
										 |  |  |       }.to raise_error(TypeError, "Livecheck#url expects a String or valid Symbol") | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_hash" do | 
					
						
							|  |  |  |     it "returns a Hash of all instance variables" do | 
					
						
							| 
									
										
										
										
											2021-01-12 15:00:49 -05:00
										 |  |  |       expect(livecheckable_f.to_hash).to eq( | 
					
						
							| 
									
										
										
										
											2020-08-05 11:54:37 -04:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2021-07-19 11:21:29 -04:00
										 |  |  |           "cask"     => nil, | 
					
						
							|  |  |  |           "formula"  => nil, | 
					
						
							| 
									
										
										
										
											2020-08-05 11:54:37 -04:00
										 |  |  |           "regex"    => nil, | 
					
						
							|  |  |  |           "skip"     => false, | 
					
						
							|  |  |  |           "skip_msg" => nil, | 
					
						
							|  |  |  |           "strategy" => nil, | 
					
						
							|  |  |  |           "url"      => nil, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ) | 
					
						
							| 
									
										
										
										
											2020-03-16 01:37:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |