39
39
40
40
it 'fails if it does not find the right release on GitHub' do
41
41
stub = stub_request ( :get , content_url ) . to_return ( status : [ 404 , 'Not Found' ] )
42
- expect ( described_class . download_file_from_tag ( repository : test_repo , tag : test_tag , file_path : test_file , download_folder : './' ) ) . to be_nil
42
+ donwloaded_file = described_class . download_file_from_tag ( repository : test_repo , tag : test_tag , file_path : test_file , download_folder : './' )
43
+ expect ( donwloaded_file ) . to be_nil
43
44
expect ( stub ) . to have_been_made . once
44
45
end
45
46
46
47
it 'writes the raw content to a file' do
47
48
stub = stub_request ( :get , content_url ) . to_return ( status : 200 , body : 'my-test-content' )
48
49
Dir . mktmpdir ( 'a8c-download-repo-file-' ) do |tmpdir |
49
50
dst_file = File . join ( tmpdir , 'test-file.xml' )
50
- expect ( described_class . download_file_from_tag ( repository : test_repo , tag : test_tag , file_path : test_file , download_folder : tmpdir ) ) . to eq ( dst_file )
51
+ donwloaded_file = described_class . download_file_from_tag ( repository : test_repo , tag : test_tag , file_path : test_file , download_folder : tmpdir )
52
+ expect ( donwloaded_file ) . to eq ( dst_file )
51
53
expect ( stub ) . to have_been_made . once
52
54
expect ( File . read ( dst_file ) ) . to eq ( 'my-test-content' )
53
55
end
70
72
71
73
it 'returns correct milestone' do
72
74
expect ( client ) . to receive ( :list_milestones )
73
- expect ( described_class . get_last_milestone ( repository : test_repo ) ) . to eq ( last_stone )
75
+ last_milestone = described_class . get_last_milestone ( repository : test_repo )
76
+ expect ( last_milestone ) . to eq ( last_stone )
74
77
end
75
78
76
79
def mock_milestone ( title )
@@ -136,7 +139,7 @@ def mock_comment(body: '<!-- REUSE_ID: test-id --> Test', user_id: 1234)
136
139
137
140
describe 'get_milestone' do
138
141
let ( :test_repo ) { 'repo-test/project-test' }
139
- let ( :test_milestone ) { [ { title : 'release/10.0 ' } , { title : 'release/ 10.1' } , { title : 'hotfix/ 10.2 ' } ] }
142
+ let ( :test_milestones ) { [ { title : '9.8 ' } , { title : '10.1' } , { title : '10.1.3 ❄️ ' } ] }
140
143
let ( :client ) do
141
144
instance_double (
142
145
Octokit ::Client ,
@@ -154,22 +157,26 @@ def mock_comment(body: '<!-- REUSE_ID: test-id --> Test', user_id: 1234)
154
157
end
155
158
156
159
it 'returns nil when no milestone is returned from the api' do
157
- expect ( described_class . get_milestone ( test_repo , 'release' ) ) . to be_nil
160
+ milestone = described_class . get_milestone ( test_repo , '10' )
161
+ expect ( milestone ) . to be_nil
158
162
end
159
163
160
164
it 'returns nil when no milestone title starts with the searched term' do
161
- allow ( client ) . to receive ( :list_milestones ) . and_return ( test_milestone )
162
- expect ( described_class . get_milestone ( test_repo , '10.0' ) ) . to be_nil
165
+ allow ( client ) . to receive ( :list_milestones ) . and_return ( test_milestones )
166
+ milestone = described_class . get_milestone ( test_repo , '8.5' )
167
+ expect ( milestone ) . to be_nil
163
168
end
164
169
165
170
it 'returns a milestone when the milestone title starts with search term' do
166
- allow ( client ) . to receive ( :list_milestones ) . and_return ( test_milestone )
167
- expect ( described_class . get_milestone ( test_repo , 'hotfix' ) ) . to eq ( { title : 'hotfix/10.2' } )
171
+ allow ( client ) . to receive ( :list_milestones ) . and_return ( test_milestones )
172
+ milestone = described_class . get_milestone ( test_repo , '9' )
173
+ expect ( milestone ) . to eq ( { title : '9.8' } )
168
174
end
169
175
170
- it 'returns the newest of milestones where the title matches with search term' do
171
- allow ( client ) . to receive ( :list_milestones ) . and_return ( test_milestone )
172
- expect ( described_class . get_milestone ( test_repo , 'release' ) ) . to eq ( { title : 'release/10.1' } )
176
+ it 'returns the milestone with the latest due date matching the search term when there are more than one' do
177
+ allow ( client ) . to receive ( :list_milestones ) . and_return ( test_milestones )
178
+ milestone = described_class . get_milestone ( test_repo , '10.1' )
179
+ expect ( milestone ) . to eq ( { title : '10.1.3 ❄️' } )
173
180
end
174
181
end
175
182
@@ -235,7 +242,7 @@ def create_milestone(need_submission:, milestone_duration:, days_code_freeze:)
235
242
it 'has the correct options' do
236
243
options = { body : test_description , draft : true , name : test_tag , prerelease : false , target_commitish : test_target }
237
244
expect ( client ) . to receive ( :create_release ) . with ( test_repo , test_tag , options )
238
- mockrelease
245
+ create_release
239
246
end
240
247
241
248
it 'upload the assets to the correct location' do
@@ -244,10 +251,10 @@ def create_milestone(need_submission:, milestone_duration:, days_code_freeze:)
244
251
245
252
allow ( client ) . to receive ( :create_release ) . and_return ( { url : test_url } )
246
253
expect ( client ) . to receive ( :upload_asset ) . with ( test_url , test_assets , { content_type : 'application/octet-stream' } )
247
- mockrelease ( [ test_assets ] )
254
+ create_release ( assets : [ test_assets ] )
248
255
end
249
256
250
- def mockrelease ( assets = [ ] )
257
+ def create_release ( assets : [ ] )
251
258
described_class . create_release (
252
259
repository : test_repo ,
253
260
version : test_tag ,
0 commit comments