10
10
RSpec . describe Dependabot ::Updater ::GroupDependencySelector do
11
11
let ( :group_name ) { "backend-dependencies" }
12
12
let ( :dependency_group ) do
13
- double (
14
- " DependencyGroup" ,
13
+ instance_double (
14
+ Dependabot :: DependencyGroup ,
15
15
name : group_name ,
16
16
dependencies : [ ] ,
17
17
rules : group_rules
163
163
end
164
164
165
165
# Mock job configuration checking
166
- allow ( job ) . to receive ( :ignore_conditions_for ) . and_return ( [ ] )
167
- allow ( job ) . to receive ( :allowed_update? ) . and_return ( true )
166
+ allow ( job ) . to receive_messages ( ignore_conditions_for : [ ] , allowed_update? : true )
168
167
169
168
# Mock the dependency change to have mutable updated_dependencies array
170
169
allow ( dependency_change . updated_dependencies ) . to receive ( :clear )
176
175
selector . filter_to_group! ( dependency_change )
177
176
178
177
# Check that the selector attempted to filter dependencies
179
- included_deps = original_deps . select { |dep | %w( rails redis-client ) . include? ( dep . name ) }
178
+ expected_deps = %w( rails redis-client )
179
+ included_deps = original_deps . select { |dep | expected_deps . include? ( dep . name ) }
180
180
expect ( included_deps . length ) . to eq ( 2 )
181
181
end
182
182
216
216
end
217
217
218
218
# Mock job configuration checking
219
- allow ( job ) . to receive ( :ignore_conditions_for ) . and_return ( [ ] )
220
- allow ( job ) . to receive ( :allowed_update? ) . and_return ( true )
219
+ allow ( job ) . to receive_messages ( ignore_conditions_for : [ ] , allowed_update? : true )
221
220
222
221
# Mock the dependency change array methods
223
222
allow ( dependency_change . updated_dependencies ) . to receive ( :clear )
294
293
let ( :redis_dep ) { create_dependency ( "redis-client" , "0.11.0" ) }
295
294
let ( :unauthorized_dep ) { create_dependency ( "puma" , "5.6.0" ) }
296
295
297
- context "when group has contains_dependency? method" do
298
- before do
299
- allow ( dependency_group ) . to receive ( :respond_to? )
300
- . with ( :contains_dependency? ) . and_return ( true )
301
- allow ( dependency_group ) . to receive ( :contains_dependency? ) do |dep , directory :|
302
- %w( rails pg ) . include? ( dep . name )
303
- end
304
- end
305
-
306
- it "uses the group's method" do
307
- expect ( selector . send ( :group_contains_dependency? , rails_dep , "/api" ) ) . to be true
308
- expect ( selector . send ( :group_contains_dependency? , unauthorized_dep , "/api" ) ) . to be false
309
- end
310
- end
311
-
312
296
context "when group uses pattern matching fallback" do
313
297
before do
314
298
allow ( dependency_group ) . to receive ( :respond_to? )
360
344
end
361
345
362
346
it "returns false when dependency is ignored" do
363
- all_versions_condition = double ( "ignore_condition" )
347
+ all_versions_condition = instance_double ( Dependabot :: Config :: IgnoreCondition )
364
348
allow ( job ) . to receive ( :ignore_conditions_for ) . with ( dependency ) . and_return ( [ all_versions_condition ] )
365
349
366
350
# Mock the constant check
381
365
private
382
366
383
367
def create_dependency ( name , version )
384
- double (
385
- " Dependency" ,
368
+ instance_double (
369
+ Dependabot :: Dependency ,
386
370
name : name ,
387
371
version : version
388
372
) . tap do |dep |
@@ -392,10 +376,8 @@ def create_dependency(name, version)
392
376
allow ( dep ) . to receive ( :attribution_directory= )
393
377
allow ( dep ) . to receive ( :attribution_timestamp= )
394
378
# Allow attribution getter methods
395
- allow ( dep ) . to receive ( :attribution_source_group ) . and_return ( nil )
396
- allow ( dep ) . to receive ( :attribution_selection_reason ) . and_return ( nil )
397
- allow ( dep ) . to receive ( :attribution_directory ) . and_return ( nil )
398
- allow ( dep ) . to receive ( :attribution_timestamp ) . and_return ( nil )
379
+ allow ( dep ) . to receive_messages ( attribution_source_group : nil , attribution_selection_reason : nil ,
380
+ attribution_directory : nil , attribution_timestamp : nil )
399
381
end
400
382
end
401
383
0 commit comments