Skip to content

Commit

Permalink
Enabling RSpec/BeforeAfterAll Rubocop rule (#10043)
Browse files Browse the repository at this point in the history
  • Loading branch information
GarryHurleyJr committed Jun 24, 2024
1 parent 2b8bb15 commit 32e07d1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 53 deletions.
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ RSpec/AnyInstance:
- 'updater/spec/dependabot/dependency_change_builder_spec.rb'
- 'updater/spec/dependabot/file_fetcher_command_spec.rb'

# Offense count: 7
RSpec/BeforeAfterAll:
Exclude:
- 'nuget/spec/dependabot/nuget/update_checker/dependency_finder_spec.rb'
- 'pub/spec/dependabot/pub/file_updater_spec.rb'
- 'pub/spec/dependabot/pub/infer_sdk_versions_spec.rb'
- 'pub/spec/dependabot/pub/update_checker_spec.rb'

# Offense count: 1286
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,7 @@
let(:nuget_config) { Dependabot::DependencyFile.new(name: "NuGet.Config", content: nuget_config_body) }
let(:dependency_files) { [csproj, nuget_config] }

def create_nupkg(nuspec_name, nuspec_fixture_path)
content = Zip::OutputStream.write_buffer do |zio|
zio.put_next_entry("#{nuspec_name}.nuspec")
zio.write(fixture("nuspecs", nuspec_fixture_path))
end
content.rewind
content.sysread
end

before(:context) do
before do
disallowed_urls = %w(
https://api.nuget.org/v3/index.json
https://api.nuget.org/v3-flatcontainer/microsoft.extensions.dependencymodel/42.42.42/microsoft.extensions.dependencymodel.nuspec
Expand All @@ -93,6 +84,15 @@ def create_nupkg(nuspec_name, nuspec_fixture_path)
"Microsoft.NETCore.Platforms_43.43.43_faked.nuspec"))
end

def create_nupkg(nuspec_name, nuspec_fixture_path)
content = Zip::OutputStream.write_buffer do |zio|
zio.put_next_entry("#{nuspec_name}.nuspec")
zio.write(fixture("nuspecs", nuspec_fixture_path))
end
content.rewind
content.sysread
end

# this test doesn't really care about the dependency count, we just need to ensure that `api.nuget.org` wasn't hit
its(:length) do
is_expected.to eq(1)
Expand Down
20 changes: 7 additions & 13 deletions pub/spec/dependabot/pub/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,23 @@
package = File.basename(f, ".json")
@server.unmount "/api/packages/#{package}"
end
end

before do
sample_files.each do |f|
package = File.basename(f, ".json")
@server.mount_proc "/api/packages/#{package}" do |_req, res|
res.body = File.read(File.join("..", "..", "..", f))
end
end
end

after(:all) do
@server.shutdown
end

before(:all) do
before do
# Because we do the networking in dependency_services we have to run an
# actual web server.
dev_null = WEBrick::Log.new("/dev/null", 7)
@server = WEBrick::HTTPServer.new({ Port: 0, AccessLog: [], Logger: dev_null })
Thread.new do
@server.start
end
sample_files.each do |f|
package = File.basename(f, ".json")
@server.mount_proc "/api/packages/#{package}" do |_req, res|
res.body = File.read(File.join("..", "..", "..", f))
end
end
end

it_behaves_like "a dependency file updater"
Expand Down
13 changes: 5 additions & 8 deletions pub/spec/dependabot/pub/infer_sdk_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@
require "webrick"

RSpec.describe "Helpers" do
before(:all) do
before do
# Because we do the networking in infer_sdk_versions we have to run an
# actual web server.
dev_null = WEBrick::Log.new("/dev/null", 7)
@server = WEBrick::HTTPServer.new({ Port: 0, AccessLog: [], Logger: dev_null })
Thread.new do
@server.start
end
end

after(:all) do
@server.shutdown
end

before do
@server.mount_proc "/flutter_releases.json" do |_req, res|
res.body = File.read(File.join(__dir__, "..", "..", "fixtures", "flutter_releases.json"))
end
end

after do
@server.shutdown
end

let(:inferred_result) do
Dependabot::Pub::Helpers.run_infer_sdk_versions \
File.join("spec", "fixtures", "projects", project), url: "http://localhost:#{@server[:Port]}/flutter_releases.json"
Expand Down
22 changes: 8 additions & 14 deletions pub/spec/dependabot/pub/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@
package = File.basename(f, ".json")
@server.unmount "/api/packages/#{package}"
end
@server.shutdown
end

before do
# Because we do the networking in dependency_services we have to run an
# actual web server.
dev_null = WEBrick::Log.new("/dev/null", 7)
@server = WEBrick::HTTPServer.new({ Port: 0, AccessLog: [], Logger: dev_null })
Thread.new do
@server.start
end
sample_files.each do |f|
package = File.basename(f, ".json")
@server.mount_proc "/api/packages/#{package}" do |_req, res|
Expand All @@ -88,20 +96,6 @@
end
end

after(:all) do
@server.shutdown
end

before(:all) do
# Because we do the networking in dependency_services we have to run an
# actual web server.
dev_null = WEBrick::Log.new("/dev/null", 7)
@server = WEBrick::HTTPServer.new({ Port: 0, AccessLog: [], Logger: dev_null })
Thread.new do
@server.start
end
end

it_behaves_like "an update checker"

context "when given an outdated dependency, not requiring unlock" do
Expand Down

0 comments on commit 32e07d1

Please sign in to comment.