Merge pull request #16979 from Homebrew/rspec-cleanup

Enable and fix RSpec/DescribedClassModuleWrapping
This commit is contained in:
Douglas Eichelberger 2024-03-30 18:16:26 -07:00 committed by GitHub
commit 221fde4ad8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 1621 additions and 1632 deletions

View File

@ -230,19 +230,12 @@ RSpec/AnyInstance:
Enabled: false Enabled: false
RSpec/DescribeClass: RSpec/DescribeClass:
Enabled: false Enabled: false
RSpec/FilePath:
Enabled: false
RSpec/SpecFilePathFormat: RSpec/SpecFilePathFormat:
Enabled: false Enabled: false
RSpec/StubbedMock: RSpec/StubbedMock:
Enabled: false Enabled: false
RSpec/SubjectStub: RSpec/SubjectStub:
Enabled: false Enabled: false
# We use `allow(:foo).to receive(:bar)` everywhere.
RSpec/MessageSpies:
EnforcedStyle: receive
# These were ever-growing numbers, not useful. # These were ever-growing numbers, not useful.
RSpec/ExampleLength: RSpec/ExampleLength:
Enabled: false Enabled: false
@ -253,9 +246,16 @@ RSpec/NestedGroups:
RSpec/MultipleMemoizedHelpers: RSpec/MultipleMemoizedHelpers:
Enabled: false Enabled: false
RSpec/DescribedClassModuleWrapping:
Enabled: true
RSpec/FilePath:
SpecSuffixOnly: true
# Annoying to have these autoremoved. # Annoying to have these autoremoved.
RSpec/Focus: RSpec/Focus:
AutoCorrect: false AutoCorrect: false
# We use `allow(:foo).to receive(:bar)` everywhere.
RSpec/MessageSpies:
EnforcedStyle: receive
# Try getting rid of these. # Try getting rid of these.
Sorbet/ConstantsFromStrings: Sorbet/ConstantsFromStrings:

View File

@ -3,6 +3,7 @@
require "deprecate_disable" require "deprecate_disable"
require "formula_text_auditor" require "formula_text_auditor"
require "formula_versions"
require "resource_auditor" require "resource_auditor"
module Homebrew module Homebrew

View File

@ -1,11 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
module Cask RSpec.describe Cask::Download, :cask do
RSpec.describe Download, :cask do
describe "#verify_download_integrity" do describe "#verify_download_integrity" do
subject(:verification) { described_class.new(cask).verify_download_integrity(downloaded_path) } subject(:verification) { described_class.new(cask).verify_download_integrity(downloaded_path) }
let(:cask) { instance_double(Cask, token: "cask", sha256: expected_sha256) } let(:cask) { instance_double(Cask::Cask, token: "cask", sha256: expected_sha256) }
let(:cafebabe) { "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" } let(:cafebabe) { "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" }
let(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" } let(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }
let(:computed_sha256) { cafebabe } let(:computed_sha256) { cafebabe }
@ -55,5 +54,4 @@ module Cask
end end
end end
end end
end
end end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
# frozen_string_literal: true
require "socket"
require "formula_free_port"
module Homebrew
RSpec.describe FreePort do
include described_class
describe "#free_port" do
it "returns a free TCP/IP port" do
# IANA suggests user port from 1024 to 49151
# and dynamic port for 49152 to 65535
# http://www.iana.org/assignments/port-numbers
min_port = 1024
max_port = 65535
port = free_port
expect(port).to be_between(min_port, max_port)
expect { TCPServer.new(port).close }.not_to raise_error
end
end
end
end

View File

@ -0,0 +1,39 @@
# frozen_string_literal: true
require "formula_text_auditor"
RSpec.describe Homebrew::FormulaTextAuditor do
alias_matcher :have_trailing_newline, :be_trailing_newline
let(:dir) { mktmpdir }
def formula_text(name, body = nil)
path = dir/"#{name}.rb"
path.write <<~RUBY
class #{Formulary.class_s(name)} < Formula
#{body}
end
RUBY
described_class.new(path)
end
specify "simple valid Formula" do
ft = formula_text "valid", <<~RUBY
url "https://www.brew.sh/valid-1.0.tar.gz"
RUBY
expect(ft).to have_trailing_newline
expect(ft =~ /\burl\b/).to be_truthy
expect(ft.line_number(/desc/)).to be_nil
expect(ft.line_number(/\burl\b/)).to eq(2)
expect(ft).to include("Valid")
end
specify "#trailing_newline?" do
ft = formula_text "newline"
expect(ft).to have_trailing_newline
end
end

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
require "socket"
require "formula_free_port"
RSpec.describe Homebrew::FreePort do
include described_class
describe "#free_port" do
it "returns a free TCP/IP port" do
# IANA suggests user port from 1024 to 49151
# and dynamic port for 49152 to 65535
# http://www.iana.org/assignments/port-numbers
min_port = 1024
max_port = 65535
port = free_port
expect(port).to be_between(min_port, max_port)
expect { TCPServer.new(port).close }.not_to raise_error
end
end
end

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
require "rubocops/shell_commands"
RSpec.describe RuboCop::Cop::Homebrew::ExecShellMetacharacters do
subject(:cop) { described_class.new }
context "when auditing exec calls" do
it "reports aan offense when output piping is used" do
expect_offense(<<~RUBY)
fork do
exec "foo bar > output"
^^^^^^^^^^^^^^^^^^ Homebrew/ExecShellMetacharacters: Don't use shell metacharacters in `exec`. Implement the logic in Ruby instead, using methods like `$stdout.reopen`.
end
RUBY
end
it "reports no offenses when no metacharacters are used" do
expect_no_offenses(<<~RUBY)
fork do
exec "foo bar"
end
RUBY
end
end
end

View File

@ -2,10 +2,7 @@
require "rubocops/shell_commands" require "rubocops/shell_commands"
module RuboCop RSpec.describe RuboCop::Cop::Homebrew::ShellCommands do
module Cop
module Homebrew
::RSpec.describe ShellCommands do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
context "when auditing shell commands" do context "when auditing shell commands" do
@ -211,30 +208,4 @@ module RuboCop
RUBY RUBY
end end
end end
end
::RSpec.describe ExecShellMetacharacters do
subject(:cop) { described_class.new }
context "when auditing exec calls" do
it "reports aan offense when output piping is used" do
expect_offense(<<~RUBY)
fork do
exec "foo bar > output"
^^^^^^^^^^^^^^^^^^ Homebrew/ExecShellMetacharacters: Don't use shell metacharacters in `exec`. Implement the logic in Ruby instead, using methods like `$stdout.reopen`.
end
RUBY
end
it "reports no offenses when no metacharacters are used" do
expect_no_offenses(<<~RUBY)
fork do
exec "foo bar"
end
RUBY
end
end
end
end
end
end end