Improve existing tests for Livecheck DSL
This commit is contained in:
parent
b99e8626e2
commit
47d07b2f1b
@ -4,19 +4,25 @@ require "formula"
|
|||||||
require "livecheck"
|
require "livecheck"
|
||||||
|
|
||||||
describe Livecheck do
|
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
|
let(:f) do
|
||||||
formula do
|
formula do
|
||||||
url "https://brew.sh/test-0.1.tbz"
|
homepage HOMEPAGE_URL
|
||||||
|
url STABLE_URL
|
||||||
|
head HEAD_URL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
let(:livecheckable) { described_class.new(f) }
|
let(:livecheckable) { described_class.new(f) }
|
||||||
|
|
||||||
describe "#regex" do
|
describe "#regex" do
|
||||||
it "returns nil if unset" do
|
it "returns nil if not set" do
|
||||||
expect(livecheckable.regex).to be nil
|
expect(livecheckable.regex).to be nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the Regex if set" do
|
it "returns the Regexp if set" do
|
||||||
livecheckable.regex(/foo/)
|
livecheckable.regex(/foo/)
|
||||||
expect(livecheckable.regex).to eq(/foo/)
|
expect(livecheckable.regex).to eq(/foo/)
|
||||||
end
|
end
|
||||||
@ -29,14 +35,14 @@ describe Livecheck do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#skip" do
|
describe "#skip" do
|
||||||
it "sets the instance variable skip to true and skip_msg to nil when the argument is not present" do
|
it "sets @skip to true when no argument is provided" do
|
||||||
livecheckable.skip
|
expect(livecheckable.skip).to be true
|
||||||
expect(livecheckable.instance_variable_get(:@skip)).to be true
|
expect(livecheckable.instance_variable_get(:@skip)).to be true
|
||||||
expect(livecheckable.instance_variable_get(:@skip_msg)).to be nil
|
expect(livecheckable.instance_variable_get(:@skip_msg)).to be nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets the instance variable skip to true and skip_msg to the argument when present" do
|
it "sets @skip to true and @skip_msg to the provided String" do
|
||||||
livecheckable.skip("foo")
|
expect(livecheckable.skip("foo")).to be true
|
||||||
expect(livecheckable.instance_variable_get(:@skip)).to be true
|
expect(livecheckable.instance_variable_get(:@skip)).to be true
|
||||||
expect(livecheckable.instance_variable_get(:@skip_msg)).to eq("foo")
|
expect(livecheckable.instance_variable_get(:@skip_msg)).to eq("foo")
|
||||||
end
|
end
|
||||||
@ -49,8 +55,9 @@ describe Livecheck do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#skip?" do
|
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
|
expect(livecheckable.skip?).to be false
|
||||||
|
|
||||||
livecheckable.skip
|
livecheckable.skip
|
||||||
expect(livecheckable.skip?).to be true
|
expect(livecheckable.skip?).to be true
|
||||||
end
|
end
|
||||||
@ -74,7 +81,7 @@ describe Livecheck do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#url" do
|
describe "#url" do
|
||||||
it "returns nil if unset" do
|
it "returns nil if not set" do
|
||||||
expect(livecheckable.url).to be nil
|
expect(livecheckable.url).to be nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,6 +89,16 @@ describe Livecheck do
|
|||||||
livecheckable.url("foo")
|
livecheckable.url("foo")
|
||||||
expect(livecheckable.url).to eq("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
|
it "raises a TypeError if the argument isn't a String or Symbol" do
|
||||||
expect {
|
expect {
|
||||||
livecheckable.url(/foo/)
|
livecheckable.url(/foo/)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user