Skip to content

Commit

Permalink
Enabling RSpec HooksBefore rubocop rule (#9974)
Browse files Browse the repository at this point in the history
* Enabling RSpec HooksBefore rubocop rule

* Fixing lint issues due to misapplied rubocop rules
  • Loading branch information
GarryHurleyJr committed Jun 13, 2024
1 parent 6620402 commit 7f1217e
Show file tree
Hide file tree
Showing 44 changed files with 138 additions and 139 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +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: 56
# This cop supports safe autocorrection (--autocorrect).
RSpec/HooksBeforeExamples:
Enabled: false


# Offense count: 70
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
RSpec/IndexedLet:
Expand Down
5 changes: 3 additions & 2 deletions bundler/spec/dependabot/bundler/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
)
end

it_behaves_like "a dependency file fetcher"

before do
allow(file_fetcher_instance).to receive(:commit).and_return("sha")
stub_request(:get, File.join(url, ".ruby-version?ref=sha"))
Expand All @@ -47,8 +45,11 @@
body: fixture("github", "tool_versions_content.json"),
headers: { "content-type" => "application/json" }
)
allow(file_fetcher_instance).to receive(:commit).and_return("sha")
end

it_behaves_like "a dependency file fetcher"

context "with a directory" do
let(:directory) { "/test" }
let(:url) { "https://api.github.com/repos/gocardless/bump/contents/test" }
Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/dependabot/bundler/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
)
end

it_behaves_like "a dependency file updater"

before { FileUtils.mkdir_p(tmp_path) }

it_behaves_like "a dependency file updater"

describe "#updated_dependency_files" do
subject(:updated_files) { updater.updated_dependency_files }

Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/dependabot/bundler/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
)
end

it_behaves_like "a dependency metadata finder"

before do
stub_request(:get, "https://example.com/status").to_return(
status: 200,
Expand All @@ -50,6 +48,8 @@
)
end

it_behaves_like "a dependency metadata finder"

describe "#source_url" do
subject(:source_url) { finder.source_url }

Expand Down
5 changes: 3 additions & 2 deletions cargo/spec/dependabot/cargo/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
)
end

it_behaves_like "a dependency file fetcher"

before do
allow(file_fetcher_instance).to receive(:commit).and_return("sha")
stub_request(:get, url + "Cargo.toml?ref=sha")
Expand Down Expand Up @@ -62,8 +60,11 @@
body: fixture("github", "contents_cargo_config.json"),
headers: json_header
)
allow(file_fetcher_instance).to receive(:commit).and_return("sha")
end

it_behaves_like "a dependency file fetcher"

context "with a lockfile" do
before do
stub_request(:get, url + "?ref=sha")
Expand Down
4 changes: 2 additions & 2 deletions cargo/spec/dependabot/cargo/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
)
end

it_behaves_like "a dependency file updater"

before { FileUtils.mkdir_p(tmp_path) }

it_behaves_like "a dependency file updater"

describe "#updated_dependency_files" do
subject(:updated_files) { updater.updated_dependency_files }

Expand Down
4 changes: 2 additions & 2 deletions cargo/spec/dependabot/cargo/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
)
end

it_behaves_like "a dependency metadata finder"

before do
stub_request(:get, "https://example.com/status").to_return(
status: 200,
Expand All @@ -45,6 +43,8 @@
)
end

it_behaves_like "a dependency metadata finder"

describe "#source_url" do
subject(:source_url) { finder.source_url }

Expand Down
4 changes: 2 additions & 2 deletions cargo/spec/dependabot/cargo/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
let(:crates_response) { fixture("crates_io_responses", crates_fixture_name) }
let(:crates_url) { "https://crates.io/api/v1/crates/#{dependency_name}" }

it_behaves_like "an update checker"

before do
stub_request(:get, crates_url).to_return(status: 200, body: crates_response)
end

it_behaves_like "an update checker"

describe "#can_update?" do
subject { checker.can_update?(requirements_to_unlock: :own) }

Expand Down
4 changes: 2 additions & 2 deletions common/spec/dependabot/file_fetchers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ def fetch_files
context "with a GitHub source" do
let(:url) { "https://api.github.com/repos/#{repo}/contents/" }

its(:length) { is_expected.to eq(1) }

before do
stub_request(:get, url + "requirements.txt?ref=sha")
.with(headers: { "Authorization" => "token token" })
Expand All @@ -317,6 +315,8 @@ def fetch_files
headers: { "content-type" => "application/json" })
end

its(:length) { is_expected.to eq(1) }

describe "the file" do
subject(:files_find) { files.find { |file| file.name == "requirements.txt" } }

Expand Down
4 changes: 2 additions & 2 deletions composer/spec/dependabot/composer/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
)
end

it_behaves_like "a dependency file fetcher"

before do
allow(file_fetcher_instance).to receive(:commit).and_return("sha")

Expand All @@ -55,6 +53,8 @@
)
end

it_behaves_like "a dependency file fetcher"

it "fetches the composer.json and composer.lock" do
expect(file_fetcher_instance.files.map(&:name))
.to match_array(%w(composer.json composer.lock))
Expand Down
4 changes: 2 additions & 2 deletions composer/spec/dependabot/composer/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
)
end

it_behaves_like "a dependency file updater"

before { FileUtils.mkdir_p(tmp_path) }

it_behaves_like "a dependency file updater"

describe "#updated_dependency_files" do
subject(:updated_files) { updater.updated_dependency_files }

Expand Down
4 changes: 2 additions & 2 deletions composer/spec/dependabot/composer/metadata_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
)
end

it_behaves_like "a dependency metadata finder"

