Skip to content

Commit 65ea110

Browse files
authored
Refactor: Replace double with instance_double for DependencyGroup and Dependency in specs
1 parent e3989b9 commit 65ea110

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

updater/spec/dependabot/updater/group_dependency_selector_spec.rb

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
RSpec.describe Dependabot::Updater::GroupDependencySelector do
1111
let(:group_name) { "backend-dependencies" }
1212
let(:dependency_group) do
13-
double(
14-
"DependencyGroup",
13+
instance_double(
14+
Dependabot::DependencyGroup,
1515
name: group_name,
1616
dependencies: [],
1717
rules: group_rules
@@ -163,8 +163,7 @@
163163
end
164164

165165
# 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)
168167

169168
# Mock the dependency change to have mutable updated_dependencies array
170169
allow(dependency_change.updated_dependencies).to receive(:clear)
@@ -176,7 +175,8 @@
176175
selector.filter_to_group!(dependency_change)
177176

178177
# 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) }
180180
expect(included_deps.length).to eq(2)
181181
end
182182

@@ -216,8 +216,7 @@
216216
end
217217

218218
# 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)
221220

222221
# Mock the dependency change array methods
223222
allow(dependency_change.updated_dependencies).to receive(:clear)
@@ -294,21 +293,6 @@
294293
let(:redis_dep) { create_dependency("redis-client", "0.11.0") }
295294
let(:unauthorized_dep) { create_dependency("puma", "5.6.0") }
296295

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-
312296
context "when group uses pattern matching fallback" do
313297
before do
314298
allow(dependency_group).to receive(:respond_to?)
@@ -360,7 +344,7 @@
360344
end
361345

362346
it "returns false when dependency is ignored" do
363-
all_versions_condition = double("ignore_condition")
347+
all_versions_condition = instance_double(Dependabot::Config::IgnoreCondition)
364348
allow(job).to receive(:ignore_conditions_for).with(dependency).and_return([all_versions_condition])
365349

366350
# Mock the constant check
@@ -381,8 +365,8 @@
381365
private
382366

383367
def create_dependency(name, version)
384-
double(
385-
"Dependency",
368+
instance_double(
369+
Dependabot::Dependency,
386370
name: name,
387371
version: version
388372
).tap do |dep|
@@ -392,10 +376,8 @@ def create_dependency(name, version)
392376
allow(dep).to receive(:attribution_directory=)
393377
allow(dep).to receive(:attribution_timestamp=)
394378
# 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)
399381
end
400382
end
401383

0 commit comments

Comments
 (0)