Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling RSpec IndexedLet Rubocop rule #10024

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,6 @@ RSpec/FilePath:
- 'nuget/spec/dependabot/nuget/update_checker/repository_finder_spec.rb'
- 'nuget/spec/dependabot/nuget/update_checker/tfm_finder_spec.rb'

# Offense count: 70
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
RSpec/IndexedLet:
Exclude:
- 'bundler/spec/dependabot/bundler/helper_spec.rb'
- 'cargo/spec/dependabot/cargo/file_parser_spec.rb'
- 'common/spec/dependabot/dependency_file_spec.rb'
- 'common/spec/dependabot/dependency_group_spec.rb'
- 'common/spec/dependabot/dependency_spec.rb'
- 'common/spec/dependabot/pull_request_creator/message_builder_spec.rb'
- 'github_actions/spec/dependabot/github_actions/update_checker_spec.rb'
- 'hex/spec/dependabot/hex/file_parser_spec.rb'
- 'hex/spec/dependabot/hex/file_updater/lockfile_updater_spec.rb'
- 'hex/spec/dependabot/hex/file_updater_spec.rb'
- 'hex/spec/dependabot/hex/update_checker_spec.rb'
- 'npm_and_yarn/spec/dependabot/npm_and_yarn/update_checker_spec.rb'
- 'python/spec/dependabot/python/file_updater/pip_compile_file_updater_spec.rb'
- 'python/spec/dependabot/python/update_checker/latest_version_finder_spec.rb'

# Offense count: 29
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Expand Down
12 changes: 6 additions & 6 deletions bundler/spec/dependabot/bundler/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
LOCKFILE
end

let(:lockfile_bundled_with_v1) do
let(:lockfile_bundle_with_version_one) do
Dependabot::DependencyFile.new(name: "Gemfile.lock", content: <<~LOCKFILE)
Mock Gemfile.lock Content Goes Here

Expand All @@ -23,7 +23,7 @@
LOCKFILE
end

let(:lockfile_bundled_with_v2) do
let(:lockfile_bundle_with_version_two) do
Dependabot::DependencyFile.new(name: "Gemfile.lock", content: <<~LOCKFILE)
Mock Gemfile.lock Content Goes Here

Expand Down Expand Up @@ -55,11 +55,11 @@ def described_method(lockfile)
end

it "is 1 if it was bundled with a v1.x version" do
expect(described_method(lockfile_bundled_with_v1)).to eql("1")
expect(described_method(lockfile_bundle_with_version_one)).to eql("1")
end

it "is 2 if it was bundled with a v2.x version" do
expect(described_method(lockfile_bundled_with_v2)).to eql("2")
expect(described_method(lockfile_bundle_with_version_two)).to eql("2")
end

it "is 2 if it was bundled with a future version" do
Expand All @@ -81,11 +81,11 @@ def described_method(lockfile)
end

it "is 1 if it was bundled with a v1.x version" do
expect(described_method(lockfile_bundled_with_v1)).to eql("1")
expect(described_method(lockfile_bundle_with_version_one)).to eql("1")
end

it "is 2 if it was bundled with a v2.x version" do
expect(described_method(lockfile_bundled_with_v2)).to eql("2")
expect(described_method(lockfile_bundle_with_version_two)).to eql("2")
end

it "reports the version if it was bundled with a future version" do
Expand Down
14 changes: 7 additions & 7 deletions cargo/spec/dependabot/cargo/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@
manifest,
lockfile,
workspace_child,
workspace_child2,
workspace_child3
second_workspace_child,
third_workspace_child
]
end
let(:workspace_child) do
Expand All @@ -291,19 +291,19 @@
content: fixture("manifests", "workspace_child")
)
end
let(:workspace_child2) do
let(:second_workspace_child) do
Dependabot::DependencyFile.new(
name: "src/sub_crate2/Cargo.toml",
content: workspace_child2_body
content: second_workspace_child_body
)
end
let(:workspace_child3) do
let(:third_workspace_child) do
Dependabot::DependencyFile.new(
name: "src/sub_crate3/Cargo.toml",
content: workspace_child2_body
content: second_workspace_child_body
)
end
let(:workspace_child2_body) do
let(:second_workspace_child_body) do
fixture("manifests", "workspace_child_with_path_dependency")
end

Expand Down
24 changes: 12 additions & 12 deletions common/spec/dependabot/dependency_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,35 +288,35 @@

describe "#==" do
context "when two dependency files are equal" do
let(:file1) { described_class.new(name: "Gemfile", content: "a") }
let(:file2) { described_class.new(name: "Gemfile", content: "a") }
let(:file_one) { described_class.new(name: "Gemfile", content: "a") }
let(:file_two) { described_class.new(name: "Gemfile", content: "a") }

specify { expect(file1).to eq(file2) }
specify { expect(file_one).to eq(file_two) }
end

context "when two dependency files are equal, but one is a support file" do
let(:file1) { described_class.new(name: "Gemfile", content: "a") }
let(:file2) do
let(:file_one) { described_class.new(name: "Gemfile", content: "a") }
let(:file_two) do
described_class.new(name: "Gemfile", content: "a", support_file: true)
end

specify { expect(file1).to eq(file2) }
specify { expect(file_one).to eq(file_two) }
end

context "when two dependency files are equal, but one is a vendored file" do
let(:file1) { described_class.new(name: "Gemfile", content: "a") }
let(:file2) do
let(:file_one) { described_class.new(name: "Gemfile", content: "a") }
let(:file_two) do
described_class.new(name: "Gemfile", content: "a", vendored_file: true)
end

