brew/Library/Homebrew/test/livecheck_spec.rb

58 lines
1.6 KiB
Ruby
Raw Normal View History

2020-03-16 01:37:49 +05:30
# frozen_string_literal: true
require "livecheck"
describe Livecheck do
subject(:livecheckable) { described_class.new }
describe "#regex" do
it "returns nil if unset" do
expect(livecheckable.regex).to be nil
end
it "returns the Regex if set" do
livecheckable.regex(/foo/)
expect(livecheckable.regex).to eq(/foo/)
end
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
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")
expect(livecheckable.instance_variable_get(:@skip)).to be true
expect(livecheckable.instance_variable_get(:@skip_msg)).to eq("foo")
end
end
describe "#skip?" do
it "returns the value of the instance variable skip" do
expect(livecheckable.skip?).to be false
livecheckable.skip
expect(livecheckable.skip?).to be true
end
end
describe "#url" do
it "returns nil if unset" do
expect(livecheckable.url).to be nil
end
it "returns the URL if set" do
livecheckable.url("foo")
expect(livecheckable.url).to eq("foo")
end
end
describe "#to_hash" do
it "returns a Hash of all instance variables" do
expect(livecheckable.to_hash).to eq({ "regex"=>nil, "skip"=>false, "skip_msg"=>nil, "url"=>nil })
end
end
end