From 77c9c1ddf01bbb6384c1e51b63b691be1f3474ff Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 13 Apr 2018 14:55:28 +0200 Subject: [PATCH 01/10] Use `described_class` in `Formulary` spec. --- Library/Homebrew/test/formulary_spec.rb | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 87124c60ce..5c41f630d3 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -7,7 +7,7 @@ describe Formulary do let(:formula_path) { CoreTap.new.formula_dir/"#{formula_name}.rb" } let(:formula_content) do <<~EOS - class #{subject.class_s(formula_name)} < Formula + class #{described_class.class_s(formula_name)} < Formula url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" sha256 TESTBALL_SHA256 @@ -29,18 +29,18 @@ describe Formulary do describe "::class_s" do it "replaces '+' with 'x'" do - expect(subject.class_s("foo++")).to eq("Fooxx") + expect(described_class.class_s("foo++")).to eq("Fooxx") end it "converts a string to PascalCase" do - expect(subject.class_s("shell.fm")).to eq("ShellFm") - expect(subject.class_s("s-lang")).to eq("SLang") - expect(subject.class_s("pkg-config")).to eq("PkgConfig") - expect(subject.class_s("foo_bar")).to eq("FooBar") + expect(described_class.class_s("shell.fm")).to eq("ShellFm") + expect(described_class.class_s("s-lang")).to eq("SLang") + expect(described_class.class_s("pkg-config")).to eq("PkgConfig") + expect(described_class.class_s("foo_bar")).to eq("FooBar") end it "replaces '@' with 'AT'" do - expect(subject.class_s("openssl@1.1")).to eq("OpensslAT11") + expect(described_class.class_s("openssl@1.1")).to eq("OpensslAT11") end end @@ -50,16 +50,16 @@ describe Formulary do end it "returns a Formula" do - expect(subject.factory(formula_name)).to be_kind_of(Formula) + expect(described_class.factory(formula_name)).to be_kind_of(Formula) end it "returns a Formula when given a fully qualified name" do - expect(subject.factory("homebrew/core/#{formula_name}")).to be_kind_of(Formula) + expect(described_class.factory("homebrew/core/#{formula_name}")).to be_kind_of(Formula) end it "raises an error if the Formula cannot be found" do expect { - subject.factory("not_existed_formula") + described_class.factory("not_existed_formula") }.to raise_error(FormulaUnavailableError) end @@ -67,29 +67,29 @@ describe Formulary do let(:formula_name) { "giraffe" } let(:formula_content) do <<~EOS - class Wrong#{subject.class_s(formula_name)} < Formula + class Wrong#{described_class.class_s(formula_name)} < Formula end EOS end it "raises an error" do expect { - subject.factory(formula_name) + described_class.factory(formula_name) }.to raise_error(FormulaClassUnavailableError) end end it "returns a Formula when given a path" do - expect(subject.factory(formula_path)).to be_kind_of(Formula) + expect(described_class.factory(formula_path)).to be_kind_of(Formula) end it "returns a Formula when given a URL" do - formula = subject.factory("file://#{formula_path}") + formula = described_class.factory("file://#{formula_path}") expect(formula).to be_kind_of(Formula) end it "returns a Formula when given a bottle" do - formula = subject.factory(bottle) + formula = described_class.factory(bottle) expect(formula).to be_kind_of(Formula) expect(formula.local_bottle_path).to eq(bottle.realpath) end @@ -99,19 +99,19 @@ describe Formulary do alias_dir.mkpath alias_path = alias_dir/"foo" FileUtils.ln_s formula_path, alias_path - result = subject.factory("foo") + result = described_class.factory("foo") expect(result).to be_kind_of(Formula) expect(result.alias_path).to eq(alias_path.to_s) end context "with installed Formula" do - let(:formula) { subject.factory(formula_path) } + let(:formula) { described_class.factory(formula_path) } let(:installer) { FormulaInstaller.new(formula) } it "returns a Formula when given a rack" do installer.install - f = subject.from_rack(formula.rack) + f = described_class.from_rack(formula.rack) expect(f).to be_kind_of(Formula) expect(f.build).to be_kind_of(Tab) end @@ -120,7 +120,7 @@ describe Formulary do installer.install keg = Keg.new(formula.prefix) - f = subject.from_keg(keg) + f = described_class.from_keg(keg) expect(f).to be_kind_of(Formula) expect(f.build).to be_kind_of(Tab) end @@ -131,24 +131,24 @@ describe Formulary do let(:formula_path) { tap.path/"#{formula_name}.rb" } it "returns a Formula when given a name" do - expect(subject.factory(formula_name)).to be_kind_of(Formula) + expect(described_class.factory(formula_name)).to be_kind_of(Formula) end it "returns a Formula from an Alias path" do alias_dir = tap.path/"Aliases" alias_dir.mkpath FileUtils.ln_s formula_path, alias_dir/"bar" - expect(subject.factory("bar")).to be_kind_of(Formula) + expect(described_class.factory("bar")).to be_kind_of(Formula) end it "raises an error when the Formula cannot be found" do expect { - subject.factory("#{tap}/not_existed_formula") + described_class.factory("#{tap}/not_existed_formula") }.to raise_error(TapFormulaUnavailableError) end it "returns a Formula when given a fully qualified name" do - expect(subject.factory("#{tap}/#{formula_name}")).to be_kind_of(Formula) + expect(described_class.factory("#{tap}/#{formula_name}")).to be_kind_of(Formula) end it "raises an error if a Formula is in multiple Taps" do @@ -156,7 +156,7 @@ describe Formulary do another_tap = Tap.new("homebrew", "bar") (another_tap.path/"#{formula_name}.rb").write formula_content expect { - subject.factory(formula_name) + described_class.factory(formula_name) }.to raise_error(TapFormulaAmbiguityError) ensure another_tap.path.rmtree @@ -166,17 +166,17 @@ describe Formulary do end specify "::from_contents" do - expect(subject.from_contents(formula_name, formula_path, formula_content)).to be_kind_of(Formula) + expect(described_class.from_contents(formula_name, formula_path, formula_content)).to be_kind_of(Formula) end specify "::to_rack" do - expect(subject.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name) + expect(described_class.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name) (HOMEBREW_CELLAR/formula_name).mkpath - expect(subject.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name) + expect(described_class.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name) expect { - subject.to_rack("a/b/#{formula_name}") + described_class.to_rack("a/b/#{formula_name}") }.to raise_error(TapFormulaUnavailableError) end @@ -191,7 +191,7 @@ describe Formulary do end it "prioritizes core Formulae" do - formula = subject.find_with_priority(formula_name) + formula = described_class.find_with_priority(formula_name) expect(formula).to be_kind_of(Formula) expect(formula.path).to eq(core_path) end @@ -199,7 +199,7 @@ describe Formulary do it "prioritizes Formulae from pinned Taps" do begin tap.pin - formula = subject.find_with_priority(formula_name) + formula = described_class.find_with_priority(formula_name) expect(formula).to be_kind_of(Formula) expect(formula.path).to eq(tap_path.realpath) ensure @@ -211,7 +211,7 @@ describe Formulary do describe "::core_path" do it "returns the path to a Formula in the core tap" do name = "foo-bar" - expect(subject.core_path(name)) + expect(described_class.core_path(name)) .to eq(Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb")) end end From e169b87f9ec430c7520d340fb65647aed66e0f97 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 13 Apr 2018 15:14:11 +0200 Subject: [PATCH 02/10] Use `expect { }.to output`. --- Library/Homebrew/test/keg_spec.rb | 34 +++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/test/keg_spec.rb b/Library/Homebrew/test/keg_spec.rb index b2ca62cff9..3c06f5b1c7 100644 --- a/Library/Homebrew/test/keg_spec.rb +++ b/Library/Homebrew/test/keg_spec.rb @@ -17,17 +17,6 @@ describe Keg do keg end - around do |example| - begin - @old_stdout = $stdout - $stdout = StringIO.new - - example.run - ensure - $stdout = @old_stdout - end - end - let(:dst) { HOMEBREW_PREFIX/"bin"/"helloworld" } let(:nonexistent) { Pathname.new("/some/nonexistent/path") } let(:mode) { OpenStruct.new } @@ -96,13 +85,15 @@ describe Keg do it "only prints what would be done" do mode.dry_run = true - expect(keg.link(mode)).to eq(0) - expect(keg).not_to be_linked + expect { + expect(keg.link(mode)).to eq(0) + }.to output(<<~EOF).to_stdout + #{HOMEBREW_PREFIX}/bin/goodbye_cruel_world + #{HOMEBREW_PREFIX}/bin/helloworld + #{HOMEBREW_PREFIX}/bin/hiworld + EOF - ["hiworld", "helloworld", "goodbye_cruel_world"].each do |file| - expect($stdout.string).to match("#{HOMEBREW_PREFIX}/bin/#{file}") - end - expect($stdout.string.lines.count).to eq(3) + expect(keg).not_to be_linked end end @@ -145,10 +136,13 @@ describe Keg do mode.overwrite = true mode.dry_run = true - expect(keg.link(mode)).to eq(0) - expect(keg).not_to be_linked + expect { + expect(keg.link(mode)).to eq(0) + }.to output(<<~EOF).to_stdout + #{dst} + EOF - expect($stdout.string).to eq("#{dst}\n") + expect(keg).not_to be_linked end end From db747b1651c2dd5b0565a46968238f1ab27752d1 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 13 Apr 2018 15:20:02 +0200 Subject: [PATCH 03/10] Refactor requirement specs. --- Library/Homebrew/test/os_requirement_spec.rb | 18 ------------------ .../requirements/linux_requirement_spec.rb | 11 +++++++++++ .../requirements/macos_requirement_spec.rb | 11 +++++++++++ 3 files changed, 22 insertions(+), 18 deletions(-) delete mode 100644 Library/Homebrew/test/os_requirement_spec.rb create mode 100644 Library/Homebrew/test/requirements/linux_requirement_spec.rb create mode 100644 Library/Homebrew/test/requirements/macos_requirement_spec.rb diff --git a/Library/Homebrew/test/os_requirement_spec.rb b/Library/Homebrew/test/os_requirement_spec.rb deleted file mode 100644 index 87f86231c1..0000000000 --- a/Library/Homebrew/test/os_requirement_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "requirements/linux_requirement" -require "requirements/macos_requirement" - -describe LinuxRequirement do - describe "#satisfied?" do - it "returns true if OS is Linux" do - expect(subject.satisfied?).to eq(OS.linux?) - end - end -end - -describe MacOSRequirement do - describe "#satisfied?" do - it "returns true if OS is macOS" do - expect(subject.satisfied?).to eq(OS.mac?) - end - end -end diff --git a/Library/Homebrew/test/requirements/linux_requirement_spec.rb b/Library/Homebrew/test/requirements/linux_requirement_spec.rb new file mode 100644 index 0000000000..3d456f1f1f --- /dev/null +++ b/Library/Homebrew/test/requirements/linux_requirement_spec.rb @@ -0,0 +1,11 @@ +require "requirements/linux_requirement" + +describe LinuxRequirement do + subject(:requirement) { described_class.new } + + describe "#satisfied?" do + it "returns true on Linux" do + expect(requirement.satisfied?).to eq(OS.linux?) + end + end +end diff --git a/Library/Homebrew/test/requirements/macos_requirement_spec.rb b/Library/Homebrew/test/requirements/macos_requirement_spec.rb new file mode 100644 index 0000000000..7828e73185 --- /dev/null +++ b/Library/Homebrew/test/requirements/macos_requirement_spec.rb @@ -0,0 +1,11 @@ +require "requirements/macos_requirement" + +describe MacOSRequirement do + subject(:requirement) { described_class.new } + + describe "#satisfied?" do + it "returns true on macOS" do + expect(requirement.satisfied?).to eq(OS.mac?) + end + end +end From d0d7116dc8093a3dd6d0483e5d7d6a302c7d0aa3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 13 Apr 2018 16:40:08 +0200 Subject: [PATCH 04/10] Refactor `Formulary` spec. --- Library/Homebrew/test/formulary_spec.rb | 117 +++++++++++++++--------- Library/Homebrew/test/spec_helper.rb | 1 + 2 files changed, 75 insertions(+), 43 deletions(-) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 5c41f630d3..2beaed5e34 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -32,10 +32,19 @@ describe Formulary do expect(described_class.class_s("foo++")).to eq("Fooxx") end - it "converts a string to PascalCase" do + it "converts a string with dots to PascalCase" do expect(described_class.class_s("shell.fm")).to eq("ShellFm") - expect(described_class.class_s("s-lang")).to eq("SLang") + end + + it "converts a string with hyphens to PascalCase" do expect(described_class.class_s("pkg-config")).to eq("PkgConfig") + end + + it "converts a string with a single letter separated by a hyphen to PascalCase" do + expect(described_class.class_s("s-lang")).to eq("SLang") + end + + it "converts a string with underscores to PascalCase" do expect(described_class.class_s("foo_bar")).to eq("FooBar") end @@ -63,7 +72,7 @@ describe Formulary do }.to raise_error(FormulaUnavailableError) end - context "if the Formula has the wrong class" do + context "when the Formula has the wrong class" do let(:formula_name) { "giraffe" } let(:formula_content) do <<~EOS @@ -88,20 +97,36 @@ describe Formulary do expect(formula).to be_kind_of(Formula) end - it "returns a Formula when given a bottle" do - formula = described_class.factory(bottle) - expect(formula).to be_kind_of(Formula) - expect(formula.local_bottle_path).to eq(bottle.realpath) + context "when given a bottle" do + subject(:formula) { described_class.factory(bottle) } + + it "returns a Formula" do + expect(formula).to be_kind_of(Formula) + end + + it "calling #local_bottle_path on the returned Formula returns the bottle path" do + expect(formula.local_bottle_path).to eq(bottle.realpath) + end end - it "returns a Formula when given an alias" do - alias_dir = CoreTap.instance.alias_dir - alias_dir.mkpath - alias_path = alias_dir/"foo" - FileUtils.ln_s formula_path, alias_path - result = described_class.factory("foo") - expect(result).to be_kind_of(Formula) - expect(result.alias_path).to eq(alias_path.to_s) + context "when given an alias" do + subject(:formula) { described_class.factory("foo") } + + let(:alias_dir) { CoreTap.instance.alias_dir.tap(&:mkpath) } + let(:alias_path) { alias_dir/"foo" } + + before do + alias_dir.mkpath + FileUtils.ln_s formula_path, alias_path + end + + it "returns a Formula" do + expect(formula).to be_kind_of(Formula) + end + + it "calling #alias_path on the returned Formula returns the alias path" do + expect(formula.alias_path).to eq(alias_path.to_s) + end end context "with installed Formula" do @@ -113,7 +138,6 @@ describe Formulary do f = described_class.from_rack(formula.rack) expect(f).to be_kind_of(Formula) - expect(f.build).to be_kind_of(Tab) end it "returns a Formula when given a Keg" do @@ -122,12 +146,12 @@ describe Formulary do keg = Keg.new(formula.prefix) f = described_class.from_keg(keg) expect(f).to be_kind_of(Formula) - expect(f.build).to be_kind_of(Tab) end end - context "from Tap" do + context "when loading from Tap" do let(:tap) { Tap.new("homebrew", "foo") } + let(:another_tap) { Tap.new("homebrew", "bar") } let(:formula_path) { tap.path/"#{formula_name}.rb" } it "returns a Formula when given a name" do @@ -152,15 +176,11 @@ describe Formulary do end it "raises an error if a Formula is in multiple Taps" do - begin - another_tap = Tap.new("homebrew", "bar") - (another_tap.path/"#{formula_name}.rb").write formula_content - expect { - described_class.factory(formula_name) - }.to raise_error(TapFormulaAmbiguityError) - ensure - another_tap.path.rmtree - end + (another_tap.path/"#{formula_name}.rb").write formula_content + + expect { + described_class.factory(formula_name) + }.to raise_error(TapFormulaAmbiguityError) end end end @@ -169,15 +189,32 @@ describe Formulary do expect(described_class.from_contents(formula_name, formula_path, formula_content)).to be_kind_of(Formula) end - specify "::to_rack" do - expect(described_class.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name) + describe "::to_rack" do + alias_matcher :exist, :be_exist - (HOMEBREW_CELLAR/formula_name).mkpath - expect(described_class.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name) + let(:rack_path) { HOMEBREW_CELLAR/formula_name } - expect { - described_class.to_rack("a/b/#{formula_name}") - }.to raise_error(TapFormulaUnavailableError) + context "when the Rack does not exist" do + it "returns the Rack" do + expect(described_class.to_rack(formula_name)).to eq(rack_path) + end + end + + context "when the Rack exists" do + before do + rack_path.mkpath + end + + it "returns the Rack" do + expect(described_class.to_rack(formula_name)).to eq(rack_path) + end + end + + it "raises an error if the Formula is not available" do + expect { + described_class.to_rack("a/b/#{formula_name}") + }.to raise_error(TapFormulaUnavailableError) + end end describe "::find_with_priority" do @@ -192,19 +229,13 @@ describe Formulary do it "prioritizes core Formulae" do formula = described_class.find_with_priority(formula_name) - expect(formula).to be_kind_of(Formula) expect(formula.path).to eq(core_path) end it "prioritizes Formulae from pinned Taps" do - begin - tap.pin - formula = described_class.find_with_priority(formula_name) - expect(formula).to be_kind_of(Formula) - expect(formula.path).to eq(tap_path.realpath) - ensure - tap.pinned_symlink_path.parent.parent.rmtree - end + tap.pin + formula = described_class.find_with_priority(formula_name) + expect(formula.path).to eq(tap_path.realpath) end end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 8719c6e584..2ad3b2e642 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -130,6 +130,7 @@ RSpec.configure do |config| HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo", HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services", HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow", + HOMEBREW_LIBRARY/"PinnedTaps", HOMEBREW_REPOSITORY/".git", CoreTap.instance.path/".git", CoreTap.instance.alias_dir, From b91628a6143f990939210c09c563bb521dede320 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 03:01:33 +0200 Subject: [PATCH 05/10] Refactor `Hardware::CPU` spec. --- .../Homebrew/extend/os/mac/hardware/cpu.rb | 12 +- Library/Homebrew/hardware.rb | 6 +- Library/Homebrew/test/hardware/cpu_spec.rb | 114 ++++++++++++++++++ Library/Homebrew/test/hardware_spec.rb | 87 ------------- 4 files changed, 123 insertions(+), 96 deletions(-) create mode 100644 Library/Homebrew/test/hardware/cpu_spec.rb delete mode 100644 Library/Homebrew/test/hardware_spec.rb diff --git a/Library/Homebrew/extend/os/mac/hardware/cpu.rb b/Library/Homebrew/extend/os/mac/hardware/cpu.rb index 14ee2fd9ae..340e421221 100644 --- a/Library/Homebrew/extend/os/mac/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/mac/hardware/cpu.rb @@ -167,15 +167,15 @@ module Hardware def intel_can_run?(arch) case arch - when :ppc + when *PPC_32BIT_ARCHS # Rosetta is still available MacOS.version < :lion - when :ppc64 + when *PPC_64BIT_ARCHS # Rosetta never supported PPC64 false - when :x86_64 + when *INTEL_64BIT_ARCHS Hardware::CPU.is_64_bit? - when :i386 + when *INTEL_32BIT_ARCHS true else # dunno false @@ -184,9 +184,9 @@ module Hardware def ppc_can_run?(arch) case arch - when :ppc + when *PPC_32BIT_ARCHS true - when :ppc64 + when *PPC_64BIT_ARCHS Hardware::CPU.is_64_bit? else # Intel is never supported diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index b2a559d59c..c7756dd3b5 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -2,7 +2,7 @@ module Hardware class CPU INTEL_32BIT_ARCHS = [:i386].freeze INTEL_64BIT_ARCHS = [:x86_64].freeze - PPC_32BIT_ARCHS = [:ppc, :ppc7400, :ppc7450, :ppc970].freeze + PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze PPC_64BIT_ARCHS = [:ppc64].freeze class << self @@ -118,9 +118,9 @@ module Hardware if is_32_bit? arch_32_bit == arch elsif intel? - [:i386, :x86_64].include? arch + (INTEL_32BIT_ARCHS + INTEL_64BIT_ARCHS).include?(arch) elsif ppc? - [:ppc, :ppc64].include? arch + (PPC_32BIT_ARCHS + PPC_64BIT_ARCHS).include?(arch) else false end diff --git a/Library/Homebrew/test/hardware/cpu_spec.rb b/Library/Homebrew/test/hardware/cpu_spec.rb new file mode 100644 index 0000000000..5bcb9fca5c --- /dev/null +++ b/Library/Homebrew/test/hardware/cpu_spec.rb @@ -0,0 +1,114 @@ +require "hardware" + +describe Hardware::CPU do + describe "::type" do + let(:cpu_types) { + [ + :intel, + :ppc, + :dunno, + ] + } + + it "returns the current CPU's type as a symbol, or :dunno if it cannot be detected" do + expect(cpu_types).to include(described_class.type) + end + end + + describe "::family" do + let(:cpu_families) { + [ + :core, + :core2, + :penryn, + :nehalem, + :arrandale, + :sandybridge, + :ivybridge, + :haswell, + :broadwell, + :skylake, + :kabylake, + :dunno, + ] + } + + it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do + expect(cpu_families).to include described_class.family + end + end + + describe "::can_run?" do + subject { described_class } + + matcher :be_able_to_run do |arch| + match do |expected| + allow(expected).to receive(:type).and_return type + allow(expected).to receive(:bits).and_return bits + + expect(expected.can_run?(arch)).to be true + end + end + + let(:type) { described_class.type } + let(:bits) { described_class.bits } + + before do + allow(described_class).to receive(:type).and_return type + allow(described_class).to receive(:bits).and_return bits + end + + context "when on an 32-bit Intel machine" do + let(:type) { :intel } + let(:bits) { 32 } + + it { is_expected.to be_able_to_run :i386 } + it { is_expected.not_to be_able_to_run :x86_64 } + it { is_expected.not_to be_able_to_run :ppc32 } + it { is_expected.not_to be_able_to_run :ppc64 } + end + + context "when on an 64-bit Intel machine" do + let(:type) { :intel } + let(:bits) { 64 } + + it { is_expected.to be_able_to_run :i386 } + it { is_expected.to be_able_to_run :x86_64 } + it { is_expected.not_to be_able_to_run :ppc32 } + it { is_expected.not_to be_able_to_run :ppc64 } + end + + context "when on a 32-bit PowerPC machine" do + let(:type) { :ppc } + let(:bits) { 32 } + + it { is_expected.not_to be_able_to_run :i386 } + it { is_expected.not_to be_able_to_run :x86_64 } + it { is_expected.to be_able_to_run :ppc32 } + it { is_expected.not_to be_able_to_run :ppc64 } + end + + context "when on a 64-bit PowerPC machine" do + let(:type) { :ppc } + let(:bits) { 64 } + + it { is_expected.not_to be_able_to_run :i386 } + it { is_expected.not_to be_able_to_run :x86_64 } + it { is_expected.to be_able_to_run :ppc32 } + it { is_expected.to be_able_to_run :ppc64 } + end + + context "when the CPU type is unknown" do + let(:type) { :dunno } + + it { is_expected.not_to be_able_to_run :i386 } + it { is_expected.not_to be_able_to_run :x86_64 } + it { is_expected.not_to be_able_to_run :ppc32 } + it { is_expected.not_to be_able_to_run :ppc64 } + end + + context "when the architecture is unknown" do + it { is_expected.not_to be_able_to_run :blah } + end + end +end diff --git a/Library/Homebrew/test/hardware_spec.rb b/Library/Homebrew/test/hardware_spec.rb deleted file mode 100644 index de8d77e680..0000000000 --- a/Library/Homebrew/test/hardware_spec.rb +++ /dev/null @@ -1,87 +0,0 @@ -require "hardware" - -module Hardware - describe CPU do - describe "::type" do - it "returns the current CPU's type as a symbol, or :dunno if it cannot be detected" do - expect( - [ - :intel, - :ppc, - :dunno, - ], - ).to include(described_class.type) - end - end - - describe "::family" do - it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do - skip "Needs an Intel CPU." unless described_class.intel? - - expect( - [ - :core, - :core2, - :penryn, - :nehalem, - :arrandale, - :sandybridge, - :ivybridge, - :haswell, - :broadwell, - :skylake, - :kabylake, - :dunno, - ], - ).to include(described_class.family) - end - end - - describe "::can_run?" do - it "reports that Intel machines can run Intel executables" do - allow(Hardware::CPU).to receive(:type).and_return :intel - allow(Hardware::CPU).to receive(:bits).and_return 64 - expect(Hardware::CPU.can_run?(:i386)).to be true - expect(Hardware::CPU.can_run?(:x86_64)).to be true - end - - it "reports that PowerPC machines can run PowerPC executables" do - allow(Hardware::CPU).to receive(:type).and_return :ppc - allow(Hardware::CPU).to receive(:bits).and_return 64 - expect(Hardware::CPU.can_run?(:ppc)).to be true - expect(Hardware::CPU.can_run?(:ppc64)).to be true - end - - it "reports that 32-bit Intel machines can't run x86_64 executables" do - allow(Hardware::CPU).to receive(:type).and_return :intel - allow(Hardware::CPU).to receive(:bits).and_return 32 - expect(Hardware::CPU.can_run?(:x86_64)).to be false - end - - it "reports that 32-bit PowerPC machines can't run ppc64 executables" do - allow(Hardware::CPU).to receive(:type).and_return :ppc - allow(Hardware::CPU).to receive(:bits).and_return 32 - expect(Hardware::CPU.can_run?(:ppc64)).to be false - end - - it "identifies that Intel and PowerPC machines can't run each others' executables" do - allow(Hardware::CPU).to receive(:type).and_return :ppc - expect(Hardware::CPU.can_run?(:i386)).to be false - expect(Hardware::CPU.can_run?(:x86_64)).to be false - - allow(Hardware::CPU).to receive(:type).and_return :intel - expect(Hardware::CPU.can_run?(:ppc)).to be false - expect(Hardware::CPU.can_run?(:ppc64)).to be false - end - - it "returns false for unknown CPU types" do - allow(Hardware::CPU).to receive(:type).and_return :dunno - expect(Hardware::CPU.can_run?(:i386)).to be false - end - - it "returns false for unknown arches" do - expect(Hardware::CPU.can_run?(:blah)).to be false - end - end - end -end From 5e2d4d52ba9c3452adf1765a39ccd2249c7d254a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 00:57:14 +0200 Subject: [PATCH 06/10] Refactor `OsxfuseRequirement` spec. --- Library/Homebrew/dev-cmd/tests.rb | 1 + .../non_binary_osxfuse_requirement.rb | 15 ++++++ .../mac/requirements/osxfuse_requirement.rb | 12 ----- .../non_binary_osxfuse_requirement.rb | 3 ++ .../non_binary_osxfuse_requirement.rb | 7 +++ .../requirements/osxfuse_requirement.rb | 4 -- .../test/os/linux/osxfuse_requirement_spec.rb | 9 ---- .../test/os/mac/osxfuse_requirement_spec.rb | 36 ------------- .../non_binary_osxfuse_requirement_spec.rb | 9 ++++ .../requirements/osxfuse_requirement_spec.rb | 50 +++++++++++++++++++ 10 files changed, 85 insertions(+), 61 deletions(-) create mode 100644 Library/Homebrew/extend/os/mac/requirements/non_binary_osxfuse_requirement.rb create mode 100644 Library/Homebrew/extend/os/requirements/non_binary_osxfuse_requirement.rb create mode 100644 Library/Homebrew/requirements/non_binary_osxfuse_requirement.rb delete mode 100644 Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb delete mode 100644 Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb create mode 100644 Library/Homebrew/test/requirements/non_binary_osxfuse_requirement_spec.rb create mode 100644 Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index c96b19a1d7..3edc12ed5b 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -113,6 +113,7 @@ module Homebrew end unless OS.linux? + args << "--tag" << "~needs_linux" files = files.reject { |p| p =~ %r{^test/os/linux(/.*|_spec\.rb)$} } end diff --git a/Library/Homebrew/extend/os/mac/requirements/non_binary_osxfuse_requirement.rb b/Library/Homebrew/extend/os/mac/requirements/non_binary_osxfuse_requirement.rb new file mode 100644 index 0000000000..39d638cf88 --- /dev/null +++ b/Library/Homebrew/extend/os/mac/requirements/non_binary_osxfuse_requirement.rb @@ -0,0 +1,15 @@ +require "requirement" + +class NonBinaryOsxfuseRequirement < Requirement + fatal true + satisfy(build_env: false) do + HOMEBREW_PREFIX.to_s != "/usr/local" || !OsxfuseRequirement.binary_osxfuse_installed? + end + + def message + <<~EOS + osxfuse is already installed from the binary distribution and + conflicts with this formula. + EOS + end +end diff --git a/Library/Homebrew/extend/os/mac/requirements/osxfuse_requirement.rb b/Library/Homebrew/extend/os/mac/requirements/osxfuse_requirement.rb index 89c2b8786b..f6ca8cfc28 100644 --- a/Library/Homebrew/extend/os/mac/requirements/osxfuse_requirement.rb +++ b/Library/Homebrew/extend/os/mac/requirements/osxfuse_requirement.rb @@ -19,15 +19,3 @@ class OsxfuseRequirement < Requirement end end end - -class NonBinaryOsxfuseRequirement < Requirement - fatal true - satisfy(build_env: false) { HOMEBREW_PREFIX.to_s != "/usr/local" || !OsxfuseRequirement.binary_osxfuse_installed? } - - def message - <<~EOS - osxfuse is already installed from the binary distribution and - conflicts with this formula. - EOS - end -end diff --git a/Library/Homebrew/extend/os/requirements/non_binary_osxfuse_requirement.rb b/Library/Homebrew/extend/os/requirements/non_binary_osxfuse_requirement.rb new file mode 100644 index 0000000000..099f29382c --- /dev/null +++ b/Library/Homebrew/extend/os/requirements/non_binary_osxfuse_requirement.rb @@ -0,0 +1,3 @@ +if OS.mac? + require "extend/os/mac/requirements/non_binary_osxfuse_requirement" +end diff --git a/Library/Homebrew/requirements/non_binary_osxfuse_requirement.rb b/Library/Homebrew/requirements/non_binary_osxfuse_requirement.rb new file mode 100644 index 0000000000..bb7788f487 --- /dev/null +++ b/Library/Homebrew/requirements/non_binary_osxfuse_requirement.rb @@ -0,0 +1,7 @@ +require "requirement" + +class NonBinaryOsxfuseRequirement < Requirement + fatal false +end + +require "extend/os/requirements/non_binary_osxfuse_requirement" diff --git a/Library/Homebrew/requirements/osxfuse_requirement.rb b/Library/Homebrew/requirements/osxfuse_requirement.rb index 15da16c59c..2e67a4b050 100644 --- a/Library/Homebrew/requirements/osxfuse_requirement.rb +++ b/Library/Homebrew/requirements/osxfuse_requirement.rb @@ -5,8 +5,4 @@ class OsxfuseRequirement < Requirement fatal true end -class NonBinaryOsxfuseRequirement < Requirement - fatal false -end - require "extend/os/requirements/osxfuse_requirement" diff --git a/Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb b/Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb deleted file mode 100644 index c45af2fa79..0000000000 --- a/Library/Homebrew/test/os/linux/osxfuse_requirement_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "requirements/osxfuse_requirement" - -describe OsxfuseRequirement do - subject { described_class.new([]) } - - describe "#message" do - its(:message) { is_expected.to match("libfuse is required to install this formula") } - end -end diff --git a/Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb b/Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb deleted file mode 100644 index 06d3d885e6..0000000000 --- a/Library/Homebrew/test/os/mac/osxfuse_requirement_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require "requirements/osxfuse_requirement" - -describe OsxfuseRequirement do - subject { described_class.new([]) } - - describe "::binary_osxfuse_installed?" do - it "returns false if fuse.h does not exist" do - allow(File).to receive(:exist?).and_return(false) - expect(described_class).not_to be_binary_osxfuse_installed - end - - it "returns false if osxfuse include directory is a symlink" do - allow(File).to receive(:exist?).and_return(true) - allow(File).to receive(:symlink?).and_return(true) - expect(described_class).not_to be_binary_osxfuse_installed - end - end - - describe "environment" do - it "adds the fuse directories to the appropriate paths" do - expect(ENV).to receive(:append_path).with("PKG_CONFIG_PATH", any_args) - expect(ENV).to receive(:append_path).with("HOMEBREW_LIBRARY_PATHS", any_args) - expect(ENV).to receive(:append_path).with("HOMEBREW_INCLUDE_PATHS", any_args) - subject.modify_build_environment - end - end -end - -describe NonBinaryOsxfuseRequirement do - subject { described_class.new([]) } - - describe "#message" do - msg = /osxfuse is already installed from the binary distribution/ - its(:message) { is_expected.to match(msg) } - end -end diff --git a/Library/Homebrew/test/requirements/non_binary_osxfuse_requirement_spec.rb b/Library/Homebrew/test/requirements/non_binary_osxfuse_requirement_spec.rb new file mode 100644 index 0000000000..84fb448740 --- /dev/null +++ b/Library/Homebrew/test/requirements/non_binary_osxfuse_requirement_spec.rb @@ -0,0 +1,9 @@ +require "requirements/non_binary_osxfuse_requirement" + +describe NonBinaryOsxfuseRequirement, :needs_macos do + subject { described_class.new([]) } + + describe "#message" do + its(:message) { is_expected.to match("osxfuse is already installed from the binary distribution") } + end +end diff --git a/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb b/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb new file mode 100644 index 0000000000..59a3553077 --- /dev/null +++ b/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb @@ -0,0 +1,50 @@ +require "requirements/osxfuse_requirement" + +describe OsxfuseRequirement do + subject(:requirement) { described_class.new([]) } + + describe "::binary_osxfuse_installed?", :needs_macos do + alias_matcher :have_binary_osxfuse_installed, :be_binary_osxfuse_installed + + it "returns false if fuse.h does not exist" do + allow(File).to receive(:exist?).and_return(false) + expect(described_class).not_to have_binary_osxfuse_installed + end + + it "returns false if osxfuse include directory is a symlink" do + allow(File).to receive(:exist?).and_return(true) + allow(File).to receive(:symlink?).and_return(true) + expect(described_class).not_to have_binary_osxfuse_installed + end + end + + describe "#modify_build_environment", :needs_macos do + it "adds the fuse directories to PKG_CONFIG_PATH" do + allow(ENV).to receive(:append_path) + requirement.modify_build_environment + expect(ENV).to have_received(:append_path).with("PKG_CONFIG_PATH", any_args) + end + + it "adds the fuse directories to HOMEBREW_LIBRARY_PATHS" do + allow(ENV).to receive(:append_path) + requirement.modify_build_environment + expect(ENV).to have_received(:append_path).with("HOMEBREW_LIBRARY_PATHS", any_args) + end + + it "adds the fuse directories to HOMEBREW_INCLUDE_PATHS" do + allow(ENV).to receive(:append_path) + requirement.modify_build_environment + expect(ENV).to have_received(:append_path).with("HOMEBREW_INCLUDE_PATHS", any_args) + end + end + + describe "#message" do + it "prompts for installation of 'libfuse' on Linux", :needs_linux do + expect(requirement.message).to match("libfuse is required to install this formula") + end + + it "prompts for installation of 'osxFuse' on macOS", :needs_macos do + expect(requirement.message).to match("osxfuse.github.io") + end + end +end From 16fb563d4977ec7a0f99a6578491a3ef156a2a37 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 01:39:00 +0200 Subject: [PATCH 07/10] Refactor `MissingFormula` spec. --- Library/Homebrew/.rubocop.yml | 4 + Library/Homebrew/cmd/info.rb | 2 +- Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 2 +- Library/Homebrew/dev-cmd/create.rb | 2 +- Library/Homebrew/test/missing_formula_spec.rb | 106 ++++++------------ 7 files changed, 42 insertions(+), 78 deletions(-) diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 58b911ca9f..267641f022 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -88,3 +88,7 @@ Style/HashSyntax: # so many of these in formulae but none in here Style/TrailingBodyOnMethodDefinition: Enabled: true + +Rspec/ExpectActual: + Exclude: + - 'test/missing_formula_spec.rb' diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index a0e1cd4756..cfe8b13d87 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -60,7 +60,7 @@ module Homebrew rescue FormulaUnavailableError => e ofail e.message # No formula with this name, try a missing formula lookup - if (reason = Homebrew::MissingFormula.reason(f)) + if (reason = MissingFormula.reason(f)) $stderr.puts reason end end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 8fce1d60a6..21ea88193a 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -257,7 +257,7 @@ module Homebrew end ofail e.message - if (reason = Homebrew::MissingFormula.reason(e.name)) + if (reason = MissingFormula.reason(e.name)) $stderr.puts reason return end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index c61f4576a1..0f01afa46f 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -64,7 +64,7 @@ module Homebrew count = local_results.length + tap_results.length ohai "Searching blacklisted, migrated and deleted formulae..." - if reason = Homebrew::MissingFormula.reason(query, silent: true) + if reason = MissingFormula.reason(query, silent: true) if count.positive? puts puts "If you meant #{query.inspect} specifically:" diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index ddd07a0ecd..3fe5a80d01 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -308,7 +308,7 @@ class FormulaAuditor name = formula.name - if Homebrew::MissingFormula.blacklisted_reason(name) + if MissingFormula.blacklisted_reason(name) problem "'#{name}' is blacklisted." end diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index a992e5706c..d9905a39da 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -65,7 +65,7 @@ module Homebrew # Don't allow blacklisted formula, or names that shadow aliases, # unless --force is specified. unless ARGV.force? - if reason = Homebrew::MissingFormula.blacklisted_reason(fc.name) + if reason = MissingFormula.blacklisted_reason(fc.name) raise "#{fc.name} is blacklisted for creation.\n#{reason}\nIf you really want to create this formula use --force." end diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index a9d0083d09..56c4ad2c3c 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -1,117 +1,77 @@ require "missing_formula" describe Homebrew::MissingFormula do - context "::reason" do + describe "::reason" do subject { described_class.reason("gem") } it { is_expected.not_to be_nil } end - context "::blacklisted_reason" do - matcher(:be_blacklisted) do + describe "::blacklisted_reason" do + matcher :be_blacklisted do match do |expected| described_class.blacklisted_reason(expected) end end - context "rubygems" do - %w[gem rubygem rubygems].each do |s| - subject { s } - - it { is_expected.to be_blacklisted } - end + specify "RubyGems is blacklisted" do + expect(%w[gem rubygem rubygems]).to all be_blacklisted end - context "latex" do - %w[latex tex tex-live texlive TexLive].each do |s| - subject { s } - - it { is_expected.to be_blacklisted } - end + specify "LaTeX is blacklisted" do + expect(%w[latex tex tex-live texlive TexLive]).to all be_blacklisted end - context "pip" do - subject { "pip" } - - it { is_expected.to be_blacklisted } + specify "pip is blacklisted" do + expect("pip").to be_blacklisted end - context "pil" do - subject { "pil" } - - it { is_expected.to be_blacklisted } + specify "PIL is blacklisted" do + expect("pil").to be_blacklisted end - context "macruby" do - subject { "MacRuby" } - - it { is_expected.to be_blacklisted } + specify "MacRuby is blacklisted" do + expect("MacRuby").to be_blacklisted end - context "lzma" do - %w[lzma liblzma].each do |s| - subject { s } - - it { is_expected.to be_blacklisted } - end + specify "lzma is blacklisted" do + expect(%w[lzma liblzma]).to all be_blacklisted end - context "gtest" do - %w[gtest googletest google-test].each do |s| - subject { s } - - it { is_expected.to be_blacklisted } - end + specify "gtest is blacklisted" do + expect(%w[gtest googletest google-test]).to all be_blacklisted end - context "gmock" do - %w[gmock googlemock google-mock].each do |s| - subject { s } - - it { is_expected.to be_blacklisted } - end + specify "gmock is blacklisted" do + expect(%w[gmock googlemock google-mock]).to all be_blacklisted end - context "sshpass" do - subject { "sshpass" } - - it { is_expected.to be_blacklisted } + specify "sshpass is blacklisted" do + expect("sshpass").to be_blacklisted end - context "gsutil" do - subject { "gsutil" } - - it { is_expected.to be_blacklisted } + specify "gsutil is blacklisted" do + expect("gsutil").to be_blacklisted end - context "gfortran" do - subject { "gfortran" } - - it { is_expected.to be_blacklisted } + specify "gfortran is blacklisted" do + expect("gfortran").to be_blacklisted end - context "play" do - subject { "play" } - - it { is_expected.to be_blacklisted } + specify "play is blacklisted" do + expect("play").to be_blacklisted end - context "haskell-platform" do - subject { "haskell-platform" } - - it { is_expected.to be_blacklisted } + specify "haskell-platform is blacklisted" do + expect("haskell-platform").to be_blacklisted end - context "xcode", :needs_macos do - %w[xcode Xcode].each do |s| - subject { s } - - it { is_expected.to be_blacklisted } - end + specify "Xcode is blacklisted", :needs_macos do + expect(%w[xcode Xcode]).to all be_blacklisted end end - context "::tap_migration_reason" do + describe "::tap_migration_reason" do subject { described_class.tap_migration_reason(formula) } before do @@ -136,7 +96,7 @@ describe Homebrew::MissingFormula do end end - context "::deleted_reason" do + describe "::deleted_reason" do subject { described_class.deleted_reason(formula, silent: true) } before do From 0432feabd33e4fa02e5089783080e9568c982a77 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 06:34:46 +0200 Subject: [PATCH 08/10] Add missing blacklisted Formulae. --- Library/Homebrew/test/missing_formula_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index 56c4ad2c3c..bd17439d2b 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -66,6 +66,14 @@ describe Homebrew::MissingFormula do expect("haskell-platform").to be_blacklisted end + specify "mysqldump-secure is blacklisted" do + expect("mysqldump-secure").to be_blacklisted + end + + specify "ngrok is blacklisted" do + expect("ngrok").to be_blacklisted + end + specify "Xcode is blacklisted", :needs_macos do expect(%w[xcode Xcode]).to all be_blacklisted end From 9f1b64a9d44650ac36f8bfacfc325c67364a2837 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 06:46:01 +0200 Subject: [PATCH 09/10] Add additional specs for `PATH`. --- Library/Homebrew/PATH.rb | 2 +- Library/Homebrew/test/PATH_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index de7167eb4b..263f26484e 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -32,7 +32,7 @@ class PATH end def to_ary - @paths + @paths.dup.to_ary end alias to_a to_ary diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index 68233c23c7..b6f884d665 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -23,6 +23,13 @@ describe PATH do it "returns a PATH array" do expect(described_class.new("/path1", "/path2").to_ary).to eq(["/path1", "/path2"]) end + + it "does not allow mutating the original" do + path = described_class.new("/path1", "/path2") + path.to_ary << "/path3" + + expect(path).not_to include("/path3") + end end describe "#to_str" do @@ -61,6 +68,12 @@ describe PATH do end end + describe "#==" do + it "always returns false when comparing against something which does not respons to `#to_ary` or `#to_str`" do + expect(described_class.new).not_to eq Object.new + end + end + describe "#include?" do it "returns true if a path is included" do path = described_class.new("/path1", "/path2") From 54166f9886701f30988f90dbce76564b2f2b00cd Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 17 Apr 2018 17:45:21 +0200 Subject: [PATCH 10/10] Update `Gemfile.lock`. --- Library/Homebrew/test/Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index 8fac7645d3..f5b13e4fbf 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -36,7 +36,7 @@ GEM rspec-support (3.7.1) rspec-wait (0.0.9) rspec (>= 3, < 4) - rubocop (0.54.0) + rubocop (0.55.0) parallel (~> 1.10) parser (>= 2.5) powerpack (~> 0.1) @@ -62,7 +62,7 @@ DEPENDENCIES rspec-its rspec-retry rspec-wait - rubocop (= 0.54.0) + rubocop (= 0.55.0) simplecov BUNDLED WITH