From ff63136c6f96f73f4641b4e5525e7d23fed3d7c0 Mon Sep 17 00:00:00 2001 From: Mohammad Zain Abbas Date: Thu, 30 Jun 2022 16:06:36 +0200 Subject: [PATCH] Added tests for `livecheck` in `resource_spec.rb` --- Library/Homebrew/test/resource_spec.rb | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Library/Homebrew/test/resource_spec.rb b/Library/Homebrew/test/resource_spec.rb index 63a14b0b1e..06117a9bff 100644 --- a/Library/Homebrew/test/resource_spec.rb +++ b/Library/Homebrew/test/resource_spec.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true require "resource" +require "livecheck" describe Resource do subject(:resource) { described_class.new("test") } @@ -52,6 +53,52 @@ describe Resource do end end + describe Resource do + let(:r) do + livecheck do + url "https://brew.sh/foo-1.0.tar.gz" + regex(/foo/) + end + end + + let(:livecheckable_r) { described_class.new(r) } + + describe "#livecheck" do + it "returns nil if not set" do + expect(livecheckable_r.livecheck).to be_nil + end + + it "returns the string if set" do + livecheckable_r.livecheck("other-resource") + expect(livecheckable_r.livecheck).to eq("other-resource") + end + + it "raises a TypeError if the argument isn't a String" do + expect { + livecheckable_r.livecheck(123) + }.to raise_error(TypeError, "Resource#livecheck expects a String") + end + end + + describe "#regex" do + it "returns nil if not set" do + expect(livecheckable_r.regex).to be_nil + end + + it "returns the Regexp if set" do + livecheckable_r.regex(/foo/) + expect(livecheckable_r.regex).to eq(/foo/) + end + + it "raises a TypeError if the argument isn't a Regexp" do + expect { + livecheckable_r.regex("foo") + }.to raise_error(TypeError, "Resource#livecheck#regex expects a Regexp") + end + end + + end + describe "#version" do it "sets the version" do resource.version("1.0")