specify { expect(file1).to eq(file2) }
specify { expect(file_one).to eq(file_two) }
end

context "when two dependency files are not equal" do
let(:file1) { described_class.new(name: "Gemfile", content: "a") }
let(:file2) { described_class.new(name: "Gemfile", content: "b") }
let(:file_one) { described_class.new(name: "Gemfile", content: "a") }
let(:file_two) { described_class.new(name: "Gemfile", content: "b") }

specify { expect(file1).not_to eq(file2) }
specify { expect(file_one).not_to eq(file_two) }
end
end

Expand Down
34 changes: 17 additions & 17 deletions common/spec/dependabot/dependency_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:name) { "test_group" }
let(:rules) { { "patterns" => ["test-*"] } }

let(:test_dependency1) do
let(:test_first_dependency) do
Dependabot::Dependency.new(
name: "test-dependency-1",
package_manager: "bundler",
Expand All @@ -27,7 +27,7 @@
)
end

let(:test_dependency2) do
let(:test_second_dependency) do
Dependabot::Dependency.new(
name: "test-dependency-2",
package_manager: "bundler",
Expand Down Expand Up @@ -95,12 +95,12 @@

context "when dependencies have been assigned" do
before do
dependency_group.dependencies << test_dependency1
dependency_group.dependencies << test_first_dependency
end

it "returns the dependencies" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.dependencies).not_to include(test_dependency2)
expect(dependency_group.dependencies).to include(test_first_dependency)
expect(dependency_group.dependencies).not_to include(test_second_dependency)
end
end
end
Expand All @@ -117,12 +117,12 @@
context "when no dependencies are assigned to the group" do
it "returns true if the dependency matches a pattern" do
expect(dependency_group.dependencies).to eq([])
expect(dependency_group.contains?(test_dependency1)).to be(true)
expect(dependency_group.contains?(test_first_dependency)).to be(true)
end

it "returns false if the dependency is specifically excluded" do
expect(dependency_group.dependencies).to eq([])
expect(dependency_group.contains?(test_dependency2)).to be(false)
expect(dependency_group.contains?(test_second_dependency)).to be(false)
end

it "returns false if the dependency does not match any patterns" do
Expand All @@ -133,21 +133,21 @@

context "when dependencies are assigned to the group" do
before do
dependency_group.dependencies << test_dependency1
dependency_group.dependencies << test_first_dependency
end

it "returns true if the dependency is in the dependency list" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.contains?(test_dependency1)).to be(true)
expect(dependency_group.dependencies).to include(test_first_dependency)
expect(dependency_group.contains?(test_first_dependency)).to be(true)
end

it "returns false if the dependency is specifically excluded" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.contains?(test_dependency2)).to be(false)
expect(dependency_group.dependencies).to include(test_first_dependency)
expect(dependency_group.contains?(test_second_dependency)).to be(false)
end

it "returns false if the dependency is not in the dependency list and does not match a pattern" do
expect(dependency_group.dependencies).to include(test_dependency1)
expect(dependency_group.dependencies).to include(test_first_dependency)
expect(dependency_group.contains?(production_dependency)).to be(false)
end
end
Expand All @@ -165,8 +165,8 @@
end

it "returns false if the dependency does not match the specified type" do
expect(dependency_group.contains?(test_dependency1)).to be(false)
expect(dependency_group.contains?(test_dependency2)).to be(false)
expect(dependency_group.contains?(test_first_dependency)).to be(false)
expect(dependency_group.contains?(test_second_dependency)).to be(false)
end

context "when a dependency is specifically excluded" do
Expand All @@ -193,15 +193,15 @@
end

it "returns true if the dependency matches the specified type and a pattern" do
expect(dependency_group.contains?(test_dependency1)).to be(true)
expect(dependency_group.contains?(test_first_dependency)).to be(true)
end

it "returns false if the dependency only matches the pattern" do
expect(dependency_group.contains?(production_dependency)).to be(false)
end

it "returns false if the dependency matches the specified type and pattern but is excluded" do
expect(dependency_group.contains?(test_dependency2)).to be(false)
expect(dependency_group.contains?(test_second_dependency)).to be(false)
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions common/spec/dependabot/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@
end

context "when two dependencies are equal" do
let(:dependency1) { described_class.new(**args) }
let(:dependency2) { described_class.new(**args) }
let(:first_dependency) { described_class.new(**args) }
let(:second_dependency) { described_class.new(**args) }

specify { expect(dependency1).to eq(dependency2) }
specify { expect(first_dependency).to eq(second_dependency) }
end

context "when two dependencies are not equal" do
let(:dependency1) { described_class.new(**args) }
let(:dependency2) { described_class.new(**args.merge(name: "dep2")) }
let(:first_dependency) { described_class.new(**args) }
let(:second_dependency) { described_class.new(**args.merge(name: "dep2")) }

specify { expect(dependency1).not_to eq(dependency2) }
specify { expect(first_dependency).not_to eq(second_dependency) }
end
end

Expand Down Expand Up @@ -327,19 +327,19 @@
end

it "isn't utilized by the equality operator" do
dependency1 = described_class.new(
first_dependency = described_class.new(
name: "dep",
requirements: [],
package_manager: "dummy",
metadata: { foo: 42 }
)
dependency2 = described_class.new(
second_dependency = described_class.new(
name: "dep",
requirements: [],
package_manager: "dummy",
metadata: { foo: 43 }
)
expect(dependency1).to eq(dependency2)
expect(first_dependency).to eq(second_dependency)
end
end

Expand Down
Loading
Loading