brew/Library/Homebrew/test/livecheck_spec.rb

164 lines
4.1 KiB
Ruby
Raw Normal View History

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"
RSpec.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
2023-04-21 01:21:38 +02:00
let(:livecheckable_f) { described_class.new(f.class) }
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 "#formula" do
it "returns nil if not set" do
expect(livecheckable_f.formula).to be_nil
end
it "returns the String if set" do
livecheckable_f.formula("other-formula")
expect(livecheckable_f.formula).to eq("other-formula")
end
it "raises a TypeError if the argument isn't a String" do
expect do
livecheckable_f.formula(123)
2023-04-21 01:21:38 +02:00
end.to raise_error TypeError
end
end
describe "#cask" do
it "returns nil if not set" do
expect(livecheckable_c.cask).to be_nil
end
it "returns the String if set" do
livecheckable_c.cask("other-cask")
expect(livecheckable_c.cask).to eq("other-cask")
end
end
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
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
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
end
2024-03-21 08:19:35 -04:00
describe "#throttle" do
it "returns nil if not set" do
expect(livecheckable_f.throttle).to be_nil
end
it "returns the Integer if set" do
livecheckable_f.throttle(10)
expect(livecheckable_f.throttle).to eq(10)
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
2023-04-21 01:21:38 +02:00
it "raises an ArgumentError if the argument isn't a valid Symbol" do
expect do
2023-04-21 01:21:38 +02:00
livecheckable_f.url(:not_a_valid_symbol)
end.to raise_error ArgumentError
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
{
"cask" => nil,
"formula" => nil,
2020-08-05 11:54:37 -04:00
"regex" => nil,
"skip" => false,
"skip_msg" => nil,
"strategy" => nil,
2024-03-21 08:19:35 -04:00
"throttle" => nil,
2020-08-05 11:54:37 -04:00
"url" => nil,
},
)
2020-03-16 01:37:49 +05:30
end
end
end