json_spec: Clean up tests
This renames `simple_content` to `content_simple`, which makes the `content_*` variable name convention more consistent (as is in the `Xml` strategy tests).
This commit is contained in:
parent
cebb951baf
commit
e75ab0a26f
@ -11,7 +11,6 @@ describe Homebrew::Livecheck::Strategy::Json do
|
||||
|
||||
let(:regex) { /^v?(\d+(?:\.\d+)+)$/i }
|
||||
|
||||
let(:simple_content) { '{"version":"1.2.3"}' }
|
||||
let(:content) {
|
||||
<<~EOS
|
||||
{
|
||||
@ -40,9 +39,10 @@ describe Homebrew::Livecheck::Strategy::Json do
|
||||
}
|
||||
EOS
|
||||
}
|
||||
let(:content_simple) { '{"version":"1.2.3"}' }
|
||||
|
||||
let(:simple_content_matches) { ["1.2.3"] }
|
||||
let(:content_matches) { ["1.1.2", "1.1.1", "1.1.0", "1.0.3", "1.0.2", "1.0.1", "1.0.0"] }
|
||||
let(:content_simple_matches) { ["1.2.3"] }
|
||||
|
||||
let(:find_versions_return_hash) {
|
||||
{
|
||||
@ -92,10 +92,10 @@ describe Homebrew::Livecheck::Strategy::Json do
|
||||
|
||||
it "returns an array of version strings when given content and a block" do
|
||||
# Returning a string from block
|
||||
expect(json.versions_from_content(simple_content) { |json| json["version"] }).to eq(simple_content_matches)
|
||||
expect(json.versions_from_content(simple_content, regex) do |json|
|
||||
expect(json.versions_from_content(content_simple) { |json| json["version"] }).to eq(content_simple_matches)
|
||||
expect(json.versions_from_content(content_simple, regex) do |json|
|
||||
json["version"][regex, 1]
|
||||
end).to eq(simple_content_matches)
|
||||
end).to eq(content_simple_matches)
|
||||
|
||||
# Returning an array of strings from block
|
||||
expect(json.versions_from_content(content, regex) do |json, regex|
|
||||
@ -105,16 +105,16 @@ describe Homebrew::Livecheck::Strategy::Json do
|
||||
end
|
||||
|
||||
it "allows a nil return from a block" do
|
||||
expect(json.versions_from_content(content, regex) { next }).to eq([])
|
||||
expect(json.versions_from_content(content_simple, regex) { next }).to eq([])
|
||||
end
|
||||
|
||||
it "errors if a block uses two arguments but a regex is not given" do
|
||||
expect { json.versions_from_content(simple_content) { |json, regex| json["version"][regex, 1] } }
|
||||
expect { json.versions_from_content(content_simple) { |json, regex| json["version"][regex, 1] } }
|
||||
.to raise_error("Two arguments found in `strategy` block but no regex provided.")
|
||||
end
|
||||
|
||||
it "errors on an invalid return type from a block" do
|
||||
expect { json.versions_from_content(content, regex) { 123 } }
|
||||
expect { json.versions_from_content(content_simple, regex) { 123 } }
|
||||
.to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user