# typed: false
# frozen_string_literal: true
require "livecheck/strategy/page_match"
describe Homebrew::Livecheck::Strategy::PageMatch do
subject(:page_match) { described_class }
let(:url) { "https://brew.sh/blog/" }
let(:regex) { %r{href=.*?/homebrew[._-]v?(\d+(?:\.\d+)+)/?["' >]}i }
let(:page_content) {
<<~EOS
Homebrew — Homebrew
EOS
}
let(:page_content_matches) { ["2.6.0", "2.5.0", "2.4.0", "2.3.0", "2.2.0", "2.1.0", "2.0.0", "1.9.0"] }
describe "::match?" do
it "returns true for any URL" do
expect(page_match.match?(url)).to be true
end
end
describe "::page_matches" do
it "finds matching text in page content using a regex" do
expect(page_match.page_matches(page_content, regex)).to eq(page_content_matches)
end
it "finds matching text in page content using a strategy block" do
expect(page_match.page_matches(page_content, regex) { |content| content.scan(regex).map(&:first).uniq })
.to eq(page_content_matches)
end
end
end