brew/Library/Homebrew/test/livecheck_spec.rb

124 lines
3.2 KiB
Ruby
Raw Normal View History

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
HOMEPAGE_URL = "https://example.com/"
STABLE_URL = "https://example.com/example-1.2.3.tar.gz"
HEAD_URL = "https://example.com/example.git"
2020-05-31 00:10:46 +05:30
let(:f) do
formula do
homepage HOMEPAGE_URL
url STABLE_URL
head HEAD_URL
2020-05-31 00:10:46 +05:30
end
end
let(:livecheckable) { described_class.new(f) }
2020-03-16 01:37:49 +05:30
describe "#regex" do
it "returns nil if not set" do
2020-03-16 01:37:49 +05:30
expect(livecheckable.regex).to be nil
end
it "returns the Regexp if set" do
2020-03-16 01:37:49 +05:30
livecheckable.regex(/foo/)
expect(livecheckable.regex).to eq(/foo/)
end
it "raises a TypeError if the argument isn't a Regexp" do
expect {
livecheckable.regex("foo")
}.to raise_error(TypeError, "Livecheck#regex expects a Regexp")
end
2020-03-16 01:37:49 +05:30
end
describe "#skip" do
it "sets @skip to true when no argument is provided" do
expect(livecheckable.skip).to be true
2020-03-16 01:37:49 +05:30
expect(livecheckable.instance_variable_get(:@skip)).to be true
expect(livecheckable.instance_variable_get(:@skip_msg)).to be nil
end
it "sets @skip to true and @skip_msg to the provided String" do
expect(livecheckable.skip("foo")).to be true
2020-03-16 01:37:49 +05:30
expect(livecheckable.instance_variable_get(:@skip)).to be true
expect(livecheckable.instance_variable_get(:@skip_msg)).to eq("foo")
end
it "raises a TypeError if the argument isn't a String" do
expect {
livecheckable.skip(/foo/)
}.to raise_error(TypeError, "Livecheck#skip expects a String")
end
2020-03-16 01:37:49 +05:30
end
describe "#skip?" do
it "returns the value of @skip" do
2020-03-16 01:37:49 +05:30
expect(livecheckable.skip?).to be false
2020-03-16 01:37:49 +05:30
livecheckable.skip
expect(livecheckable.skip?).to be true
end
end
2020-08-05 11:54:37 -04:00
describe "#strategy" do
it "returns nil if not set" do
expect(livecheckable.strategy).to be nil
end
it "returns the Symbol if set" do
livecheckable.strategy(:page_match)
expect(livecheckable.strategy).to eq(:page_match)
end
it "raises a TypeError if the argument isn't a Symbol" do
expect {
livecheckable.strategy("page_match")
}.to raise_error(TypeError, "Livecheck#strategy expects a Symbol")
end
end
2020-03-16 01:37:49 +05:30
describe "#url" do
it "returns nil if not set" do
2020-03-16 01:37:49 +05:30
expect(livecheckable.url).to be nil
end
it "returns the URL if set" 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/)
}.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
2020-08-05 11:54:37 -04:00
expect(livecheckable.to_hash).to eq(
{
"regex" => nil,
"skip" => false,
"skip_msg" => nil,
"strategy" => nil,
"url" => nil,
},
)
2020-03-16 01:37:49 +05:30
end
end
end