Enable and fix RSpec/DescribedClassModuleWrapping
This commit is contained in:
parent
02a0ea8449
commit
03b815df82
@ -253,6 +253,8 @@ RSpec/NestedGroups:
|
||||
RSpec/MultipleMemoizedHelpers:
|
||||
Enabled: false
|
||||
|
||||
RSpec/DescribedClassModuleWrapping:
|
||||
Enabled: true
|
||||
# Annoying to have these autoremoved.
|
||||
RSpec/Focus:
|
||||
AutoCorrect: false
|
||||
|
@ -1,11 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Cask
|
||||
RSpec.describe Download, :cask do
|
||||
RSpec.describe Cask::Download, :cask do
|
||||
describe "#verify_download_integrity" do
|
||||
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(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }
|
||||
let(:computed_sha256) { cafebabe }
|
||||
@ -55,5 +54,4 @@ module Cask
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
1295
Library/Homebrew/test/formula_auditor_spec.rb
Normal file
1295
Library/Homebrew/test/formula_auditor_spec.rb
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
|
42
Library/Homebrew/test/formula_text_auditor_spec.rb
Normal file
42
Library/Homebrew/test/formula_text_auditor_spec.rb
Normal 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
|
22
Library/Homebrew/test/free_port_spec.rb
Normal file
22
Library/Homebrew/test/free_port_spec.rb
Normal 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
|
@ -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
|
@ -2,10 +2,7 @@
|
||||
|
||||
require "rubocops/shell_commands"
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Homebrew
|
||||
::RSpec.describe ShellCommands do
|
||||
RSpec.describe RuboCop::Cop::Homebrew::ShellCommands do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "when auditing shell commands" do
|
||||
@ -211,30 +208,4 @@ module RuboCop
|
||||
RUBY
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user