brew/Library/Homebrew/test/livecheck_spec.rb

141 lines
3.7 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
2020-05-31 00:10:46 +05:30
let(:f) do
formula do
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
let(:livecheckable_f) { described_class.new(f) }
let(:c) do
Cask::CaskLoader.load(+<<-RUBY)
cask "test" do
version "0.0.1,2"
url "https://brew.sh/test-0.0.1.dmg"
name "Test"
desc "Test cask"
homepage "https://brew.sh"
end
RUBY
end
let(:livecheckable_c) { described_class.new(c) }
2020-03-16 01:37:49 +05:30
describe "#regex" do
it "returns nil if not set" do
expect(livecheckable_f.regex).to be nil
2020-03-16 01:37:49 +05:30
end
it "returns the Regexp if set" do
livecheckable_f.regex(/foo/)
expect(livecheckable_f.regex).to eq(/foo/)
2020-03-16 01:37:49 +05:30
end
it "raises a TypeError if the argument isn't a Regexp" do
expect {
livecheckable_f.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_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
it "sets @skip to true and @skip_msg to the provided String" do
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
it "raises a TypeError if the argument isn't a String" do
expect {
livecheckable_f.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
expect(livecheckable_f.skip?).to be false
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
expect(livecheckable_f.strategy).to be nil
2020-08-05 11:54:37 -04:00
end
it "returns the Symbol if set" do
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 {
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
let(:url_string) { "https://brew.sh" }
it "returns nil if not set" do
expect(livecheckable_f.url).to be nil
end
it "returns a string when set to a string" do
livecheckable_f.url(url_string)
expect(livecheckable_f.url).to eq(url_string)
2020-03-16 01:37:49 +05:30
end
it "returns the URL symbol if valid" do
livecheckable_f.url(:head)
expect(livecheckable_f.url).to eq(:head)
livecheckable_f.url(:homepage)
expect(livecheckable_f.url).to eq(:homepage)
livecheckable_f.url(:stable)
expect(livecheckable_f.url).to eq(:stable)
livecheckable_c.url(:url)
expect(livecheckable_c.url).to eq(:url)
end
it "raises a TypeError if the argument isn't a String or valid Symbol" do
expect {
livecheckable_f.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
expect(livecheckable_f.to_hash).to eq(
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