Improve standardization of strategy tests

This commit is contained in:
Sam Ford 2021-08-10 17:39:11 -04:00
parent 56dd89114d
commit 7e07010f06
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
17 changed files with 63 additions and 47 deletions

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Apache do
let(:non_apache_url) { "https://brew.sh/test" } let(:non_apache_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is an Apache URL" do it "returns true for an Apache URL" do
expect(apache.match?(apache_url)).to be true expect(apache.match?(apache_url)).to be true
end end
it "returns false if the argument provided is not an Apache URL" do it "returns false for a non-Apache URL" do
expect(apache.match?(non_apache_url)).to be false expect(apache.match?(non_apache_url)).to be false
end end
end end

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Bitbucket do
let(:non_bitbucket_url) { "https://brew.sh/test" } let(:non_bitbucket_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a Bitbucket URL" do it "returns true for a Bitbucket URL" do
expect(bitbucket.match?(bitbucket_url)).to be true expect(bitbucket.match?(bitbucket_url)).to be true
end end
it "returns false if the argument provided is not a Bitbucket URL" do it "returns false for a non-Bitbucket URL" do
expect(bitbucket.match?(non_bitbucket_url)).to be false expect(bitbucket.match?(non_bitbucket_url)).to be false
end end
end end

View File

@ -11,12 +11,12 @@ describe Homebrew::Livecheck::Strategy::Cpan do
let(:non_cpan_url) { "https://brew.sh/test" } let(:non_cpan_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a CPAN URL" do it "returns true for a CPAN URL" do
expect(cpan.match?(cpan_url_no_subdirectory)).to be true expect(cpan.match?(cpan_url_no_subdirectory)).to be true
expect(cpan.match?(cpan_url_with_subdirectory)).to be true expect(cpan.match?(cpan_url_with_subdirectory)).to be true
end end
it "returns false if the argument provided is not a CPAN URL" do it "returns false for a non-CPAN URL" do
expect(cpan.match?(non_cpan_url)).to be false expect(cpan.match?(non_cpan_url)).to be false
end end
end end

View File

@ -6,8 +6,8 @@ require "livecheck/strategy"
describe Homebrew::Livecheck::Strategy::ElectronBuilder do describe Homebrew::Livecheck::Strategy::ElectronBuilder do
subject(:electron_builder) { described_class } subject(:electron_builder) { described_class }
let(:valid_url) { "https://www.example.com/example/latest-mac.yml" } let(:yaml_url) { "https://www.example.com/example/latest-mac.yml" }
let(:invalid_url) { "https://brew.sh/test" } let(:non_yaml_url) { "https://brew.sh/test" }
let(:electron_builder_yaml) { let(:electron_builder_yaml) {
<<~EOS <<~EOS
@ -29,12 +29,12 @@ describe Homebrew::Livecheck::Strategy::ElectronBuilder do
let(:versions) { ["1.2.3"] } let(:versions) { ["1.2.3"] }
describe "::match?" do describe "::match?" do
it "returns true for any URL pointing to a YAML file" do it "returns true for a YAML file URL" do
expect(electron_builder.match?(valid_url)).to be true expect(electron_builder.match?(yaml_url)).to be true
end end
it "returns false for a URL not pointing to a YAML file" do it "returns false for non-YAML URL" do
expect(electron_builder.match?(invalid_url)).to be false expect(electron_builder.match?(non_yaml_url)).to be false
end end
end end

View File

@ -39,11 +39,11 @@ describe Homebrew::Livecheck::Strategy::Git do
end end
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a Git repository" do it "returns true for a Git repository URL" do
expect(git.match?(git_url)).to be true expect(git.match?(git_url)).to be true
end end
it "returns false if the argument provided is not a Git repository" do it "returns false for a non-Git URL" do
expect(git.match?(non_git_url)).to be false expect(git.match?(non_git_url)).to be false
end end
end end

View File

@ -14,19 +14,19 @@ describe Homebrew::Livecheck::Strategy::GithubLatest do
let(:non_github_url) { "https://brew.sh/test" } let(:non_github_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a GitHub release artifact URL" do it "returns true for a GitHub release artifact URL" do
expect(github_latest.match?(github_release_artifact_url)).to be true expect(github_latest.match?(github_release_artifact_url)).to be true
end end
it "returns true if the argument provided is a GitHub tag archive URL" do it "returns true for a GitHub tag archive URL" do
expect(github_latest.match?(github_tag_archive_url)).to be true expect(github_latest.match?(github_tag_archive_url)).to be true
end end
it "returns true if the argument provided is a GitHub repository upload URL" do it "returns true for a GitHub repository upload URL" do
expect(github_latest.match?(github_repository_upload_url)).to be true expect(github_latest.match?(github_repository_upload_url)).to be true
end end
it "returns false if the argument provided is not a GitHub URL" do it "returns false for a non-GitHub URL" do
expect(github_latest.match?(non_github_url)).to be false expect(github_latest.match?(non_github_url)).to be false
end end
end end

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Gnome do
let(:non_gnome_url) { "https://brew.sh/test" } let(:non_gnome_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a GNOME URL" do it "returns true for a GNOME URL" do
expect(gnome.match?(gnome_url)).to be true expect(gnome.match?(gnome_url)).to be true
end end
it "returns false if the argument provided is not a GNOME URL" do it "returns false for a non-GNOME URL" do
expect(gnome.match?(non_gnome_url)).to be false expect(gnome.match?(non_gnome_url)).to be false
end end
end end

View File

@ -11,15 +11,15 @@ describe Homebrew::Livecheck::Strategy::Gnu do
let(:non_gnu_url) { "https://brew.sh/test" } let(:non_gnu_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a non-Savannah GNU URL" do it "returns true for a [non-Savannah] GNU URL" do
expect(gnu.match?(gnu_url)).to be true expect(gnu.match?(gnu_url)).to be true
end end
it "returns false if the argument provided is a Savannah GNU URL" do it "returns false for a Savannah GNU URL" do
expect(gnu.match?(savannah_gnu_url)).to be false expect(gnu.match?(savannah_gnu_url)).to be false
end end
it "returns false if the argument provided is not a GNU URL" do it "returns false for a non-GNU URL (not nongnu.org)" do
expect(gnu.match?(non_gnu_url)).to be false expect(gnu.match?(non_gnu_url)).to be false
end end
end end

View File

@ -11,12 +11,12 @@ describe Homebrew::Livecheck::Strategy::Hackage do
let(:non_hackage_url) { "https://brew.sh/test" } let(:non_hackage_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a Hackage URL" do it "returns true for a Hackage URL" do
expect(hackage.match?(hackage_url)).to be true expect(hackage.match?(hackage_url)).to be true
expect(hackage.match?(hackage_downloads_url)).to be true expect(hackage.match?(hackage_downloads_url)).to be true
end end
it "returns false if the argument provided is not a Hackage URL" do it "returns false for a non-Hackage URL" do
expect(hackage.match?(non_hackage_url)).to be false expect(hackage.match?(non_hackage_url)).to be false
end end
end end

View File

@ -6,7 +6,8 @@ require "livecheck/strategy"
describe Homebrew::Livecheck::Strategy::HeaderMatch do describe Homebrew::Livecheck::Strategy::HeaderMatch do
subject(:header_match) { described_class } subject(:header_match) { described_class }
let(:url) { "https://www.example.com/" } let(:http_url) { "https://brew.sh/blog/" }
let(:non_http_url) { "ftp://brew.sh/" }
let(:versions) { let(:versions) {
versions = { versions = {
@ -47,8 +48,12 @@ describe Homebrew::Livecheck::Strategy::HeaderMatch do
} }
describe "::match?" do describe "::match?" do
it "returns true for any URL" do it "returns true for an HTTP URL" do
expect(header_match.match?(url)).to be true expect(header_match.match?(http_url)).to be true
end
it "returns false for a non-HTTP URL" do
expect(header_match.match?(non_http_url)).to be false
end end
end end

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Launchpad do
let(:non_launchpad_url) { "https://brew.sh/test" } let(:non_launchpad_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a Launchpad URL" do it "returns true for a Launchpad URL" do
expect(launchpad.match?(launchpad_url)).to be true expect(launchpad.match?(launchpad_url)).to be true
end end
it "returns false if the argument provided is not a Launchpad URL" do it "returns false for a non-Launchpad URL" do
expect(launchpad.match?(non_launchpad_url)).to be false expect(launchpad.match?(non_launchpad_url)).to be false
end end
end end

View File

@ -11,12 +11,12 @@ describe Homebrew::Livecheck::Strategy::Npm do
let(:non_npm_url) { "https://brew.sh/test" } let(:non_npm_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is an npm URL" do it "returns true for an npm URL" do
expect(npm.match?(npm_url)).to be true expect(npm.match?(npm_url)).to be true
expect(npm.match?(npm_scoped_url)).to be true expect(npm.match?(npm_scoped_url)).to be true
end end
it "returns false if the argument provided is not an npm URL" do it "returns false for a non-npm URL" do
expect(npm.match?(non_npm_url)).to be false expect(npm.match?(non_npm_url)).to be false
end end
end end

View File

@ -6,7 +6,9 @@ require "livecheck/strategy"
describe Homebrew::Livecheck::Strategy::PageMatch do describe Homebrew::Livecheck::Strategy::PageMatch do
subject(:page_match) { described_class } subject(:page_match) { described_class }
let(:url) { "https://brew.sh/blog/" } let(:http_url) { "https://brew.sh/blog/" }
let(:non_http_url) { "ftp://brew.sh/" }
let(:regex) { %r{href=.*?/homebrew[._-]v?(\d+(?:\.\d+)+)/?["' >]}i } let(:regex) { %r{href=.*?/homebrew[._-]v?(\d+(?:\.\d+)+)/?["' >]}i }
let(:content) { let(:content) {
@ -50,7 +52,7 @@ describe Homebrew::Livecheck::Strategy::PageMatch do
"1.9.0" => Version.new("1.9.0"), "1.9.0" => Version.new("1.9.0"),
}, },
regex: regex, regex: regex,
url: url, url: http_url,
} }
} }
@ -61,8 +63,12 @@ describe Homebrew::Livecheck::Strategy::PageMatch do
} }
describe "::match?" do describe "::match?" do
it "returns true for any URL" do it "returns true for an HTTP URL" do
expect(page_match.match?(url)).to be true expect(page_match.match?(http_url)).to be true
end
it "returns false for a non-HTTP URL" do
expect(page_match.match?(non_http_url)).to be false
end end
end end
@ -100,7 +106,7 @@ describe Homebrew::Livecheck::Strategy::PageMatch do
describe "::find_versions?" do describe "::find_versions?" do
it "finds versions in provided_content" do it "finds versions in provided_content" do
expect(page_match.find_versions(url, regex, provided_content: content)) expect(page_match.find_versions(http_url, regex, provided_content: content))
.to eq(find_versions_cached_return_hash) .to eq(find_versions_cached_return_hash)
end end
end end

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Pypi do
let(:non_pypi_url) { "https://brew.sh/test" } let(:non_pypi_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a PyPI URL" do it "returns true for a PyPI URL" do
expect(pypi.match?(pypi_url)).to be true expect(pypi.match?(pypi_url)).to be true
end end
it "returns false if the argument provided is not a PyPI URL" do it "returns false for a non-PyPI URL" do
expect(pypi.match?(non_pypi_url)).to be false expect(pypi.match?(non_pypi_url)).to be false
end end
end end

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Sourceforge do
let(:non_sourceforge_url) { "https://brew.sh/test" } let(:non_sourceforge_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is a SourceForge URL" do it "returns true for a SourceForge URL" do
expect(sourceforge.match?(sourceforge_url)).to be true expect(sourceforge.match?(sourceforge_url)).to be true
end end
it "returns false if the argument provided is not a SourceForge URL" do it "returns false for a non-SourceForge URL" do
expect(sourceforge.match?(non_sourceforge_url)).to be false expect(sourceforge.match?(non_sourceforge_url)).to be false
end end
end end

View File

@ -7,7 +7,8 @@ require "bundle_version"
describe Homebrew::Livecheck::Strategy::Sparkle do describe Homebrew::Livecheck::Strategy::Sparkle do
subject(:sparkle) { described_class } subject(:sparkle) { described_class }
let(:url) { "https://www.example.com/example/appcast.xml" } let(:appcast_url) { "https://www.example.com/example/appcast.xml" }
let(:non_http_url) { "ftp://brew.sh/" }
let(:appcast_data) { let(:appcast_data) {
{ {
@ -25,7 +26,7 @@ describe Homebrew::Livecheck::Strategy::Sparkle do
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel> <channel>
<title>Example Changelog</title> <title>Example Changelog</title>
<link>#{url}</link> <link>#{appcast_url}</link>
<description>Most recent changes with links to updates.</description> <description>Most recent changes with links to updates.</description>
<language>en</language> <language>en</language>
<item> <item>
@ -52,8 +53,12 @@ describe Homebrew::Livecheck::Strategy::Sparkle do
let(:versions) { [item.bundle_version.nice_version] } let(:versions) { [item.bundle_version.nice_version] }
describe "::match?" do describe "::match?" do
it "returns true for any URL" do it "returns true for an HTTP URL" do
expect(sparkle.match?(url)).to be true expect(sparkle.match?(appcast_url)).to be true
end
it "returns false for a non-HTTP URL" do
expect(sparkle.match?(non_http_url)).to be false
end end
end end

View File

@ -10,11 +10,11 @@ describe Homebrew::Livecheck::Strategy::Xorg do
let(:non_xorg_url) { "https://brew.sh/test" } let(:non_xorg_url) { "https://brew.sh/test" }
describe "::match?" do describe "::match?" do
it "returns true if the argument provided is an X.Org URL" do it "returns true for an X.Org URL" do
expect(xorg.match?(xorg_url)).to be true expect(xorg.match?(xorg_url)).to be true
end end
it "returns false if the argument provided is not an X.Org URL" do it "returns false for a non-X.Org URL" do
expect(xorg.match?(non_xorg_url)).to be false expect(xorg.match?(non_xorg_url)).to be false
end end
end end