|
8 | 8 | let(:pypi_url) { "https://files.pythonhosted.org/packages/ab/cd/efg/example-package-1.2.3.tar.gz" } |
9 | 9 | let(:non_pypi_url) { "https://brew.sh/test" } |
10 | 10 |
|
11 | | - let(:regex) { /^v?(\d+(?:\.\d+)+)$/i } |
| 11 | + let(:regex) { /^v?(\d+(?:\.\d+)+)/i } |
12 | 12 |
|
13 | 13 | let(:generated) do |
14 | 14 | { |
|
17 | 17 | end |
18 | 18 |
|
19 | 19 | # This is a limited subset of a PyPI JSON API response object, for the sake |
20 | | - # of testing. |
| 20 | + # of testing. Typical versions use a `1.2.3` format but this adds a suffix, |
| 21 | + # so we can test regex matching. |
21 | 22 | let(:content) do |
22 | 23 | <<~JSON |
23 | 24 | { |
24 | 25 | "info": { |
25 | | - "version": "1.2.3" |
| 26 | + "version": "1.2.3-456" |
26 | 27 | } |
27 | 28 | } |
28 | 29 | JSON |
29 | 30 | end |
30 | 31 |
|
31 | | - let(:matches) { ["1.2.3"] } |
| 32 | + let(:matches) { ["1.2.3-456"] } |
32 | 33 |
|
33 | 34 | let(:find_versions_return_hash) do |
34 | 35 | { |
35 | 36 | matches: { |
36 | | - "1.2.3" => Version.new("1.2.3"), |
| 37 | + "1.2.3-456" => Version.new("1.2.3-456"), |
37 | 38 | }, |
38 | | - regex: nil, |
| 39 | + regex:, |
39 | 40 | url: generated[:url], |
40 | 41 | } |
41 | 42 | end |
|
76 | 77 | { |
77 | 78 | cached:, |
78 | 79 | cached_default: cached.merge({ matches: {} }), |
| 80 | + cached_regex: cached.merge({ |
| 81 | + matches: { "1.2.3" => Version.new("1.2.3") }, |
| 82 | + regex:, |
| 83 | + }), |
79 | 84 | } |
80 | 85 | end |
81 | 86 |
|
82 | 87 | it "finds versions in provided content" do |
| 88 | + expect(pypi.find_versions(url: pypi_url, regex:, provided_content: content)) |
| 89 | + .to eq(match_data[:cached_regex]) |
| 90 | + |
83 | 91 | expect(pypi.find_versions(url: pypi_url, provided_content: content)) |
84 | 92 | .to eq(match_data[:cached]) |
85 | 93 | end |
|
92 | 100 | next if match.blank? |
93 | 101 |
|
94 | 102 | match[1] |
95 | | - end).to eq(match_data[:cached].merge({ regex: })) |
| 103 | + end).to eq(match_data[:cached_regex]) |
96 | 104 |
|
97 | 105 | expect(pypi.find_versions(url: pypi_url, provided_content: content) do |json| |
98 | 106 | json.dig("info", "version").presence |
99 | 107 | end).to eq(match_data[:cached]) |
100 | 108 | end |
101 | 109 |
|
102 | 110 | it "returns default match_data when block doesn't return version information" do |
| 111 | + no_match_regex = /will_not_match/i |
| 112 | + |
103 | 113 | expect(pypi.find_versions(url: pypi_url, provided_content: '{"info":{"version":""}}')) |
104 | 114 | .to eq(match_data[:cached_default]) |
105 | 115 | expect(pypi.find_versions(url: pypi_url, provided_content: '{"other":true}')) |
106 | 116 | .to eq(match_data[:cached_default]) |
| 117 | + expect(pypi.find_versions(url: pypi_url, regex: no_match_regex, provided_content: content)) |
| 118 | + .to eq(match_data[:cached_default].merge({ regex: no_match_regex })) |
107 | 119 | end |
108 | 120 |
|
109 | 121 | it "returns default match_data when url is blank" do |
|
0 commit comments