diff --git a/Library/Homebrew/.rubocop-rspec.yml b/Library/Homebrew/.rubocop-rspec.yml deleted file mode 100644 index 0aac8fc3e2..0000000000 --- a/Library/Homebrew/.rubocop-rspec.yml +++ /dev/null @@ -1,6 +0,0 @@ -inherit_from: - - .rubocop.yml - -RSpec/ExpectActual: - Exclude: - - 'test/missing_formula_spec.rb' diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index da003e380b..22d0d1ec49 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -1,5 +1,6 @@ inherit_from: - ../.rubocop.yml + - .rubocop_todo.yml AllCops: Include: diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml new file mode 100644 index 0000000000..ac9e850a82 --- /dev/null +++ b/Library/Homebrew/.rubocop_todo.yml @@ -0,0 +1,141 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2018-09-20 09:03:52 +0100 using RuboCop version 0.59.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/LeadingCommentSpace: + Exclude: + - 'style.rb' + +# Offense count: 27 +RSpec/AnyInstance: + Exclude: + - 'test/cask/cmd/create_spec.rb' + - 'test/cask/cmd/edit_spec.rb' + - 'test/cask/cmd/outdated_spec.rb' + - 'test/cask/cmd/upgrade_spec.rb' + - 'test/caveats_spec.rb' + - 'test/cleanup_spec.rb' + - 'test/download_strategies_spec.rb' + - 'test/formatter_spec.rb' + - 'test/os/linux/dependency_collector_spec.rb' + - 'test/utils/analytics_spec.rb' + - 'test/utils/git_spec.rb' + +# Offense count: 139 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Enabled: false + +# Offense count: 69 +RSpec/DescribeClass: + Enabled: false + +# Offense count: 573 +# Configuration parameters: Max. +RSpec/ExampleLength: + Max: 133 + +# Offense count: 16 +RSpec/ExpectActual: + Exclude: + - 'spec/routing/**/*' + - 'test/missing_formula_spec.rb' + +# Offense count: 21 +RSpec/ExpectInHook: + Exclude: + - 'test/cache_store_spec.rb' + - 'test/cask/audit_spec.rb' + - 'test/cmd/reinstall_spec.rb' + - 'test/download_strategies_spec.rb' + - 'test/linkage_cache_store_spec.rb' + - 'test/migrator_spec.rb' + - 'test/os/mac/java_requirement_spec.rb' + +# Offense count: 32 +# Configuration parameters: CustomTransform, IgnoreMethods. +RSpec/FilePath: + Enabled: false + +# Offense count: 6 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Exclude: + - 'test/download_strategies_spec.rb' + - 'test/support/helper/spec/shared_context/integration_test.rb' + - 'test/utils/git_spec.rb' + - 'test/version_spec.rb' + +# Offense count: 113 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + Enabled: false + +# Offense count: 1 +RSpec/MissingExampleGroupArgument: + Exclude: + - 'test/cask/depends_on_spec.rb' + +# Offense count: 23 +RSpec/MultipleDescribes: + Enabled: false + +# Offense count: 544 +# Configuration parameters: AggregateFailuresByDefault. +RSpec/MultipleExpectations: + Max: 26 + +# Offense count: 929 +RSpec/NamedSubject: + Enabled: false + +# Offense count: 99 +RSpec/NestedGroups: + Max: 5 + +# Offense count: 11 +RSpec/RepeatedDescription: + Exclude: + - 'test/inreplace_spec.rb' + - 'test/migrator_spec.rb' + - 'test/rubocops/dependency_order_cop_spec.rb' + - 'test/rubocops/lines_cop_spec.rb' + - 'test/tab_spec.rb' + +# Offense count: 10 +RSpec/RepeatedExample: + Exclude: + - 'test/compiler_selector_spec.rb' + - 'test/utils/shell_spec.rb' + +# Offense count: 31 +RSpec/SubjectStub: + Exclude: + - 'test/cache_store_spec.rb' + - 'test/cmd/update-report/reporter_spec.rb' + - 'test/download_strategies_spec.rb' + - 'test/formula_installer_spec.rb' + - 'test/java_requirement_spec.rb' + - 'test/language/python_spec.rb' + - 'test/os/mac/java_requirement_spec.rb' + +# Offense count: 64 +# Configuration parameters: IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty, nil, both +Style/EmptyElse: + Exclude: + - 'style.rb' diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 5a050d1cd0..163d43e887 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -11,8 +11,6 @@ #: If `--display-cop-names` is passed, include the RuboCop cop name for each #: violation in the output. #: -#: If `--rspec` is passed, install and use the RuboCop RSpec gem. -#: #: Passing `--only-cops=` will check for violations of only the listed #: RuboCop , while `--except-cops=` will skip checking the listed #: . For either option should be a comma-separated list of cop names. diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index bbfee6cf33..ca95138c05 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -18,10 +18,12 @@ module Homebrew fix = options[:fix] Homebrew.install_gem_setup_path! "rubocop", HOMEBREW_RUBOCOP_VERSION + Homebrew.install_gem! "rubocop-rspec" require "rubocop" require "rubocops" args = %w[ + --require rubocop-rspec --force-exclusion ] if fix @@ -34,11 +36,6 @@ module Homebrew args += ["--extra-details", "--display-cop-names"] end - if ARGV.include?("--rspec") - Homebrew.install_gem! "rubocop-rspec" - args += %w[--require rubocop-rspec] - end - if options[:except_cops] options[:except_cops].map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } cops_to_exclude = options[:except_cops].select do |cop| @@ -65,11 +62,7 @@ module Homebrew File.expand_path(file).start_with? HOMEBREW_LIBRARY_PATH end config_file = if files.nil? || has_non_formula - if ARGV.include?("--rspec") - HOMEBREW_LIBRARY_PATH/".rubocop-rspec.yml" - else - HOMEBREW_LIBRARY_PATH/".rubocop.yml" - end + HOMEBREW_LIBRARY_PATH/".rubocop.yml" else HOMEBREW_LIBRARY/".rubocop_audit.yml" end diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile index b9ef330917..f19f6b1f18 100644 --- a/Library/Homebrew/test/Gemfile +++ b/Library/Homebrew/test/Gemfile @@ -8,6 +8,7 @@ gem "rspec-its", require: false gem "rspec-retry", require: false gem "rspec-wait", require: false gem "rubocop", HOMEBREW_RUBOCOP_VERSION +gem "rubocop-rspec", require: false group :development do gem "ronn", require: false diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index 182be5c13e..ccc48f5a23 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -52,6 +52,8 @@ GEM rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) + rubocop-rspec (1.29.1) + rubocop (>= 0.58.0) ruby-progressbar (1.10.0) simplecov (0.16.1) docile (~> 1.1) @@ -73,6 +75,7 @@ DEPENDENCIES rspec-retry rspec-wait rubocop (= 0.59.1) + rubocop-rspec simplecov BUNDLED WITH diff --git a/Library/Homebrew/test/bottle_filename_spec.rb b/Library/Homebrew/test/bottle_filename_spec.rb index 2bf2294698..06e03e29e7 100644 --- a/Library/Homebrew/test/bottle_filename_spec.rb +++ b/Library/Homebrew/test/bottle_filename_spec.rb @@ -18,6 +18,7 @@ describe Bottle::Filename do context "when rebuild is 1" do let(:rebuild) { 1 } + its(:extname) { is_expected.to eq ".tag.bottle.1.tar.gz" } end end diff --git a/Library/Homebrew/test/cache_store_spec.rb b/Library/Homebrew/test/cache_store_spec.rb index e4363baf11..e2cb9e5d1b 100644 --- a/Library/Homebrew/test/cache_store_spec.rb +++ b/Library/Homebrew/test/cache_store_spec.rb @@ -1,23 +1,23 @@ require "cache_store" describe CacheStoreDatabase do - subject { CacheStoreDatabase.new(:sample) } + subject { described_class.new(:sample) } describe "self.use" do let(:type) { :test } it "creates a new `DatabaseCache` instance" do cache_store = double("cache_store", close_if_open!: nil) - expect(CacheStoreDatabase).to receive(:new).with(type).and_return(cache_store) + expect(described_class).to receive(:new).with(type).and_return(cache_store) expect(cache_store).to receive(:close_if_open!) - CacheStoreDatabase.use(type) { |_db| } + described_class.use(type) { |_db| } end end describe "#set" do let(:db) { double("db", :[]= => nil) } - before(:each) do + before do allow(File).to receive(:write) allow(subject).to receive(:created?).and_return(true) expect(db).to receive(:has_key?).with(:foo).and_return(false) @@ -25,7 +25,7 @@ describe CacheStoreDatabase do end it "sets the value in the `CacheStoreDatabase`" do - expect(db).to_not have_key(:foo) + expect(db).not_to have_key(:foo) subject.set(:foo, "bar") end end @@ -34,7 +34,7 @@ describe CacheStoreDatabase do context "database created" do let(:db) { double("db", :[] => "bar") } - before(:each) do + before do allow(subject).to receive(:created?).and_return(true) expect(db).to receive(:has_key?).with(:foo).and_return(true) allow(subject).to receive(:db).and_return(db) @@ -49,13 +49,13 @@ describe CacheStoreDatabase do context "database not created" do let(:db) { double("db", :[] => nil) } - before(:each) do + before do allow(subject).to receive(:created?).and_return(false) allow(subject).to receive(:db).and_return(db) end it "does not get value in the `CacheStoreDatabase` corresponding to key" do - expect(subject.get(:foo)).to_not be("bar") + expect(subject.get(:foo)).not_to be("bar") end it "does not call `db[]` if `CacheStoreDatabase.created?` is `false`" do @@ -69,7 +69,7 @@ describe CacheStoreDatabase do context "database created" do let(:db) { double("db", :[] => { foo: "bar" }) } - before(:each) do + before do allow(subject).to receive(:created?).and_return(true) allow(subject).to receive(:db).and_return(db) end @@ -83,7 +83,7 @@ describe CacheStoreDatabase do context "database not created" do let(:db) { double("db", delete: nil) } - before(:each) do + before do allow(subject).to receive(:created?).and_return(false) allow(subject).to receive(:db).and_return(db) end @@ -97,22 +97,22 @@ describe CacheStoreDatabase do describe "#close_if_open!" do context "database open" do - before(:each) do + before do subject.instance_variable_set(:@db, instance_double(DBM, close: nil)) end it "does not raise an error when `close` is called on the database" do - expect { subject.close_if_open! }.to_not raise_error(NoMethodError) + expect { subject.close_if_open! }.not_to raise_error(NoMethodError) end end context "database not open" do - before(:each) do + before do subject.instance_variable_set(:@db, nil) end it "does not raise an error when `close` is called on the database" do - expect { subject.close_if_open! }.to_not raise_error(NoMethodError) + expect { subject.close_if_open! }.not_to raise_error(NoMethodError) end end end @@ -120,12 +120,12 @@ describe CacheStoreDatabase do describe "#created?" do let(:cache_path) { Pathname("path/to/homebrew/cache/sample.db") } - before(:each) do + before do allow(subject).to receive(:cache_path).and_return(cache_path) end - context "`cache_path.exist?` returns `true`" do - before(:each) do + context "`File.exist?(cache_path)` returns `true`" do + before do allow(cache_path).to receive(:exist?).and_return(true) end @@ -134,8 +134,8 @@ describe CacheStoreDatabase do end end - context "`cache_path.exist?` returns `false`" do - before(:each) do + context "`File.exist?(cache_path)` returns `false`" do + before do allow(cache_path).to receive(:exist?).and_return(false) end diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index d3c10ea925..9726cbc732 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -112,6 +112,10 @@ describe Cask::Artifact::App, :cask do FileUtils.chmod 0555, target_path end + after do + FileUtils.chmod 0755, target_path + end + it "overwrites the existing app" do expect(command).to receive(:run).with( "/bin/chmod", args: [ @@ -148,10 +152,6 @@ describe Cask::Artifact::App, :cask do contents_path = target_path.join("Contents/Info.plist") expect(contents_path).to exist end - - after do - FileUtils.chmod 0755, target_path - end end end end diff --git a/Library/Homebrew/test/cask/artifact/installer_spec.rb b/Library/Homebrew/test/cask/artifact/installer_spec.rb index 56fa78128f..d2aab5ba5d 100644 --- a/Library/Homebrew/test/cask/artifact/installer_spec.rb +++ b/Library/Homebrew/test/cask/artifact/installer_spec.rb @@ -1,7 +1,9 @@ describe Cask::Artifact::Installer, :cask do + subject(:installer) { described_class.new(cask, **args) } + let(:staged_path) { mktmpdir } let(:cask) { instance_double(Cask::Cask, staged_path: staged_path, config: nil) } - subject(:installer) { described_class.new(cask, **args) } + let(:command) { SystemCommand } let(:args) { {} } @@ -21,7 +23,7 @@ describe Cask::Artifact::Installer, :cask do let(:executable) { staged_path/"executable" } let(:args) { { script: { executable: "executable" } } } - before(:each) do + before do FileUtils.touch executable end diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index 94e104f639..5b0687925d 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -104,7 +104,7 @@ describe Cask::Cask, :cask do allow(cask).to receive(:versions).and_return(installed_versions) allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version)) expect(cask).to receive(:outdated_versions).and_call_original - is_expected.to eq expected_output + expect(subject).to eq expected_output } end end @@ -138,7 +138,7 @@ describe Cask::Cask, :cask do allow(cask).to receive(:versions).and_return(installed_version) allow(cask).to receive(:version).and_return(Cask::DSL::Version.new(tap_version)) expect(cask).to receive(:outdated_versions).and_call_original - is_expected.to eq expected_output + expect(subject).to eq expected_output } end end diff --git a/Library/Homebrew/test/cask/cmd/info_spec.rb b/Library/Homebrew/test/cask/cmd/info_spec.rb index 2440df4b4a..f774fe2c5c 100644 --- a/Library/Homebrew/test/cask/cmd/info_spec.rb +++ b/Library/Homebrew/test/cask/cmd/info_spec.rb @@ -20,7 +20,7 @@ describe Cask::Cmd::Info, :cask do EOS end - it "it prints auto_updates if the Cask has `auto_updates true`" do + it "prints auto_updates if the Cask has `auto_updates true`" do expect { described_class.run("with-auto-updates") }.to output(<<~EOS).to_stdout diff --git a/Library/Homebrew/test/cask/cmd/style_spec.rb b/Library/Homebrew/test/cask/cmd/style_spec.rb index 835dc29f2e..bea603b416 100644 --- a/Library/Homebrew/test/cask/cmd/style_spec.rb +++ b/Library/Homebrew/test/cask/cmd/style_spec.rb @@ -93,7 +93,7 @@ describe Cask::Cmd::Style, :cask do end it { - is_expected.to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask/Casks"), + expect(subject).to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask/Casks"), a_path_ending_with("/third-party/homebrew-tap/Casks")) } end diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index 0b01f63a2e..7ee7bb7e74 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -12,7 +12,7 @@ describe "Satisfy Dependencies and Requirements", :cask do let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-cask-cyclic")) } it { - is_expected.to raise_error( + expect(subject).to raise_error( Cask::CaskCyclicDependencyError, "Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies "\ "on other Casks: with-depends-on-cask-cyclic-helper", diff --git a/Library/Homebrew/test/cask/quarantine_spec.rb b/Library/Homebrew/test/cask/quarantine_spec.rb index f4f937e26d..b56818e228 100644 --- a/Library/Homebrew/test/cask/quarantine_spec.rb +++ b/Library/Homebrew/test/cask/quarantine_spec.rb @@ -130,7 +130,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("local-transmission")), ).to be_installed - expect(Cask::Config.global.appdir.join("Transmission.app")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined end it "does not quarantine Cask fetches" do @@ -138,7 +138,7 @@ describe Cask::Quarantine, :cask do local_transmission = Cask::CaskLoader.load(cask_path("local-transmission")) cached_location = Cask::Download.new(local_transmission).perform - expect(cached_location).to_not be_quarantined + expect(cached_location).not_to be_quarantined end it "does not quarantine Cask audits" do @@ -147,7 +147,7 @@ describe Cask::Quarantine, :cask do local_transmission = Cask::CaskLoader.load(cask_path("local-transmission")) cached_location = Cask::Download.new(local_transmission).perform - expect(cached_location).to_not be_quarantined + expect(cached_location).not_to be_quarantined end it "does not quarantine Cask installs even if the fetch was" do @@ -159,7 +159,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("local-transmission")), ).to be_installed - expect(Cask::Config.global.appdir.join("Transmission.app")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined end it "does not quarantine dmg-based Casks" do @@ -169,7 +169,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("container-dmg")), ).to be_installed - expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined end it "does not quarantine tar-gz-based Casks" do @@ -179,7 +179,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("container-tar-gz")), ).to be_installed - expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined end it "does not quarantine xar-based Casks" do @@ -189,7 +189,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("container-xar")), ).to be_installed - expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined end it "does not quarantine pure bzip2-based Casks" do @@ -199,7 +199,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("container-bzip2")), ).to be_installed - expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined end it "does not quarantine pure gzip-based Casks" do @@ -209,7 +209,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("container-gzip")), ).to be_installed - expect(Cask::Config.global.appdir.join("container")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined end it "does not quarantine the pkg in naked-pkg-based Casks" do @@ -221,7 +221,7 @@ describe Cask::Quarantine, :cask do expect( Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg"), - ).to_not be_quarantined + ).not_to be_quarantined end it "does not quarantine a nested container" do @@ -231,7 +231,7 @@ describe Cask::Quarantine, :cask do Cask::CaskLoader.load(cask_path("nested-app")), ).to be_installed - expect(Cask::Config.global.appdir.join("MyNestedApp.app")).to_not be_quarantined + expect(Cask::Config.global.appdir.join("MyNestedApp.app")).not_to be_quarantined end end end diff --git a/Library/Homebrew/test/cask/verify_spec.rb b/Library/Homebrew/test/cask/verify_spec.rb index b40461a539..e5589c4b51 100644 --- a/Library/Homebrew/test/cask/verify_spec.rb +++ b/Library/Homebrew/test/cask/verify_spec.rb @@ -2,6 +2,7 @@ module Cask describe Verify, :cask do describe "::all" do subject(:verification) { described_class.all(cask, downloaded_path) } + let(:cask) { instance_double(Cask, token: "cask", sha256: expected_sha256) } let(:cafebabe) { "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" } let(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" } diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 4e11c32f64..35eaa19269 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -137,7 +137,7 @@ describe Homebrew::Cleanup do end describe "#cleanup_cask", :cask do - before(:each) do + before do Cask::Cache.path.mkpath end diff --git a/Library/Homebrew/test/cli_parser_spec.rb b/Library/Homebrew/test/cli_parser_spec.rb index 205eb8f154..ba1f8c4ae8 100644 --- a/Library/Homebrew/test/cli_parser_spec.rb +++ b/Library/Homebrew/test/cli_parser_spec.rb @@ -2,11 +2,6 @@ require_relative "../cli_parser" describe Homebrew::CLI::Parser do describe "test switch options" do - before do - allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1") - allow(ENV).to receive(:[]).with("HOMEBREW_VERBOSE") - end - subject(:parser) { described_class.new do switch :verbose, description: "Flag for verbosity" @@ -15,6 +10,11 @@ describe Homebrew::CLI::Parser do end } + before do + allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1") + allow(ENV).to receive(:[]).with("HOMEBREW_VERBOSE") + end + it "parses short option" do parser.parse(["-v"]) expect(Homebrew.args).to be_verbose diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb similarity index 100% rename from Library/Homebrew/test/diagnostic_spec.rb rename to Library/Homebrew/test/diagnostic_checks_spec.rb diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 71385c7f58..f7c1da2970 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -235,7 +235,7 @@ describe CurlDownloadStrategy do context "when URL ends with file" do it { - is_expected.to eq( + expect(subject).to eq( HOMEBREW_CACHE/"downloads/3d1c0ae7da22be9d83fb1eb774df96b7c4da71d3cf07e1cb28555cf9a5e5af70--foo.tar.gz", ) } @@ -245,7 +245,7 @@ describe CurlDownloadStrategy do let(:url) { "https://example.com/foo.tar.gz/from/this/mirror" } it { - is_expected.to eq( + expect(subject).to eq( HOMEBREW_CACHE/"downloads/1ab61269ba52c83994510b1e28dd04167a2f2e8393a35a9c50c1f7d33fd8f619--foo.tar.gz", ) } @@ -253,7 +253,7 @@ describe CurlDownloadStrategy do end describe "#fetch" do - before(:each) do + before do subject.temporary_path.dirname.mkpath FileUtils.touch subject.temporary_path end @@ -337,16 +337,19 @@ describe CurlDownloadStrategy do describe "#cached_location" do context "with a file name trailing the URL path" do let(:url) { "https://example.com/cask.dmg" } + its("cached_location.extname") { is_expected.to eq(".dmg") } end context "with a file name trailing the first query parameter" do let(:url) { "https://example.com/download?file=cask.zip&a=1" } + its("cached_location.extname") { is_expected.to eq(".zip") } end context "with a file name trailing the second query parameter" do let(:url) { "https://example.com/dl?a=1&file=cask.zip&b=2" } + its("cached_location.extname") { is_expected.to eq(".zip") } end @@ -384,7 +387,7 @@ describe CurlPostDownloadStrategy do let(:specs) { {} } describe "#fetch" do - before(:each) do + before do subject.temporary_path.dirname.mkpath FileUtils.touch subject.temporary_path end @@ -426,6 +429,7 @@ end describe ScpDownloadStrategy do subject { described_class.new(url, name, version) } + let(:name) { "foo" } let(:url) { "scp://example.com/foo.tar.gz" } let(:version) { nil } @@ -456,6 +460,7 @@ describe ScpDownloadStrategy do context "when given a valid URL" do let(:url) { "scp://example.com/foo.tar.gz" } + it "copies the file via scp" do expect(subject) .to receive(:system_command!) @@ -468,6 +473,7 @@ describe ScpDownloadStrategy do context "when given a URL with a username" do let(:url) { "scp://user@example.com/foo.tar.gz" } + it "copies the file via scp" do expect(subject) .to receive(:system_command!) @@ -480,6 +486,7 @@ describe ScpDownloadStrategy do context "when given a URL with a port" do let(:url) { "scp://example.com:1234/foo.tar.gz" } + it "copies the file via scp" do expect(subject) .to receive(:system_command!) @@ -492,6 +499,7 @@ describe ScpDownloadStrategy do context "when given a URL with /~/" do let(:url) { "scp://example.com/~/foo.tar.gz" } + it "treats the path as relative to the home directory" do expect(subject) .to receive(:system_command!) @@ -562,7 +570,7 @@ describe DownloadStrategyDetector do it "returns S3DownloadStrategy" do allow(described_class).to receive(:require_aws_sdk).and_return(true) - is_expected.to eq(S3DownloadStrategy) + expect(subject).to eq(S3DownloadStrategy) end end @@ -572,12 +580,13 @@ describe DownloadStrategyDetector do it "requires aws-sdk-s3" do allow(described_class).to receive(:require_aws_sdk).and_return(true) - is_expected.to eq(S3DownloadStrategy) + expect(subject).to eq(S3DownloadStrategy) end end context "when given an scp URL" do let(:url) { "scp://example.com/brew.tar.gz" } + it { is_expected.to eq(ScpDownloadStrategy) } end diff --git a/Library/Homebrew/test/error_during_execution_spec.rb b/Library/Homebrew/test/error_during_execution_spec.rb index 4dd6d1ec3f..bd3b96e6c6 100644 --- a/Library/Homebrew/test/error_during_execution_spec.rb +++ b/Library/Homebrew/test/error_during_execution_spec.rb @@ -1,5 +1,6 @@ describe ErrorDuringExecution do subject(:error) { described_class.new(command, status: status, output: output) } + let(:command) { ["false"] } let(:status) { instance_double(Process::Status, exitstatus: exitstatus) } let(:exitstatus) { 1 } @@ -43,7 +44,7 @@ describe ErrorDuringExecution do end its(:to_s) { - is_expected.to eq <<~EOS + expect(subject.to_s).to eq <<~EOS Failure while executing; `false` exited with 1. Here's the output: This still worked. #{Formatter.error("Here something went wrong.\n")} @@ -55,8 +56,8 @@ describe ErrorDuringExecution do let(:command) { ["env", "PATH=/bin", "cat", "with spaces"] } its(:to_s) { - is_expected - .to eq 'Failure while executing; `env PATH=/bin cat with\ spaces` exited with 1.' + expect(subject.to_s) + .to eq 'Failure while executing; `env PATH=/bin cat with\ spaces` exited with 1.' } end end diff --git a/Library/Homebrew/test/exceptions_spec.rb b/Library/Homebrew/test/exceptions_spec.rb index 590141a79a..934a651d98 100644 --- a/Library/Homebrew/test/exceptions_spec.rb +++ b/Library/Homebrew/test/exceptions_spec.rb @@ -16,7 +16,7 @@ describe FormulaValidationError do subject { described_class.new("foo", "sha257", "magic") } its(:to_s) { - is_expected.to eq(%q(invalid attribute for formula 'foo': sha257 ("magic"))) + expect(subject.to_s).to eq(%q(invalid attribute for formula 'foo': sha257 ("magic"))) } end @@ -49,7 +49,7 @@ describe FormulaUnavailableError do end its(:to_s) { - is_expected.to eq('No available formula with the name "foo" (dependency of foobar)') + expect(subject.to_s).to eq('No available formula with the name "foo" (dependency of foobar)') } end end @@ -76,7 +76,7 @@ describe FormulaClassUnavailableError do let(:list) { [] } its(:to_s) { - is_expected.to match(/Expected to find class Foo, but found no classes\./) + expect(subject.to_s).to match(/Expected to find class Foo, but found no classes\./) } end @@ -84,7 +84,7 @@ describe FormulaClassUnavailableError do let(:list) { [mod.const_get(:Bar)] } its(:to_s) { - is_expected.to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./) + expect(subject.to_s).to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./) } end @@ -184,6 +184,7 @@ end describe ErrorDuringExecution do subject { described_class.new(["badprg", "arg1", "arg2"], status: status) } + let(:status) { instance_double(Process::Status, exitstatus: 17) } its(:to_s) { is_expected.to eq("Failure while executing; `badprg arg1 arg2` exited with 17.") } diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index c7edc0b45e..62c126d444 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -137,7 +137,7 @@ describe Formulary do context "with installed Formula" do before do - allow(Formulary).to receive(:loader_for).and_call_original + allow(described_class).to receive(:loader_for).and_call_original stub_formula_loader formula("patchelf") { url "patchelf-1.0" } allow(Formula["patchelf"]).to receive(:installed?).and_return(true) end diff --git a/Library/Homebrew/test/linkage_cache_store_spec.rb b/Library/Homebrew/test/linkage_cache_store_spec.rb index ade4983b18..23cfbda71c 100644 --- a/Library/Homebrew/test/linkage_cache_store_spec.rb +++ b/Library/Homebrew/test/linkage_cache_store_spec.rb @@ -1,14 +1,14 @@ require "linkage_cache_store" describe LinkageCacheStore do + subject { described_class.new(keg_name, database) } + let(:keg_name) { "keg_name" } let(:database) { double("database") } - subject { LinkageCacheStore.new(keg_name, database) } - describe "#keg_exists?" do context "`keg_name` exists in cache" do - before(:each) do + before do expect(database).to receive(:get).with(keg_name).and_return("") end @@ -18,7 +18,7 @@ describe LinkageCacheStore do end context "`keg_name` does not exist in cache" do - before(:each) do + before do expect(database).to receive(:get).with(keg_name).and_return(nil) end @@ -52,7 +52,7 @@ describe LinkageCacheStore do describe "#fetch_type" do context "`HASH_LINKAGE_TYPES.include?(type)`" do - before(:each) do + before do expect(database).to receive(:get).with(keg_name).and_return(nil) end diff --git a/Library/Homebrew/test/messages_spec.rb b/Library/Homebrew/test/messages_spec.rb index 23d3205ea8..2518e8dd50 100644 --- a/Library/Homebrew/test/messages_spec.rb +++ b/Library/Homebrew/test/messages_spec.rb @@ -2,7 +2,7 @@ require "messages" require "spec_helper" describe Messages do - let(:messages) { Messages.new } + let(:messages) { described_class.new } let(:test_formula) { formula("foo") { url("https://example.com/foo-0.1.tgz") } } let(:elapsed_time) { 1.1 } @@ -18,7 +18,7 @@ describe Messages do it "increases the formula count" do expect { messages.formula_installed(test_formula, elapsed_time) - }.to change { messages.formula_count }.by(1) + }.to change(messages, :formula_count).by(1) end it "adds to install_times" do diff --git a/Library/Homebrew/test/os/mac_spec.rb b/Library/Homebrew/test/os/mac_spec.rb index d747297492..97f15dd610 100644 --- a/Library/Homebrew/test/os/mac_spec.rb +++ b/Library/Homebrew/test/os/mac_spec.rb @@ -24,24 +24,24 @@ describe OS::Mac do it "calls sdk_path on Xcode-only systems" do allow(OS::Mac::Xcode).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(false) - expect(OS::Mac).to receive(:sdk_path) - OS::Mac.sdk_path_if_needed + expect(described_class).to receive(:sdk_path) + described_class.sdk_path_if_needed end it "does not call sdk_path on Xcode-and-CLT systems with system headers" do allow(OS::Mac::Xcode).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(false) - expect(OS::Mac).not_to receive(:sdk_path) - OS::Mac.sdk_path_if_needed + expect(described_class).not_to receive(:sdk_path) + described_class.sdk_path_if_needed end it "does not call sdk_path on CLT-only systems with no CLT SDK" do allow(OS::Mac::Xcode).to receive(:installed?).and_return(false) allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(false) - expect(OS::Mac).not_to receive(:sdk_path) - OS::Mac.sdk_path_if_needed + expect(described_class).not_to receive(:sdk_path) + described_class.sdk_path_if_needed end it "does not call sdk_path on CLT-only systems with a CLT SDK if the system provides headers" do @@ -49,8 +49,8 @@ describe OS::Mac do allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(true) allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(false) - expect(OS::Mac).not_to receive(:sdk_path) - OS::Mac.sdk_path_if_needed + expect(described_class).not_to receive(:sdk_path) + described_class.sdk_path_if_needed end it "calls sdk_path on CLT-only systems with a CLT SDK if the system does not provide headers" do @@ -58,8 +58,8 @@ describe OS::Mac do allow(OS::Mac::CLT).to receive(:installed?).and_return(true) allow(OS::Mac::CLT).to receive(:provides_sdk?).and_return(true) allow(OS::Mac::CLT).to receive(:separate_header_package?).and_return(true) - expect(OS::Mac).to receive(:sdk_path) - OS::Mac.sdk_path_if_needed + expect(described_class).to receive(:sdk_path) + described_class.sdk_path_if_needed end end end diff --git a/Library/Homebrew/test/system_command_result_spec.rb b/Library/Homebrew/test/system_command_result_spec.rb index 0a24083270..9d48d34258 100644 --- a/Library/Homebrew/test/system_command_result_spec.rb +++ b/Library/Homebrew/test/system_command_result_spec.rb @@ -1,15 +1,16 @@ require "system_command" describe SystemCommand::Result do + subject(:result) { + described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true)) + } + let(:output_array) { [ [:stdout, "output\n"], [:stderr, "error\n"], ] } - subject(:result) { - described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true)) - } describe "#to_ary" do it "can be destructed like `Open3.capture3`" do @@ -41,6 +42,7 @@ describe SystemCommand::Result do describe "#plist" do subject { result.plist } + let(:output_array) { [[:stdout, stdout]] } let(:garbage) { <<~EOS @@ -114,7 +116,7 @@ describe SystemCommand::Result do end context "when verbose" do - before(:each) do + before do allow(ARGV).to receive(:verbose?).and_return(true) end @@ -138,7 +140,7 @@ describe SystemCommand::Result do end context "when verbose" do - before(:each) do + before do allow(ARGV).to receive(:verbose?).and_return(true) end diff --git a/Library/Homebrew/test/system_command_spec.rb b/Library/Homebrew/test/system_command_spec.rb index f77b992795..afa0bd7e55 100644 --- a/Library/Homebrew/test/system_command_spec.rb +++ b/Library/Homebrew/test/system_command_spec.rb @@ -1,9 +1,5 @@ describe SystemCommand do describe "#initialize" do - let(:env_args) { ["bash", "-c", 'printf "%s" "${A?}" "${B?}" "${C?}"'] } - let(:env) { { "A" => "1", "B" => "2", "C" => "3" } } - let(:sudo) { false } - subject(:command) { described_class.new( "env", @@ -14,6 +10,10 @@ describe SystemCommand do ) } + let(:env_args) { ["bash", "-c", 'printf "%s" "${A?}" "${B?}" "${C?}"'] } + let(:env) { { "A" => "1", "B" => "2", "C" => "3" } } + let(:sudo) { false } + context "when given some environment variables" do its("run!.stdout") { is_expected.to eq("123") } @@ -237,7 +237,7 @@ describe SystemCommand do context "when given an executable with spaces and no arguments" do let(:executable) { mktmpdir/"App Uninstaller" } - before(:each) do + before do executable.write <<~SH #!/usr/bin/env bash true diff --git a/Library/Homebrew/test/unpack_strategy/directory_spec.rb b/Library/Homebrew/test/unpack_strategy/directory_spec.rb index 0b0ba803c4..f7ceedd679 100644 --- a/Library/Homebrew/test/unpack_strategy/directory_spec.rb +++ b/Library/Homebrew/test/unpack_strategy/directory_spec.rb @@ -1,13 +1,15 @@ require_relative "shared_examples" describe UnpackStrategy::Directory do + subject(:strategy) { described_class.new(path) } + let(:path) { mktmpdir.tap do |path| FileUtils.touch path/"file" FileUtils.ln_s "file", path/"symlink" end } - subject(:strategy) { described_class.new(path) } + let(:unpack_dir) { mktmpdir } it "does not follow symlinks" do diff --git a/Library/Homebrew/test/unpack_strategy/subversion_spec.rb b/Library/Homebrew/test/unpack_strategy/subversion_spec.rb index 4985bcdaf8..cec416a324 100644 --- a/Library/Homebrew/test/unpack_strategy/subversion_spec.rb +++ b/Library/Homebrew/test/unpack_strategy/subversion_spec.rb @@ -5,7 +5,7 @@ describe UnpackStrategy::Subversion, :needs_svn do let(:working_copy) { mktmpdir } let(:path) { working_copy } - before(:each) do + before do system "svnadmin", "create", repo system "svn", "checkout", "file://#{repo}", working_copy diff --git a/Library/Homebrew/test/update_migrator_spec.rb b/Library/Homebrew/test/update_migrator_spec.rb index 211932fd6b..9a742a4894 100644 --- a/Library/Homebrew/test/update_migrator_spec.rb +++ b/Library/Homebrew/test/update_migrator_spec.rb @@ -12,7 +12,7 @@ describe UpdateMigrator do let(:old_cache_file) { HOMEBREW_CACHE/"#{formula_name}-1.2.3.tar.gz" } let(:new_cache_file) { HOMEBREW_CACHE/"#{formula_name}--1.2.3.tar.gz" } - before(:each) do + before do FileUtils.touch old_cache_file allow(Formula).to receive(:each).and_yield(f) end @@ -58,7 +58,7 @@ describe UpdateMigrator do HOMEBREW_CACHE/"downloads/5994e3a27baa3f448a001fb071ab1f0bf25c87aebcb254d91a6d0b02f46eef86--foo-1.2.3.tar.gz" } - before(:each) do + before do old_cache_file.dirname.mkpath FileUtils.touch old_cache_file allow(Formula).to receive(:[]).and_return(f) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 5326c82173..3ec68224b4 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -10,7 +10,7 @@ describe Utils::Analytics do it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do stub_const("HOMEBREW_PREFIX", "blah") - expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, #{Utils::Analytics.custom_prefix_label}") + expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, #{described_class.custom_prefix_label}") end it "includes CI when ENV['CI'] is set" do @@ -20,7 +20,7 @@ describe Utils::Analytics do it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do stub_const("HOMEBREW_PREFIX", Homebrew::DEFAULT_PREFIX) - expect(described_class.os_prefix_ci).not_to include(Utils::Analytics.custom_prefix_label) + expect(described_class.os_prefix_ci).not_to include(described_class.custom_prefix_label) end end end diff --git a/Library/Homebrew/test/utils/curl_spec.rb b/Library/Homebrew/test/utils/curl_spec.rb index 33d01a7f62..3f143c638d 100644 --- a/Library/Homebrew/test/utils/curl_spec.rb +++ b/Library/Homebrew/test/utils/curl_spec.rb @@ -9,7 +9,7 @@ describe "curl" do it "doesn't return -q as the first argument when HOMEBREW_CURLRC is set" do ENV["HOMEBREW_CURLRC"] = "1" - expect(curl_args("foo").first).to_not eq("-q") + expect(curl_args("foo").first).not_to eq("-q") end end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 8491b4f994..a1e5a0af6a 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -464,8 +464,6 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--display-cop-names` is passed, include the RuboCop cop name for each violation in the output. - If `--rspec` is passed, install and use the RuboCop RSpec gem. - Passing `--only-cops=``cops` will check for violations of only the listed RuboCop `cops`, while `--except-cops=``cops` will skip checking the listed `cops`. For either option `cops` should be a comma-separated list of cop names. diff --git a/manpages/brew.1 b/manpages/brew.1 index 4bdb289350..62a643b192 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -425,9 +425,6 @@ If \fB\-\-fix\fR is passed, automatically fix style violations using RuboCop\'s If \fB\-\-display\-cop\-names\fR is passed, include the RuboCop cop name for each violation in the output\. . .IP -If \fB\-\-rspec\fR is passed, install and use the RuboCop RSpec gem\. -. -.IP Passing \fB\-\-only\-cops=\fR\fIcops\fR will check for violations of only the listed RuboCop \fIcops\fR, while \fB\-\-except\-cops=\fR\fIcops\fR will skip checking the listed \fIcops\fR\. For either option \fIcops\fR should be a comma\-separated list of cop names\. . .IP