From 47d07b2f1baaa2a999c64b768d66ba2f7a80b892 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 7 Aug 2020 17:26:55 -0400 Subject: [PATCH] Improve existing tests for Livecheck DSL --- Library/Homebrew/test/livecheck_spec.rb | 35 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/test/livecheck_spec.rb b/Library/Homebrew/test/livecheck_spec.rb index 3b1ed99960..e5ed4a57c9 100644 --- a/Library/Homebrew/test/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck_spec.rb @@ -4,19 +4,25 @@ require "formula" require "livecheck" describe Livecheck do + HOMEPAGE_URL = "https://example.com/" + STABLE_URL = "https://example.com/example-1.2.3.tar.gz" + HEAD_URL = "https://example.com/example.git" + let(:f) do formula do - url "https://brew.sh/test-0.1.tbz" + homepage HOMEPAGE_URL + url STABLE_URL + head HEAD_URL end end let(:livecheckable) { described_class.new(f) } describe "#regex" do - it "returns nil if unset" do + it "returns nil if not set" do expect(livecheckable.regex).to be nil end - it "returns the Regex if set" do + it "returns the Regexp if set" do livecheckable.regex(/foo/) expect(livecheckable.regex).to eq(/foo/) end @@ -29,14 +35,14 @@ describe Livecheck do end describe "#skip" do - it "sets the instance variable skip to true and skip_msg to nil when the argument is not present" do - livecheckable.skip + it "sets @skip to true when no argument is provided" do + expect(livecheckable.skip).to be true expect(livecheckable.instance_variable_get(:@skip)).to be true expect(livecheckable.instance_variable_get(:@skip_msg)).to be nil end - it "sets the instance variable skip to true and skip_msg to the argument when present" do - livecheckable.skip("foo") + it "sets @skip to true and @skip_msg to the provided String" do + expect(livecheckable.skip("foo")).to be true expect(livecheckable.instance_variable_get(:@skip)).to be true expect(livecheckable.instance_variable_get(:@skip_msg)).to eq("foo") end @@ -49,8 +55,9 @@ describe Livecheck do end describe "#skip?" do - it "returns the value of the instance variable skip" do + it "returns the value of @skip" do expect(livecheckable.skip?).to be false + livecheckable.skip expect(livecheckable.skip?).to be true end @@ -74,7 +81,7 @@ describe Livecheck do end describe "#url" do - it "returns nil if unset" do + it "returns nil if not set" do expect(livecheckable.url).to be nil end @@ -82,6 +89,16 @@ describe Livecheck do livecheckable.url("foo") expect(livecheckable.url).to eq("foo") + livecheckable.url(:homepage) + expect(livecheckable.url).to eq(HOMEPAGE_URL) + + livecheckable.url(:stable) + expect(livecheckable.url).to eq(STABLE_URL) + + livecheckable.url(:head) + expect(livecheckable.url).to eq(HEAD_URL) + end + it "raises a TypeError if the argument isn't a String or Symbol" do expect { livecheckable.url(/foo/)