…lines 1–35 unchanged (35 lines)
36 # For the sake of brevity, this is a limited subset of the information found
37 # in release objects in a response from the GitHub API. Some of these objects
38 # are somewhat representative of real world scenarios but others are
39 # contrived examples for the sake of exercising code paths.
40 let(:content) do
41 <<~EOS
42 [
43 {
44 "tag_name": "v1.2.3",
45 "name": "v1.2.3",
46 "draft": false,
47 "prerelease": false
48 },
49 {
50 "tag_name": "no-version-tag-also",
51 "name": "1.2.2",
52 "draft": false,
53 "prerelease": false
54 },
55 {
56 "tag_name": "1.2.1",
57 "name": "No version title",
58 "draft": false,
59 "prerelease": false
60 },
61 {
62 "tag_name": "no-version-tag",
…lines 63–86 unchanged (24 lines)
87 }
88 ]
89 EOS
90 end
91 let(:json) { JSON.parse(content) }
92
93 let(:matches) { ["1.2.3", "1.2.2", "1.2.1"] }
94
95 describe "::match?" do
96 it "returns true for a GitHub release artifact URL" do
97 expect(github_releases.match?(github_urls[:release_asset])).to be true
98 end
99
…lines 100–144 unchanged (45 lines)
145 expect(github_releases.versions_from_content(content, regex) { "1.2.3" }).to eq(["1.2.3"])
146
147 # Returning an array of strings from block
148 expect(github_releases.versions_from_content(content, regex) do |json, regex|
149 json.map do |release|
150 next if release["draft"] || release["prerelease"]
151
152 match = release["tag_name"]&.match(regex)
153 next if match.blank?
154
155 match[1]
156 end
157 end).to eq(["1.2.3", "1.2.1"])
158 end
159
160 it "allows a nil return from a block" do
161 expect(github_releases.versions_from_content(content, regex) { next }).to eq([])
162 end
163
…lines 164–209 unchanged (46 lines)
210 next if match.blank?
211
212 match[1]
213 end
214 end,
215 ).to eq(match_data[:cached].merge({
216 matches: ["1.2.3", "1.2.1"].to_h { |v| [v, Version.new(v)] },
217 regex: brew_regex,
218 }))
219 end
220
221 it "returns default match_data when url is blank" do
222 expect(github_releases.find_versions(url: ""))
…lines 223–232 unchanged (10 lines)