before do
packagist_url = "https://repo.packagist.org/p2/#{dependency_name.downcase}.json"
stub_request(:get, packagist_url).to_return(status: 200, body: packagist_response)
Expand All @@ -51,6 +49,8 @@
)
end

it_behaves_like "a dependency metadata finder"

describe "#source_url" do
subject(:source_url) { finder.source_url }

Expand Down
4 changes: 2 additions & 2 deletions composer/spec/dependabot/composer/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
)
end

it_behaves_like "an update checker"

before do
url = "https://repo.packagist.org/p2/#{dependency_name.downcase}.json"
stub_request(:get, url).to_return(status: 200, body: packagist_response)
end

it_behaves_like "an update checker"

describe "#latest_version" do
subject(:latest_version) { checker.latest_version }

Expand Down
4 changes: 2 additions & 2 deletions docker/spec/dependabot/docker/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
)
end

it_behaves_like "a dependency file fetcher"

before { allow(file_fetcher_instance).to receive(:commit).and_return("sha") }

it_behaves_like "a dependency file fetcher"

context "with no Dockerfile or Kubernetes YAML file" do
before do
stub_request(:get, url + "?ref=sha")
Expand Down
4 changes: 2 additions & 2 deletions docker/spec/dependabot/docker/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
)
end

it_behaves_like "an update checker"

before do
auth_url = "https://auth.docker.io/token?service=registry.docker.io"
stub_request(:get, auth_url)
Expand All @@ -60,6 +58,8 @@
.and_return(status: 200, body: registry_tags)
end

it_behaves_like "an update checker"

def stub_tag_with_no_digest(tag)
stub_request(:head, repo_url + "manifests/#{tag}")
.and_return(status: 200, headers: JSON.parse(headers_response).except("docker_content_digest"))
Expand Down
5 changes: 3 additions & 2 deletions elm/spec/dependabot/elm/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
)
end

it_behaves_like "a dependency file fetcher"

before do
allow(file_fetcher_instance).to receive(:commit).and_return("sha")
stub_request(:get, url + "?ref=sha")
Expand All @@ -45,8 +43,11 @@
body: fixture("github", "contents_elm_package.json"),
headers: json_header
)
allow(file_fetcher_instance).to receive(:commit).and_return("sha")
end

it_behaves_like "a dependency file fetcher"

context "with an elm.json" do
before do
stub_request(:get, url + "?ref=sha")
Expand Down
4 changes: 2 additions & 2 deletions elm/spec/dependabot/elm/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
)
end

it_behaves_like "a dependency file updater"

before { FileUtils.mkdir_p(tmp_path) }

it_behaves_like "a dependency file updater"

describe "#updated_dependency_files" do
subject(:updated_files) { updater.updated_dependency_files }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
)
end

it_behaves_like "a dependency metadata finder"

before do
# Not hosted on GitHub Enterprise Server
stub_request(:get, "https://example.com/status").to_return(
Expand All @@ -53,6 +51,8 @@
)
end

it_behaves_like "a dependency metadata finder"

describe "#source_url" do
subject(:source_url) { finder.source_url }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
)
end

it_behaves_like "a dependency file fetcher"

before { allow(file_fetcher_instance).to receive(:commit).and_return("sha") }

it_behaves_like "a dependency file fetcher"

context "with workflow files" do
before do
stub_request(:get, url + "?ref=sha")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ def mock_service_pack_request(nwo)
}]
end

its(:length) { is_expected.to eq(4) }

before do
mock_service_pack_request("docker/setup-qemu-action")
mock_service_pack_request("docker/setup-buildx-action")
mock_service_pack_request("docker/login-action")
end

its(:length) { is_expected.to eq(4) }

context "when dealing with the first dependency" do
subject(:dependency) { dependencies.first }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
)
end

it_behaves_like "an update checker"

before do
stub_request(:get, service_pack_url)
.to_return(
Expand All @@ -77,6 +75,8 @@
)
end

it_behaves_like "an update checker"

shared_context "with multiple git sources" do
let(:upload_pack_fixture) { "checkout" }
let(:dependency_name) { "actions/checkout" }
Expand Down
4 changes: 2 additions & 2 deletions go_modules/spec/dependabot/go_modules/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
let(:branch) { "master" }
let(:repo) { "dependabot-fixtures/go-modules-lib" }

it_behaves_like "a dependency file fetcher"

after do
FileUtils.rm_rf(repo_contents_path)
end

it_behaves_like "a dependency file fetcher"

it "fetches the go.mod and go.sum" do
expect(file_fetcher_instance.files.map(&:name))
.to include("go.mod", "go.sum")
Expand Down
4 changes: 2 additions & 2 deletions go_modules/spec/dependabot/go_modules/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
let(:files) { [go_mod] }
let(:parser) { described_class.new(dependency_files: files, source: source, repo_contents_path: repo_contents_path) }

it_behaves_like "a dependency file parser"

after do
# Reset to the default go toolchain after each test
ENV["GOTOOLCHAIN"] = ENV.fetch("GO_LEGACY")
end

it_behaves_like "a dependency file parser"

it "requires a go.mod to be present" do
expect do
described_class.new(dependency_files: [], source: source)
Expand Down
4 changes: 2 additions & 2 deletions gradle/spec/dependabot/gradle/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
)
end

before { allow(file_fetcher_instance).to receive(:commit).and_return("sha") }

it_behaves_like "a dependency file fetcher"

def stub_content_request(path, fixture)
Expand All @@ -46,8 +48,6 @@ def stub_no_content_request(path)
.to_return(status: 404)
end

before { allow(file_fetcher_instance).to receive(:commit).and_return("sha") }

context "with a basic buildfile" do
before do
stub_no_content_request("gradle?ref=sha")
Expand Down
Loading

0 comments on commit 7f1217e

Please sign in to comment.