From 9218d3014d6b97a0225e537b6227eca885dd1260 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 21 Jul 2017 06:38:45 +0530 Subject: [PATCH] Added tests for plist_caveats --- Library/Homebrew/caveats.rb | 11 ++- Library/Homebrew/test/caveats_spec.rb | 124 ++++++++++++++++---------- 2 files changed, 80 insertions(+), 55 deletions(-) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 2c724ab815..172d3c73fe 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -165,7 +165,6 @@ class Caveats s = [] if f.plist || (keg && keg.plist_installed?) plist_domain = f.plist_path.basename(".plist") - plist_path = plist_complete_path # we readlink because this path probably doesn't exist since caveats # occurs before the link step of installation @@ -197,8 +196,8 @@ class Caveats s << " #{f.plist_manual}" end - # pbpaste is a system clipboard tool for OSX that doesn't work well with tmux - # This checks if tmux is being used and warns about brew failure + # pbpaste pastes the system clipboard tool on macOS and fails with `tmux` by default + # check if this is being run under `tmux` to avoid failing if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") s << "" << "WARNING: brew services will fail when run under tmux." end @@ -206,7 +205,7 @@ class Caveats s.join("\n") + "\n" unless s.empty? end - def plist_complete_path + def plist_path destination = if f.plist_startup "/Library/LaunchDaemons" else @@ -218,8 +217,8 @@ class Caveats else File.basename Dir["#{keg}/*.plist"].first end - destination_path = Pathname.new File.expand_path destination + destination_path = Pathname.new(File.expand_path(destination)) - return destination_path/plist_filename + destination_path/plist_filename end end diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index 6c734faf6a..e04e4eab33 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -1,6 +1,5 @@ require "formula" require "caveats" -require "pathname" describe Caveats do subject { described_class.new(f) } @@ -50,6 +49,81 @@ describe Caveats do end expect(described_class.new(f).caveats).to include("login") end + + it "gives information about restarting services after upgrade" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + plist_options startup: true + end + f_obj = described_class.new(f) + plist_path = Pathname.new("plist") + FileUtils.touch plist_path + allow(f_obj).to receive(:plist_path).and_return(plist_path) + allow(plist_path).to receive(:symlink?).and_return(true) + expect(f_obj.caveats).to include("restart #{f.full_name}") + expect(f_obj.caveats).to include("sudo") + end + + context "when plist_path is not a file nor symlinked and plist_startup is false" do + let(:f) { + formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + end + } + let(:f_obj) { described_class.new(f) } + let(:caveats) { f_obj.caveats } + let(:plist_path) { Pathname.new("plist") } + + before do + FileUtils.touch plist_path + allow(f_obj).to receive(:plist_path).and_return(plist_path) + allow(plist_path).to receive(:symlink?).and_return(true) + end + + it "tells command to run after upgrade" do + allow(Kernel).to receive(:system).with(any_args).and_return(true) + expect(caveats).to include("restart #{f.full_name} after an upgrade") + end + + it "tells command to run to start formula" do + expect(caveats).to include("To start #{f.full_name}:") + end + end + + it "gives information about plist_manual" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + plist_options manual: "foo" + end + caveats = described_class.new(f).caveats + + expect(caveats).to include("background service") + expect(caveats).to include(f.plist_manual) + end + + it "warns about brew failing under tmux" do + f = formula do + url "foo-1.0" + def plist + "plist_test.plist" + end + end + allow(ENV).to receive(:[]).with("TMUX").and_return(true) + allow(Homebrew).to receive(:_system).with("/usr/bin/pbpaste").and_return(false) + caveats = described_class.new(f).caveats + + expect(caveats).to include("WARNING:") + expect(caveats).to include("tmux") + end end context "when f.keg_only is not nil" do @@ -127,53 +201,5 @@ describe Caveats do expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") end end - - context "when plist_caveats are given" do - it "gives information about plist_manual" do - f = formula do - url "foo-1.0" - def plist - "plist_test.plist" - end - plist_options manual: "foo" - end - caveats = described_class.new(f).caveats - - expect(caveats).to include("background service") - expect(caveats).to include(f.plist_manual) - end - - it "warns about brew failing under tmux" do - f = formula do - url "foo-1.0" - def plist - "plist_test.plist" - end - end - allow(ENV).to receive(:[]).with("TMUX").and_return(true) - allow(Homebrew).to receive(:_system).with("/usr/bin/pbpaste").and_return(false) - caveats = described_class.new(f).caveats - - expect(caveats).to include("WARNING:") - expect(caveats).to include("tmux") - end - - it "gives information about restarting services after upgrade" do - f = formula do - url "foo-1.0" - def plist - "plist_test.plist" - end - plist_options startup: true - end - f_obj = described_class.new(f) - plist_path = Pathname.new("plist") - FileUtils.touch plist_path - allow(f_obj).to receive(:plist_complete_path).and_return(plist_path) - allow(plist_path).to receive(:symlink?).and_return(true) - expect(f_obj.caveats).to include("restart #{f.full_name}") - expect(f_obj.caveats).to include("sudo") - end - end end end