Skip to content

Commit

Permalink
Enable RSpec/LeadingSubject
Browse files Browse the repository at this point in the history
  • Loading branch information
robaiken committed May 23, 2024
1 parent 098e683 commit 58022ce
Show file tree
Hide file tree
Showing 74 changed files with 221 additions and 287 deletions.
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ RSpec/IteratedExpectation:
- 'python/spec/dependabot/python/file_updater/requirement_file_updater_spec.rb'
- 'python/spec/dependabot/python/file_updater_spec.rb'

# Offense count: 126
# This cop supports safe autocorrection (--autocorrect).
RSpec/LeadingSubject:
Enabled: false

# Offense count: 675
# This cop supports safe autocorrection (--autocorrect).
RSpec/LetBeforeExamples:
Expand Down
6 changes: 2 additions & 4 deletions bundler/helpers/v1/spec/functions/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
end

describe "#parsed_gemfile" do
let(:project_name) { "gemfile" }

subject(:parsed_gemfile) do
in_tmp_folder do
dependency_source.parsed_gemfile(gemfile_name: "Gemfile")
end
end
let(:project_name) { "gemfile" }

it "parses gemfile" do
parsed_gemfile = [
Expand All @@ -44,13 +43,12 @@
end

describe "#parsed_gemspec" do
let(:project_name) { "gemfile_exact" }

subject(:parsed_gemspec) do
in_tmp_folder do |_tmp_path|
dependency_source.parsed_gemspec(gemspec_name: "example.gemspec")
end
end
let(:project_name) { "gemfile_exact" }

it "parses gemspec" do
parsed_gemspec = [
Expand Down
6 changes: 2 additions & 4 deletions bundler/helpers/v2/spec/functions/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
end

describe "#parsed_gemfile" do
let(:project_name) { "gemfile" }

subject(:parsed_gemfile) do
in_tmp_folder do
dependency_source.parsed_gemfile(gemfile_name: "Gemfile")
end
end
let(:project_name) { "gemfile" }

it "parses gemfile" do
parsed_gemfile = [
Expand Down Expand Up @@ -109,13 +108,12 @@
end

describe "#parsed_gemspec" do
let(:project_name) { "gemfile_exact" }

subject(:parsed_gemspec) do
in_tmp_folder do |_tmp_path|
dependency_source.parsed_gemspec(gemspec_name: "example.gemspec")
end
end
let(:project_name) { "gemfile_exact" }

it "parses gemspec" do
parsed_gemspec = [
Expand Down
2 changes: 1 addition & 1 deletion bundler/helpers/v2/spec/functions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
end

describe "#git_specs" do
let(:project_name) { "git_source" }
subject(:git_specs) do
in_tmp_folder do
Functions.git_specs(
Expand All @@ -34,6 +33,7 @@
)
end
end
let(:project_name) { "git_source" }

def expect_specs(count)
expect(git_specs.size).to eq(count)
Expand Down
10 changes: 5 additions & 5 deletions bundler/spec/dependabot/bundler/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@

context "with no version specified" do
describe "the first dependency" do
let(:dependency_files) { bundler_project_dependency_files("version_not_specified") }
subject { dependencies.first }
let(:dependency_files) { bundler_project_dependency_files("version_not_specified") }
let(:expected_requirements) do
[{
requirement: ">= 0",
Expand Down Expand Up @@ -234,9 +234,9 @@
end

describe "a github dependency", :bundler_v1_only do
subject { dependencies.find { |d| d.name == "business" } }
let(:dependency_files) { bundler_project_dependency_files("github_source") }

subject { dependencies.find { |d| d.name == "business" } }
let(:expected_requirements) do
[{
requirement: ">= 0",
Expand All @@ -259,9 +259,9 @@
end

describe "a github dependency", :bundler_v2_only do
subject { dependencies.find { |d| d.name == "business" } }
let(:dependency_files) { bundler_project_dependency_files("github_source") }

subject { dependencies.find { |d| d.name == "business" } }
let(:expected_requirements) do
[{
requirement: ">= 0",
Expand All @@ -284,9 +284,9 @@
end

context "with a subdependency of a git source", :bundler_v1_only do
subject { dependencies.find { |d| d.name == "kaminari-actionview" } }
let(:dependency_files) { bundler_project_dependency_files("git_source_undeclared") }

subject { dependencies.find { |d| d.name == "kaminari-actionview" } }
let(:expected_requirements) do
[{
requirement: ">= 0",
Expand All @@ -307,9 +307,9 @@
end

context "with a subdependency of a git source", :bundler_v2_only do
subject { dependencies.find { |d| d.name == "kaminari-actionview" } }
let(:dependency_files) { bundler_project_dependency_files("git_source_undeclared") }

subject { dependencies.find { |d| d.name == "kaminari-actionview" } }
let(:expected_requirements) do
[{
requirement: ">= 0",
Expand Down
3 changes: 1 addition & 2 deletions bundler/spec/dependabot/bundler/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@
end

context "when dealing with a gems.rb setup" do
let(:project_name) { "gems_rb" }

subject(:file) { updated_files.find { |f| f.name == "gems.locked" } }
let(:project_name) { "gems_rb" }

let(:requirements) do
[{
Expand Down
6 changes: 3 additions & 3 deletions bundler/spec/dependabot/bundler/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
require_common_spec "metadata_finders/shared_examples_for_metadata_finders"

RSpec.describe Dependabot::Bundler::MetadataFinder do
subject(:finder) do
described_class.new(dependency: dependency, credentials: credentials)
end
it_behaves_like "a dependency metadata finder"

let(:dependency) do
Expand All @@ -22,9 +25,6 @@
package_manager: "bundler"
)
end
subject(:finder) do
described_class.new(dependency: dependency, credentials: credentials)
end
let(:credentials) do
[{
"type" => "git_source",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
end

context "with a gems.rb and gems.locked setup" do
let(:dependency_files) { bundler_project_dependency_files("gems_rb") }
subject { prepared_dependency_files.find { |f| f.name == "gems.rb" } }
let(:dependency_files) { bundler_project_dependency_files("gems_rb") }

it "returns the right files" do
expect(prepared_dependency_files.map(&:name))
Expand Down Expand Up @@ -221,12 +221,11 @@
end

describe "the updated gemspec" do
let(:dependency_files) { bundler_project_dependency_files("gemfile_small_example") }
let(:version) { "1.4.3" }

subject do
prepared_dependency_files.find { |f| f.name == "example.gemspec" }
end
let(:dependency_files) { bundler_project_dependency_files("gemfile_small_example") }
let(:version) { "1.4.3" }

its(:content) { is_expected.to include("'business', '>= 1.4.3'\n") }

Expand Down Expand Up @@ -287,10 +286,10 @@
end

describe "the updated path gemspec" do
subject { prepared_dependency_files.find { |f| f.name == "some/example.gemspec" } }
let(:dependency_files) do
bundler_project_dependency_files("nested_gemspec")
end
subject { prepared_dependency_files.find { |f| f.name == "some/example.gemspec" } }
let(:version) { "1.4.3" }

its(:content) { is_expected.to include(%("business", ">= 1.4.3")) }
Expand All @@ -305,12 +304,11 @@
end

describe "the updated child gemfile" do
let(:dependency_files) { bundler_project_dependency_files("nested_gemfile") }
let(:version) { "1.4.3" }

subject do
prepared_dependency_files.find { |f| f.name == "backend/Gemfile" }
end
let(:dependency_files) { bundler_project_dependency_files("nested_gemfile") }
let(:version) { "1.4.3" }

its(:content) { is_expected.to include(%("business", ">= 1.4.3")) }
its(:content) { is_expected.to include(%("statesman", "~> 1.2.0")) }
Expand Down
19 changes: 7 additions & 12 deletions bundler/spec/dependabot/bundler/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@
end

describe "#latest_version_resolvable_with_full_unlock?" do
include_context "when stubbing rubygems compact index"
subject { checker.send(:latest_version_resolvable_with_full_unlock?) }
include_context "when stubbing rubygems compact index"

context "with no latest version" do
before do
Expand Down Expand Up @@ -456,10 +456,10 @@
end

describe "#updated_dependencies_after_full_unlock" do
include_context "when stubbing rubygems compact index"
subject(:updated_dependencies_after_full_unlock) do
checker.send(:updated_dependencies_after_full_unlock)
end
include_context "when stubbing rubygems compact index"

context "with a latest version" do
before do
Expand Down Expand Up @@ -558,11 +558,10 @@
end

describe "#conflicting_dependencies" do
subject { checker.conflicting_dependencies }
include_context "when stubbing rubygems compact index"
include_context "when stubbing rubygems versions api"

subject { checker.conflicting_dependencies }

let(:dependency_files) { bundler_project_dependency_files("subdep_blocked_by_subdep") }
let(:target_version) { "2.0.0" }
let(:dependency_name) { "dummy-pkg-a" }
Expand Down Expand Up @@ -605,11 +604,10 @@
end

describe "#latest_resolvable_version" do
subject { checker.latest_resolvable_version }
include_context "when stubbing rubygems compact index"
include_context "when stubbing rubygems versions api"

subject { checker.latest_resolvable_version }

context "when given a gem from rubygems" do
context "when that only appears in the lockfile" do
let(:dependency_files) { bundler_project_dependency_files("subdependency") }
Expand Down Expand Up @@ -1407,11 +1405,10 @@
end

describe "#preferred_resolvable_version" do
subject { checker.preferred_resolvable_version }
include_context "when stubbing rubygems compact index"
include_context "when stubbing rubygems versions api"

subject { checker.preferred_resolvable_version }

it { is_expected.to eq(Gem::Version.new("1.13.0")) }

context "with a security vulnerability" do
Expand All @@ -1430,11 +1427,10 @@
end

describe "#latest_resolvable_version_with_no_unlock" do
subject { checker.latest_resolvable_version_with_no_unlock }
include_context "when stubbing rubygems compact index"
include_context "when stubbing rubygems versions api"

subject { checker.latest_resolvable_version_with_no_unlock }

context "when given a gem from rubygems" do
it { is_expected.to eq(Gem::Version.new("1.4.0")) }

Expand Down Expand Up @@ -1463,11 +1459,10 @@
end

describe "#updated_requirements" do
subject(:updated_requirements) { checker.updated_requirements }
include_context "when stubbing rubygems compact index"
include_context "when stubbing rubygems versions api"

subject(:updated_requirements) { checker.updated_requirements }

let(:requirements_updater) do
Dependabot::Bundler::UpdateChecker::RequirementsUpdater
end
Expand Down
2 changes: 1 addition & 1 deletion cargo/spec/dependabot/cargo/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@
end

context "with an override (specified as a patch)" do
subject(:top_level_dependencies) { dependencies.select(&:top_level?) }
let(:manifest_fixture_name) { "workspace_root_with_patch" }
let(:lockfile_fixture_name) { "workspace_with_patch" }
subject(:top_level_dependencies) { dependencies.select(&:top_level?) }

it "excludes the patched dependency" do
expect(top_level_dependencies.map(&:name)).to eq(["regex"])
Expand Down
6 changes: 3 additions & 3 deletions cargo/spec/dependabot/cargo/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
require_common_spec "metadata_finders/shared_examples_for_metadata_finders"

RSpec.describe Dependabot::Cargo::MetadataFinder do
subject(:finder) do
described_class.new(dependency: dependency, credentials: credentials)
end
it_behaves_like "a dependency metadata finder"

let(:dependency) do
Expand All @@ -22,9 +25,6 @@
package_manager: "cargo"
)
end
subject(:finder) do
described_class.new(dependency: dependency, credentials: credentials)
end
let(:credentials) do
[{
"type" => "git_source",
Expand Down
Loading

0 comments on commit 58022ce

Please sign in to comment.