Enable and fix RSpec/DescribedClassModuleWrapping

This commit is contained in:
Douglas Eichelberger 2024-03-30 11:18:58 -07:00
parent 02a0ea8449
commit 03b815df82
9 changed files with 1622 additions and 1625 deletions

View File

@ -253,6 +253,8 @@ RSpec/NestedGroups:
RSpec/MultipleMemoizedHelpers: RSpec/MultipleMemoizedHelpers:
Enabled: false Enabled: false
RSpec/DescribedClassModuleWrapping:
Enabled: true
# Annoying to have these autoremoved. # Annoying to have these autoremoved.
RSpec/Focus: RSpec/Focus:
AutoCorrect: false AutoCorrect: false

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,42 @@
# frozen_string_literal: true
require "formula_text_auditor"
RSpec.describe Homebrew::FormulaTextAuditor do
alias_matcher :have_data, :be_data
alias_matcher :have_end, :be_end
alias_matcher :have_trailing_newline, :be_trailing_newline
let(:dir) { mktmpdir }
def formula_text(name, body = nil, options = {})
path = dir/"#{name}.rb"
path.write <<~RUBY
class #{Formulary.class_s(name)} < Formula
#{body}
end
#{options[:patch]}
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