From 3b7e0d8dbe3d9652b6d9a81f01bc3e68479b17bc Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 01:54:24 +0200 Subject: Added tests for cask search with online search failure --- Library/Homebrew/test/cask/cli/search_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e237ad464..e7065404d 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -22,16 +22,29 @@ describe Hbc::CLI::Search, :cask do EOS end + it "returns matches even when online search failed" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { + Hbc::CLI::Search.run("local") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + EOS + .and output(/^Error: reason\n/).to_stderr + end + it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty end - it "lists all available Casks with no search term" do + it "lists all Casks available offline with no search term" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) expect { Hbc::CLI::Search.run }.to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do -- cgit v1.2.3 From 68c837f0412f0958817ee2d827b770f26d51bad6 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:01:08 +0200 Subject: Unified tests formatting for multiline output matching --- Library/Homebrew/test/cask/cli/search_spec.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e7065404d..f3b693d99 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -36,7 +36,9 @@ describe Hbc::CLI::Search, :cask do it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") - }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "foo-bar-baz". + EOS end it "lists all Casks available offline with no search term" do @@ -68,19 +70,29 @@ describe Hbc::CLI::Search, :cask do it "accepts a regexp argument" do expect { Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/") - }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Regexp Matches + local-caffeine + EOS end - it "Returns both exact and partial matches" do + it "returns both exact and partial matches" do expect { Hbc::CLI::Search.run("test-opera") - }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Exact Match + test-opera + ==> Partial Matches + test-opera-mail + EOS end it "does not search the Tap name" do expect { Hbc::CLI::Search.run("caskroom") - }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "caskroom". + EOS end it "doesn't highlight packages that aren't installed" do -- cgit v1.2.3 From 29b0c7d7472dc26c8c8913db9a16e996ce68f6d2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:05:35 +0200 Subject: Added a test for no-macthes output to non-TTY --- Library/Homebrew/test/cask/cli/search_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index f3b693d99..48a4d556d 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -41,6 +41,13 @@ describe Hbc::CLI::Search, :cask do EOS end + it "doesn't output anything to non-TTY stdout when there are no matches" do + expect { + Hbc::CLI::Search.run("foo-bar-baz") + }.to not_to_output.to_stdout + .and not_to_output.to_stderr + end + it "lists all Casks available offline with no search term" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) expect { -- cgit v1.2.3 From 6ac0b9881de5a00a884ca5e59553583d1ada0fc5 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:43:28 +0200 Subject: Fixed test for the changed error message --- Library/Homebrew/test/cask/cli/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 48a4d556d..06f0b4b32 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -30,7 +30,7 @@ describe Hbc::CLI::Search, :cask do local-caffeine local-transmission EOS - .and output(/^Error: reason\n/).to_stderr + .and output(/^Warning: Online search failed: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do -- cgit v1.2.3 From c1799bb49712b9362b54e8bccae1e721ce6542e0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Wed, 31 May 2017 02:00:27 +0530 Subject: Added tests for disk_cleanup and unremovable kegs --- Library/Homebrew/test/cleanup_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 4e5e42efa..81cd63147 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,6 +63,28 @@ describe Homebrew::Cleanup do end end + specify "::update_disk_cleanup_size" do + shutup do + described_class.instance_eval("@disk_cleanup_size = 0") + described_class.update_disk_cleanup_size(128) + end + expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) + end + + specify "::disk_cleanup_size" do + shutup do + described_class.instance_eval("@disk_cleanup_size = 0") + end + expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) + end + + specify "::unremovable_kegs" do + shutup do + described_class.unremovable_kegs + end + expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) + end + specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" -- cgit v1.2.3 From 5e17d63010c74dd23f02222feb61b76f515908d4 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Wed, 19 Jul 2017 02:46:45 +0530 Subject: Added tests for ARGV prune 'all' --- Library/Homebrew/test/cleanup_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 81cd63147..f1a6e770e 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -163,5 +163,21 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end + + it "cleans up files and directories with name containing -- if ARGV prune is all" do + a = (HOMEBREW_CACHE/"--a") + b = (HOMEBREW_CACHE/"b") + c = (HOMEBREW_CACHE/"c") + a.mkpath + b.mkpath + FileUtils.touch c + allow(ARGV).to receive(:value).with("prune").and_return("all") + shutup do + described_class.cleanup_cache + end + expect(a).not_to exist + expect(b).to exist + expect(c).not_to exist + end end end -- cgit v1.2.3 From 265d43444bcd09d5d54963161f2fe77cdef35ef9 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 4 Aug 2017 05:47:05 +0530 Subject: improved prune all test --- Library/Homebrew/test/cleanup_spec.rb | 41 +++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index f1a6e770e..da6796d5f 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -164,20 +164,37 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end - it "cleans up files and directories with name containing -- if ARGV prune is all" do - a = (HOMEBREW_CACHE/"--a") - b = (HOMEBREW_CACHE/"b") - c = (HOMEBREW_CACHE/"c") - a.mkpath - b.mkpath - FileUtils.touch c + it "cleans up all files and directories" do + git = (HOMEBREW_CACHE/"gist--git") + gist = (HOMEBREW_CACHE/"gist") + svn = (HOMEBREW_CACHE/"gist--svn") + git.mkpath + gist.mkpath + FileUtils.touch svn allow(ARGV).to receive(:value).with("prune").and_return("all") - shutup do - described_class.cleanup_cache + begin + shutup do + described_class.cleanup_cache + end + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + ensure + FileUtils.rm_rf(git) + FileUtils.rm_rf(gist) + FileUtils.rm_rf(svn) + end + end + + it "raises error when formula name is ambiguous" do + bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") + FileUtils.touch bottle + (HOMEBREW_CELLAR/"foo/foo-0.2").mkpath + begin + described_class.cleanup_cache + ensure + FileUtils.rm_rf(bottle) end - expect(a).not_to exist - expect(b).to exist - expect(c).not_to exist end end end -- cgit v1.2.3 From 134539aa55af17be779bc05fc18e1fabceaeb3d0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 5 Aug 2017 06:06:33 +0530 Subject: Added tests for cleaning up old files in HOMEBREW_CACHE --- Library/Homebrew/test/cleanup_spec.rb | 61 +++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index da6796d5f..32ffbd357 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -64,24 +64,18 @@ describe Homebrew::Cleanup do end specify "::update_disk_cleanup_size" do - shutup do - described_class.instance_eval("@disk_cleanup_size = 0") - described_class.update_disk_cleanup_size(128) - end + described_class.instance_eval("@disk_cleanup_size = 0") + described_class.update_disk_cleanup_size(128) expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) end specify "::disk_cleanup_size" do - shutup do - described_class.instance_eval("@disk_cleanup_size = 0") - end + described_class.instance_eval("@disk_cleanup_size = 0") expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) end specify "::unremovable_kegs" do - shutup do - described_class.unremovable_kegs - end + described_class.unremovable_kegs expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) end @@ -173,9 +167,7 @@ describe Homebrew::Cleanup do FileUtils.touch svn allow(ARGV).to receive(:value).with("prune").and_return("all") begin - shutup do - described_class.cleanup_cache - end + described_class.cleanup_cache expect(git).not_to exist expect(gist).to exist expect(svn).not_to exist @@ -186,14 +178,41 @@ describe Homebrew::Cleanup do end end - it "raises error when formula name is ambiguous" do - bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") - FileUtils.touch bottle - (HOMEBREW_CELLAR/"foo/foo-0.2").mkpath - begin - described_class.cleanup_cache - ensure - FileUtils.rm_rf(bottle) + context "cleaning old files in HOMEBREW_CACHE" do + before(:each) do + @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") + @testball = (HOMEBREW_CACHE/"testball-0.0.1") + FileUtils.touch(@bottle) + FileUtils.touch(@testball) + (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath + FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") + end + + after(:each) do + FileUtils.rm_rf(@bottle) + FileUtils.rm_rf(@testball) + FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") + FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") + end + + it "cleans up file if outdated" do + allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) + described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist + end + + it "cleans up file if ARGV has -s and formula not installed" do + ARGV << "-s" + described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist + end + + it "cleans up file if stale" do + puts described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist end end end -- cgit v1.2.3 From 86f7d208d09c4ebb6e4ca3b4cbf82b563307d65d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 5 Aug 2017 19:36:35 +0530 Subject: Added tests for prune? --- Library/Homebrew/test/cleanup_spec.rb | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 32ffbd357..a66157976 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,22 +63,11 @@ describe Homebrew::Cleanup do end end - specify "::update_disk_cleanup_size" do - described_class.instance_eval("@disk_cleanup_size = 0") - described_class.update_disk_cleanup_size(128) - expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) - end - specify "::disk_cleanup_size" do described_class.instance_eval("@disk_cleanup_size = 0") expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) end - specify "::unremovable_kegs" do - described_class.unremovable_kegs - expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) - end - specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" @@ -178,7 +167,20 @@ describe Homebrew::Cleanup do end end - context "cleaning old files in HOMEBREW_CACHE" do + it "cleans up VCS checkout directories with modified time < prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + begin + described_class.cleanup_cache + expect(foo).not_to exist + ensure + FileUtils.rm_rf(foo) + end + end + + context "cleans old files in HOMEBREW_CACHE" do before(:each) do @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") @testball = (HOMEBREW_CACHE/"testball-0.0.1") @@ -216,4 +218,15 @@ describe Homebrew::Cleanup do end end end + + specify "::prune?" do + foo = mktmpdir/"foo.rb" + foo.mkpath + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + begin + expect(described_class.prune?(foo, days_default: "1")).to be_truthy + ensure + FileUtils.rm_rf(foo) + end + end end -- cgit v1.2.3 From 6b5e4bb938c38bf97e9fd31fde1813bf93fe1b4d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 8 Aug 2017 00:25:01 +0530 Subject: Use let over instance_var --- Library/Homebrew/test/cleanup_spec.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index a66157976..98cdb9bd0 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -181,18 +181,19 @@ describe Homebrew::Cleanup do end context "cleans old files in HOMEBREW_CACHE" do + let(:bottle) { (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") } + let(:testball) { (HOMEBREW_CACHE/"testball-0.0.1") } + before(:each) do - @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") - @testball = (HOMEBREW_CACHE/"testball-0.0.1") - FileUtils.touch(@bottle) - FileUtils.touch(@testball) + FileUtils.touch(bottle) + FileUtils.touch(testball) (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") end after(:each) do - FileUtils.rm_rf(@bottle) - FileUtils.rm_rf(@testball) + FileUtils.rm_rf(bottle) + FileUtils.rm_rf(testball) FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") end @@ -200,21 +201,21 @@ describe Homebrew::Cleanup do it "cleans up file if outdated" do allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end it "cleans up file if ARGV has -s and formula not installed" do ARGV << "-s" described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end it "cleans up file if stale" do puts described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end end end -- cgit v1.2.3 From e7c2efa42fbf1846ef32e86eb3bcd57482e399b4 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 8 Aug 2017 00:45:29 +0530 Subject: Corrected disk_cleanup_size test --- Library/Homebrew/test/cleanup_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 98cdb9bd0..b1bf3fb18 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -64,8 +64,8 @@ describe Homebrew::Cleanup do end specify "::disk_cleanup_size" do - described_class.instance_eval("@disk_cleanup_size = 0") - expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) + disk_cleanup_size = described_class.instance_variable_get(:@disk_cleanup_size) + expect(described_class.disk_cleanup_size).to eq(disk_cleanup_size) end specify "::cleanup_formula" do -- cgit v1.2.3 From ec30de69c3b3e1c3afb3638e0e13d3518148871d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 13 Aug 2017 04:21:26 +0530 Subject: Added tests for existence of files --- Library/Homebrew/test/cleanup_spec.rb | 108 +++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 35 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index b1bf3fb18..cf3af5d35 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,11 +63,6 @@ describe Homebrew::Cleanup do end end - specify "::disk_cleanup_size" do - disk_cleanup_size = described_class.instance_variable_get(:@disk_cleanup_size) - expect(described_class.disk_cleanup_size).to eq(disk_cleanup_size) - end - specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" @@ -109,14 +104,30 @@ describe Homebrew::Cleanup do expect(f4).to be_installed end - specify "::cleanup_logs" do - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" + describe "::cleanup_logs" do + before do + path.mkpath + end + + let(:path) { (HOMEBREW_LOGS/"delete_me") } + + it "cleans all logs if prune all" do + ARGV << "--prune=all" + described_class.cleanup_logs + expect(path).not_to exist + end - described_class.cleanup_logs + it "cleans up logs if older than 14 days" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 15) + described_class.cleanup_logs + expect(path).not_to exist + end - expect(path).not_to exist + it "does not clean up logs less than 14 days old" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + described_class.cleanup_logs + expect(path).to exist + end end describe "::cleanup_cache" do @@ -129,6 +140,15 @@ describe Homebrew::Cleanup do expect(incomplete).not_to exist end + it "cleans up 'glide_home'" do + glide_home = (HOMEBREW_CACHE/"glide_home") + glide_home.mkpath + + described_class.cleanup_cache + + expect(glide_home).not_to exist + end + it "cleans up 'java_cache'" do java_cache = (HOMEBREW_CACHE/"java_cache") java_cache.mkpath @@ -151,20 +171,28 @@ describe Homebrew::Cleanup do git = (HOMEBREW_CACHE/"gist--git") gist = (HOMEBREW_CACHE/"gist") svn = (HOMEBREW_CACHE/"gist--svn") + git.mkpath gist.mkpath FileUtils.touch svn + allow(ARGV).to receive(:value).with("prune").and_return("all") - begin - described_class.cleanup_cache - expect(git).not_to exist - expect(gist).to exist - expect(svn).not_to exist - ensure - FileUtils.rm_rf(git) - FileUtils.rm_rf(gist) - FileUtils.rm_rf(svn) - end + + described_class.cleanup_cache + + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + end + + it "does not clean up directories that are not VCS checkouts" do + git = (HOMEBREW_CACHE/"git") + git.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("all") + + described_class.cleanup_cache + + expect(git).to exist end it "cleans up VCS checkout directories with modified time < prune time" do @@ -172,12 +200,16 @@ describe Homebrew::Cleanup do foo.mkpath allow(ARGV).to receive(:value).with("prune").and_return("1") allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) - begin - described_class.cleanup_cache - expect(foo).not_to exist - ensure - FileUtils.rm_rf(foo) - end + described_class.cleanup_cache + expect(foo).not_to exist + end + + it "does not clean up VCS checkout directories with modified time >= prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + described_class.cleanup_cache + expect(foo).to exist end context "cleans old files in HOMEBREW_CACHE" do @@ -213,21 +245,27 @@ describe Homebrew::Cleanup do end it "cleans up file if stale" do - puts described_class.cleanup_cache + described_class.cleanup_cache expect(bottle).not_to exist expect(testball).not_to exist end end end - specify "::prune?" do - foo = mktmpdir/"foo.rb" - foo.mkpath - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) - begin + describe "::prune?" do + before do + foo.mkpath + end + + let(:foo) { mktmpdir/"foo.rb" } + + it "returns true when path_modified_time < days_default" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) expect(described_class.prune?(foo, days_default: "1")).to be_truthy - ensure - FileUtils.rm_rf(foo) + end + + it "returns true when path_modified_time >= days_default" do + expect(described_class.prune?(foo, days_default: "2")).to be_falsey end end end -- cgit v1.2.3 From 5f7a93bcebf2f18f4740f0fd5e676555880c5d71 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 19 Aug 2017 17:17:38 +0530 Subject: Corrected test name --- Library/Homebrew/test/cleanup_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index cf3af5d35..3e9cdc79c 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -105,12 +105,12 @@ describe Homebrew::Cleanup do end describe "::cleanup_logs" do + let(:path) { (HOMEBREW_LOGS/"delete_me") } + before do path.mkpath end - let(:path) { (HOMEBREW_LOGS/"delete_me") } - it "cleans all logs if prune all" do ARGV << "--prune=all" described_class.cleanup_logs @@ -264,7 +264,7 @@ describe Homebrew::Cleanup do expect(described_class.prune?(foo, days_default: "1")).to be_truthy end - it "returns true when path_modified_time >= days_default" do + it "returns false when path_modified_time >= days_default" do expect(described_class.prune?(foo, days_default: "2")).to be_falsey end end -- cgit v1.2.3 From 01714b17ee4abd08082ef5a37810a7b21ec80d6a Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 26 Aug 2017 02:01:45 +0530 Subject: Used let for sec_in_a_day and removed redundant after(:each) block --- Library/Homebrew/test/cleanup_spec.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 3e9cdc79c..da262c5ca 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -5,6 +5,7 @@ require "pathname" describe Homebrew::Cleanup do let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") } + let(:sec_in_a_day) { 60 * 60 * 24 } around(:each) do |example| begin @@ -118,13 +119,13 @@ describe Homebrew::Cleanup do end it "cleans up logs if older than 14 days" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 15) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 15) described_class.cleanup_logs expect(path).not_to exist end it "does not clean up logs less than 14 days old" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) described_class.cleanup_logs expect(path).to exist end @@ -199,7 +200,7 @@ describe Homebrew::Cleanup do foo = (HOMEBREW_CACHE/"--foo") foo.mkpath allow(ARGV).to receive(:value).with("prune").and_return("1") - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) described_class.cleanup_cache expect(foo).not_to exist end @@ -223,13 +224,6 @@ describe Homebrew::Cleanup do FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") end - after(:each) do - FileUtils.rm_rf(bottle) - FileUtils.rm_rf(testball) - FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") - FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") - end - it "cleans up file if outdated" do allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) described_class.cleanup_cache @@ -257,10 +251,10 @@ describe Homebrew::Cleanup do foo.mkpath end - let(:foo) { mktmpdir/"foo.rb" } + let(:foo) { HOMEBREW_CACHE/"foo" } it "returns true when path_modified_time < days_default" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) expect(described_class.prune?(foo, days_default: "1")).to be_truthy end -- cgit v1.2.3 From d91036e8912b31e3eb145b1cb3964a321a587c4f Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 28 Jul 2017 00:37:32 +0530 Subject: Added tests for last_revision_commit_of_file --- Library/Homebrew/test/utils/git_spec.rb | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Library/Homebrew/test/utils/git_spec.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb new file mode 100644 index 000000000..d4eb97820 --- /dev/null +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -0,0 +1,47 @@ +require "utils/git" + +describe Git do + before(:all) do + git = HOMEBREW_SHIMS_PATH/"scm/git" + file = "lib/blah.rb" + repo = Pathname.new("repo") + FileUtils.mkpath("repo/lib") + `#{git} init` + FileUtils.touch("repo/#{file}") + File.open(repo.to_s+"/"+file, "w") { |f| f.write("blah") } + `#{git} add repo/#{file}` + `#{git} commit -m"File added"` + @hash1 = `git rev-parse HEAD` + File.open(repo.to_s+"/"+file, "w") { |f| f.write("brew") } + `#{git} add repo/#{file}` + `#{git} commit -m"written to File"` + @hash2 = `git rev-parse HEAD` + end + + let(:file) { "lib/blah.rb" } + let(:repo) { Pathname.new("repo") } + + # after(:all) do + # FileUtils.rm_rf("repo") + # end + + describe "#last_revision_commit_of_file" do + it "sets args as --skip=1 when before_commit is nil" do + expect(described_class.last_revision_commit_of_file(repo, file)).to eq(@hash1[0..6]) + end + + it "sets args as --skip=1 when before_commit is nil" do + expect(described_class.last_revision_commit_of_file(repo, file, before_commit: "0..3")).to eq(@hash2[0..6]) + end + end + + describe "#last_revision_of_file" do + it "returns last revision of file" do + expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file)).to eq("blah") + end + + it "returns last revision of file based on before_commit" do + expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file, before_commit: "0..3")).to eq("brew") + end + end +end -- cgit v1.2.3 From 657b6ef7fb67231540bac9bcf4126ec27e8e1841 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 28 Jul 2017 02:02:40 +0530 Subject: Added tests for git_available? --- Library/Homebrew/test/utils/git_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index d4eb97820..39b28794a 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -45,3 +45,22 @@ describe Git do end end end + +describe Utils do + describe "::git_available?" do + it "returns true if git --version command succeeds" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) + expect(described_class.git_available?).to be_truthy + end + + it "returns false if git --version command does not succeed" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + expect(described_class.git_available?).to be_falsey + end + + it "returns git version if already set" do + described_class.instance_variable_set(:@git, true) + expect(described_class.git_available?).to be_truthy + end + end +end -- cgit v1.2.3 From 660617a35b81ccb223682f2267cd641d7baf31c6 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 28 Jul 2017 03:45:10 +0530 Subject: Added tests for Utils --- Library/Homebrew/test/utils/git_spec.rb | 116 +++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 39b28794a..37ca331e3 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -21,9 +21,9 @@ describe Git do let(:file) { "lib/blah.rb" } let(:repo) { Pathname.new("repo") } - # after(:all) do - # FileUtils.rm_rf("repo") - # end + after(:all) do + FileUtils.rm_rf("repo") + end describe "#last_revision_commit_of_file" do it "sets args as --skip=1 when before_commit is nil" do @@ -61,6 +61,116 @@ describe Utils do it "returns git version if already set" do described_class.instance_variable_set(:@git, true) expect(described_class.git_available?).to be_truthy + described_class.instance_variable_set(:@git, nil) + end + end + + describe "::git_path" do + context "when git is not available" do + before do + described_class.instance_variable_set(:@git, false) + end + + it "returns" do + expect(described_class.git_path).to eq(nil) + end + end + + context "when git is available" do + before do + described_class.instance_variable_set(:@git, true) + end + + it "returns path of git" do + expect(described_class.git_path).to eq("/Applications/Xcode.app/Contents/Developer/usr/bin/git") + end + + it "returns git_path if already set" do + described_class.instance_variable_set(:@git_path, "git") + expect(described_class.git_path).to eq("git") + described_class.instance_variable_set(:@git_path, nil) + end + end + end + + describe "::git_version" do + context "when git is not available" do + before do + described_class.instance_variable_set(:@git, false) + end + + it "returns" do + expect(described_class.git_path).to eq(nil) + end + end + + context "when git is available" do + before do + described_class.instance_variable_set(:@git, true) + end + + it "returns version of git" do + expect(described_class.git_version).not_to be_nil + end + + it "returns git_version if already set" do + described_class.instance_variable_set(:@git_version, "v1") + expect(described_class.git_version).to eq("v1") + described_class.instance_variable_set(:@git_version, nil) + end + end + end + + describe "::git_remote_exists" do + context "when git is not available" do + before do + described_class.instance_variable_set(:@git, false) + end + + it "returns true" do + expect(described_class.git_remote_exists("blah")).to be_truthy + end + end + + context "when git is available" do + before(:all) do + described_class.instance_variable_set(:@git, true) + git = HOMEBREW_SHIMS_PATH/"scm/git" + @repo = Pathname.new("hey") + FileUtils.mkpath("hey") + `cd #{@repo}` + `#{git} init` + `#{git} remote add origin git@github.com:Homebrew/brew` + `cd ..` + end + + after(:all) do + FileUtils.rm_rf(@repo) + end + + it "returns true when git remote exists" do + expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy + end + + it "returns false when git remote does not exist" do + expect(described_class.git_remote_exists("blah")).to be_falsey + end + end + end + + describe "::clear_git_available_cache" do + it "removes @git_path and @git_version if defined" do + described_class.clear_git_available_cache + expect(@git_path).to be_nil + expect(@git_version).to be_nil + end + + it "removes @git if defined" do + described_class.instance_variable_set(:@git, true) + described_class.clear_git_available_cache + expect(@git).to be_nil + expect(@git_path).to be_nil + expect(@git_version).to be_nil end end end -- cgit v1.2.3 From 4f0f55a7748b1fd477937d2e9c48a45f754ac725 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Mon, 31 Jul 2017 22:30:36 +0530 Subject: Used system command to run git commands --- Library/Homebrew/test/utils/git_spec.rb | 41 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 37ca331e3..46c8b1e4f 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -6,16 +6,18 @@ describe Git do file = "lib/blah.rb" repo = Pathname.new("repo") FileUtils.mkpath("repo/lib") - `#{git} init` - FileUtils.touch("repo/#{file}") - File.open(repo.to_s+"/"+file, "w") { |f| f.write("blah") } - `#{git} add repo/#{file}` - `#{git} commit -m"File added"` - @hash1 = `git rev-parse HEAD` - File.open(repo.to_s+"/"+file, "w") { |f| f.write("brew") } - `#{git} add repo/#{file}` - `#{git} commit -m"written to File"` - @hash2 = `git rev-parse HEAD` + shutup do + system "#{git} init" + FileUtils.touch("repo/#{file}") + File.open(repo.join("file").to_s, "w") { |f| f.write("blah") } + system "#{git} add repo/#{file}" + system "#{git} commit -m'File added'" + @hash1 = `git rev-parse HEAD` + File.open(repo.join("file").to_s, "w") { |f| f.write("brew") } + system "#{git} add repo/#{file}" + system "#{git} commit -m'written to File'" + @hash2 = `git rev-parse HEAD` + end end let(:file) { "lib/blah.rb" } @@ -37,11 +39,11 @@ describe Git do describe "#last_revision_of_file" do it "returns last revision of file" do - expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file)).to eq("blah") + expect(described_class.last_revision_of_file(repo, repo.join("file").to_s)).to eq("blah") end it "returns last revision of file based on before_commit" do - expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file, before_commit: "0..3")).to eq("brew") + expect(described_class.last_revision_of_file(repo, repo.join("file").to_s, before_commit: "0..3")).to eq("brew") end end end @@ -82,7 +84,8 @@ describe Utils do end it "returns path of git" do - expect(described_class.git_path).to eq("/Applications/Xcode.app/Contents/Developer/usr/bin/git") + allow(Utils).to receive(popen_read).with(HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path").and_return("git") + expect(described_class.git_path).to eq("git") end it "returns git_path if already set" do @@ -99,7 +102,7 @@ describe Utils do described_class.instance_variable_set(:@git, false) end - it "returns" do + it "returns nil" do expect(described_class.git_path).to eq(nil) end end @@ -138,10 +141,12 @@ describe Utils do git = HOMEBREW_SHIMS_PATH/"scm/git" @repo = Pathname.new("hey") FileUtils.mkpath("hey") - `cd #{@repo}` - `#{git} init` - `#{git} remote add origin git@github.com:Homebrew/brew` - `cd ..` + shutup do + system "cd #{@repo}" + system "#{git} init" + system "#{git} remote add origin git@github.com:Homebrew/brew" + system "cd .." + end end after(:all) do -- cgit v1.2.3 From abe78ebb8e75079da901ccbe908efdc9af0d0a78 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 1 Aug 2017 22:27:24 +0530 Subject: Removed shutup --- Library/Homebrew/test/utils/git_spec.rb | 107 +++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 37 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 46c8b1e4f..931699c1b 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -5,50 +5,71 @@ describe Git do git = HOMEBREW_SHIMS_PATH/"scm/git" file = "lib/blah.rb" repo = Pathname.new("repo") - FileUtils.mkpath("repo/lib") - shutup do - system "#{git} init" - FileUtils.touch("repo/#{file}") - File.open(repo.join("file").to_s, "w") { |f| f.write("blah") } - system "#{git} add repo/#{file}" - system "#{git} commit -m'File added'" - @hash1 = `git rev-parse HEAD` - File.open(repo.join("file").to_s, "w") { |f| f.write("brew") } - system "#{git} add repo/#{file}" - system "#{git} commit -m'written to File'" - @hash2 = `git rev-parse HEAD` - end + + (repo/"lib").mkpath + system git, "init" + FileUtils.touch("repo/#{file}") + + File.open(repo/file, "w") { |f| f.write("blah") } + system git, "add", repo/file + system git, "commit", "-m", "'File added'" + @h1 = `git rev-parse HEAD` + + File.open(repo/file, "w") { |f| f.write("brew") } + system git, "add", repo/file + system git, "commit", "-m", "'written to File'" + @h2 = `git rev-parse HEAD` end let(:file) { "lib/blah.rb" } let(:repo) { Pathname.new("repo") } + let(:hash1) { @h1[0..6] } + let(:hash2) { @h2[0..6] } after(:all) do FileUtils.rm_rf("repo") end describe "#last_revision_commit_of_file" do - it "sets args as --skip=1 when before_commit is nil" do - expect(described_class.last_revision_commit_of_file(repo, file)).to eq(@hash1[0..6]) + it "gives last revision commit when before_commit is nil" do + expect( + described_class.last_revision_commit_of_file(repo, file), + ).to eq(hash1) end - it "sets args as --skip=1 when before_commit is nil" do - expect(described_class.last_revision_commit_of_file(repo, file, before_commit: "0..3")).to eq(@hash2[0..6]) + it "gives revision commit based on before_commit when it is not nil" do + expect( + described_class.last_revision_commit_of_file(repo, + file, + before_commit: "0..3"), + ).to eq(hash2) end end describe "#last_revision_of_file" do it "returns last revision of file" do - expect(described_class.last_revision_of_file(repo, repo.join("file").to_s)).to eq("blah") + expect( + described_class.last_revision_of_file(repo, + repo/file), + ).to eq("blah") end it "returns last revision of file based on before_commit" do - expect(described_class.last_revision_of_file(repo, repo.join("file").to_s, before_commit: "0..3")).to eq("brew") + expect( + described_class.last_revision_of_file(repo, repo/file, + before_commit: "0..3"), + ).to eq("brew") end end end describe Utils do + before(:each) do + if described_class.instance_variable_defined?(:@git) + described_class.send(:remove_instance_variable, :@git) + end + end + describe "::git_available?" do it "returns true if git --version command succeeds" do allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) @@ -73,7 +94,7 @@ describe Utils do described_class.instance_variable_set(:@git, false) end - it "returns" do + it "returns nil" do expect(described_class.git_path).to eq(nil) end end @@ -84,8 +105,7 @@ describe Utils do end it "returns path of git" do - allow(Utils).to receive(popen_read).with(HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path").and_return("git") - expect(described_class.git_path).to eq("git") + expect(described_class.git_path).to end_with("git") end it "returns git_path if already set" do @@ -138,23 +158,27 @@ describe Utils do context "when git is available" do before(:all) do described_class.instance_variable_set(:@git, true) - git = HOMEBREW_SHIMS_PATH/"scm/git" - @repo = Pathname.new("hey") - FileUtils.mkpath("hey") - shutup do - system "cd #{@repo}" - system "#{git} init" - system "#{git} remote add origin git@github.com:Homebrew/brew" - system "cd .." - end end after(:all) do - FileUtils.rm_rf(@repo) + if described_class.instance_variable_defined?(:@git) + described_class.send(:remove_instance_variable, :@git) + end end - it "returns true when git remote exists" do + it "returns true when git remote exists", :needs_network do + git = HOMEBREW_SHIMS_PATH/"scm/git" + repo = Pathname.new("hey") + repo.mkpath + + system "cd", repo + system git, "init" + system git, "remote", "add", "origin", "git@github.com:Homebrew/brew" + system "cd .." + expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy + + FileUtils.rm_rf(repo) end it "returns false when git remote does not exist" do @@ -166,16 +190,25 @@ describe Utils do describe "::clear_git_available_cache" do it "removes @git_path and @git_version if defined" do described_class.clear_git_available_cache + expect(@git_path).to be_nil expect(@git_version).to be_nil end it "removes @git if defined" do described_class.instance_variable_set(:@git, true) - described_class.clear_git_available_cache - expect(@git).to be_nil - expect(@git_path).to be_nil - expect(@git_version).to be_nil + + begin + described_class.clear_git_available_cache + + expect(@git).to be_nil + expect(@git_path).to be_nil + expect(@git_version).to be_nil + ensure + if described_class.instance_variable_defined?(:@git) + described_class.send(:remove_instance_variable, :@git) + end + end end end end -- cgit v1.2.3 From 372a42230510d24e539f2763ed148f7ba3ae7991 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 12 Aug 2017 02:33:48 +0530 Subject: Added tests for ensure_git_installed when git is available or homebrew/core is unavailable --- Library/Homebrew/test/utils/git_spec.rb | 157 ++++++++++++-------------------- 1 file changed, 59 insertions(+), 98 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 931699c1b..994e23725 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -3,45 +3,44 @@ require "utils/git" describe Git do before(:all) do git = HOMEBREW_SHIMS_PATH/"scm/git" - file = "lib/blah.rb" - repo = Pathname.new("repo") - (repo/"lib").mkpath + @file = "lib/blah.rb" + @repo = Pathname.new("repo") + + (@repo/"lib").mkpath system git, "init" - FileUtils.touch("repo/#{file}") + FileUtils.touch(@repo/@file) - File.open(repo/file, "w") { |f| f.write("blah") } - system git, "add", repo/file + File.open(@repo/@file, "w") { |f| f.write("blah") } + system git, "add", @repo/@file system git, "commit", "-m", "'File added'" @h1 = `git rev-parse HEAD` - File.open(repo/file, "w") { |f| f.write("brew") } - system git, "add", repo/file + File.open(@repo/@file, "w") { |f| f.write("brew") } + system git, "add", @repo/@file system git, "commit", "-m", "'written to File'" @h2 = `git rev-parse HEAD` end - let(:file) { "lib/blah.rb" } - let(:repo) { Pathname.new("repo") } let(:hash1) { @h1[0..6] } let(:hash2) { @h2[0..6] } after(:all) do - FileUtils.rm_rf("repo") + FileUtils.rm_rf(@repo) end describe "#last_revision_commit_of_file" do it "gives last revision commit when before_commit is nil" do expect( - described_class.last_revision_commit_of_file(repo, file), + described_class.last_revision_commit_of_file(@repo, @file), ).to eq(hash1) end it "gives revision commit based on before_commit when it is not nil" do expect( - described_class.last_revision_commit_of_file(repo, - file, - before_commit: "0..3"), + described_class.last_revision_commit_of_file(@repo, + @file, + before_commit: hash2), ).to eq(hash2) end end @@ -49,14 +48,14 @@ describe Git do describe "#last_revision_of_file" do it "returns last revision of file" do expect( - described_class.last_revision_of_file(repo, - repo/file), + described_class.last_revision_of_file(@repo, + @repo/@file), ).to eq("blah") end it "returns last revision of file based on before_commit" do expect( - described_class.last_revision_of_file(repo, repo/file, + described_class.last_revision_of_file(@repo, @repo/@file, before_commit: "0..3"), ).to eq("brew") end @@ -72,100 +71,71 @@ describe Utils do describe "::git_available?" do it "returns true if git --version command succeeds" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) expect(described_class.git_available?).to be_truthy end it "returns false if git --version command does not succeed" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") expect(described_class.git_available?).to be_falsey end - - it "returns git version if already set" do - described_class.instance_variable_set(:@git, true) - expect(described_class.git_available?).to be_truthy - described_class.instance_variable_set(:@git, nil) - end end describe "::git_path" do - context "when git is not available" do - before do - described_class.instance_variable_set(:@git, false) - end - - it "returns nil" do - expect(described_class.git_path).to eq(nil) - end + it "returns nil when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + expect(described_class.git_path).to eq(nil) end - context "when git is available" do - before do - described_class.instance_variable_set(:@git, true) - end - - it "returns path of git" do - expect(described_class.git_path).to end_with("git") - end - - it "returns git_path if already set" do - described_class.instance_variable_set(:@git_path, "git") - expect(described_class.git_path).to eq("git") - described_class.instance_variable_set(:@git_path, nil) - end + it "returns path of git when git is available" do + expect(described_class.git_path).to end_with("git") end end describe "::git_version" do - context "when git is not available" do - before do - described_class.instance_variable_set(:@git, false) - end + it "returns nil when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + expect(described_class.git_path).to eq(nil) + end - it "returns nil" do - expect(described_class.git_path).to eq(nil) - end + it "returns version of git when git is available" do + expect(described_class.git_version).not_to be_nil end + end - context "when git is available" do + describe "::ensure_git_installed!" do + it "returns nil if git already available" do + expect(described_class.ensure_git_installed!).to be_nil + end + + context "when git is not already available" do before do - described_class.instance_variable_set(:@git, true) + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") end - it "returns version of git" do - expect(described_class.git_version).not_to be_nil + it "can't install brewed git if homebrew/core is unavailable" do + allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) + expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") end - it "returns git_version if already set" do - described_class.instance_variable_set(:@git_version, "v1") - expect(described_class.git_version).to eq("v1") - described_class.instance_variable_set(:@git_version, nil) + it "raises error if can't install git" do + stub_const("HOMEBREW_BREW_FILE", mktmpdir/"brew") + expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") + end + + it "installs git" do + allow(Homebrew).to receive(:_system).with(any_args).and_return(true) + described_class.ensure_git_installed! end end end describe "::git_remote_exists" do - context "when git is not available" do - before do - described_class.instance_variable_set(:@git, false) - end - - it "returns true" do - expect(described_class.git_remote_exists("blah")).to be_truthy - end + it "returns true when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + expect(described_class.git_remote_exists("blah")).to be_truthy end context "when git is available" do - before(:all) do - described_class.instance_variable_set(:@git, true) - end - - after(:all) do - if described_class.instance_variable_defined?(:@git) - described_class.send(:remove_instance_variable, :@git) - end - end - it "returns true when git remote exists", :needs_network do git = HOMEBREW_SHIMS_PATH/"scm/git" repo = Pathname.new("hey") @@ -173,10 +143,10 @@ describe Utils do system "cd", repo system git, "init" - system git, "remote", "add", "origin", "git@github.com:Homebrew/brew" + system git, "remote", "add", "origin", "http://github.com/Homebrew/homebrew.github.io" system "cd .." - expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy + expect(described_class.git_remote_exists("http://github.com/Homebrew/homebrew.github.io")).to be_truthy FileUtils.rm_rf(repo) end @@ -191,24 +161,15 @@ describe Utils do it "removes @git_path and @git_version if defined" do described_class.clear_git_available_cache - expect(@git_path).to be_nil - expect(@git_version).to be_nil + expect(described_class.instance_variable_get(:@git_path)).to be_nil + expect(described_class.instance_variable_get(:@git_version)).to be_nil end it "removes @git if defined" do - described_class.instance_variable_set(:@git, true) - - begin - described_class.clear_git_available_cache - - expect(@git).to be_nil - expect(@git_path).to be_nil - expect(@git_version).to be_nil - ensure - if described_class.instance_variable_defined?(:@git) - described_class.send(:remove_instance_variable, :@git) - end - end + described_class.git_available? + described_class.clear_git_available_cache + + expect(described_class.instance_variable_get(:@git)).to be_nil end end end -- cgit v1.2.3 From c695dffd373aefaaa84f1cf1098d23bd9f1d998d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 25 Aug 2017 17:19:34 +0530 Subject: Added clear git version cache method --- Library/Homebrew/test/utils/git_spec.rb | 72 +++++++++++++++------------------ 1 file changed, 32 insertions(+), 40 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 994e23725..65dd3bf41 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -1,44 +1,39 @@ require "utils/git" describe Git do - before(:all) do + before(:each) do git = HOMEBREW_SHIMS_PATH/"scm/git" - @file = "lib/blah.rb" - @repo = Pathname.new("repo") + @file = "blah.rb" - (@repo/"lib").mkpath - system git, "init" - FileUtils.touch(@repo/@file) + HOMEBREW_CACHE.cd do + system git, "init" - File.open(@repo/@file, "w") { |f| f.write("blah") } - system git, "add", @repo/@file - system git, "commit", "-m", "'File added'" - @h1 = `git rev-parse HEAD` + File.open(@file, "w") { |f| f.write("blah") } + system git, "add", HOMEBREW_CACHE/@file + system git, "commit", "-m", "'File added'" + @h1 = `git rev-parse HEAD` - File.open(@repo/@file, "w") { |f| f.write("brew") } - system git, "add", @repo/@file - system git, "commit", "-m", "'written to File'" - @h2 = `git rev-parse HEAD` + File.open(@file, "w") { |f| f.write("brew") } + system git, "add", HOMEBREW_CACHE/@file + system git, "commit", "-m", "'written to File'" + @h2 = `git rev-parse HEAD` + end end let(:hash1) { @h1[0..6] } let(:hash2) { @h2[0..6] } - after(:all) do - FileUtils.rm_rf(@repo) - end - describe "#last_revision_commit_of_file" do it "gives last revision commit when before_commit is nil" do expect( - described_class.last_revision_commit_of_file(@repo, @file), + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, @file), ).to eq(hash1) end it "gives revision commit based on before_commit when it is not nil" do expect( - described_class.last_revision_commit_of_file(@repo, + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, @file, before_commit: hash2), ).to eq(hash2) @@ -48,14 +43,14 @@ describe Git do describe "#last_revision_of_file" do it "returns last revision of file" do expect( - described_class.last_revision_of_file(@repo, - @repo/@file), + described_class.last_revision_of_file(HOMEBREW_CACHE, + HOMEBREW_CACHE/@file), ).to eq("blah") end it "returns last revision of file based on before_commit" do expect( - described_class.last_revision_of_file(@repo, @repo/@file, + described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/@file, before_commit: "0..3"), ).to eq("brew") end @@ -64,9 +59,7 @@ end describe Utils do before(:each) do - if described_class.instance_variable_defined?(:@git) - described_class.send(:remove_instance_variable, :@git) - end + described_class.clear_git_version_cache end describe "::git_available?" do @@ -75,14 +68,14 @@ describe Utils do end it "returns false if git --version command does not succeed" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_available?).to be_falsey end end describe "::git_path" do it "returns nil when git is not available" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_path).to eq(nil) end @@ -93,7 +86,7 @@ describe Utils do describe "::git_version" do it "returns nil when git is not available" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_path).to eq(nil) end @@ -109,7 +102,7 @@ describe Utils do context "when git is not already available" do before do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") end it "can't install brewed git if homebrew/core is unavailable" do @@ -118,7 +111,7 @@ describe Utils do end it "raises error if can't install git" do - stub_const("HOMEBREW_BREW_FILE", mktmpdir/"brew") + stub_const("HOMEBREW_BREW_FILE", HOMEBREW_PREFIX/"bin/brew") expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") end @@ -131,24 +124,23 @@ describe Utils do describe "::git_remote_exists" do it "returns true when git is not available" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_remote_exists("blah")).to be_truthy end context "when git is available" do it "returns true when git remote exists", :needs_network do git = HOMEBREW_SHIMS_PATH/"scm/git" - repo = Pathname.new("hey") + url = "http://github.com/Homebrew/homebrew.github.io" + repo = HOMEBREW_CACHE/"hey" repo.mkpath - system "cd", repo - system git, "init" - system git, "remote", "add", "origin", "http://github.com/Homebrew/homebrew.github.io" - system "cd .." - - expect(described_class.git_remote_exists("http://github.com/Homebrew/homebrew.github.io")).to be_truthy + repo.cd do + system git, "init" + system git, "remote", "add", "origin", url + end - FileUtils.rm_rf(repo) + expect(described_class.git_remote_exists(url)).to be_truthy end it "returns false when git remote does not exist" do -- cgit v1.2.3 From 13fb14a95f6d0c909451e94e96b14447ccabdfcb Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 01:52:21 +0530 Subject: Added tests fir utils/svn --- Library/Homebrew/test/utils/svn_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Library/Homebrew/test/utils/svn_spec.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb new file mode 100644 index 000000000..35f8917aa --- /dev/null +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -0,0 +1,33 @@ +require "utils/svn" + +describe Utils do + describe "#self.svn_available?" do + it "processes value when @svn is not defined" do + expect(described_class.svn_available?).to be_truthy + end + + it "returns value of @svn when @svn is defined" do + described_class.instance_variable_set(:@svn, true) + expect(described_class.svn_available?).to be_truthy + end + end + + describe "#self.svn_remote_exists" do + let(:url) { "https://dl.bintray.com/homebrew/mirror/" } + + it "gives true when @svn is false" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + described_class.instance_variable_set(:@svn, false) + expect(described_class.svn_remote_exists(url)).to be_truthy + end + + it "gives false when url is obscure" do + expect(described_class.svn_remote_exists(url)).to be_falsy + end + + it "gives true when quiet_system succeeds with given url" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) + expect(described_class.svn_remote_exists(url)).to be_truthy + end + end +end -- cgit v1.2.3 From cf96d8d9700d0869d52add879f25179509b3773c Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 04:18:43 +0530 Subject: Improved tests for svn_available? --- Library/Homebrew/test/utils/svn_spec.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb index 35f8917aa..3ff9ac655 100644 --- a/Library/Homebrew/test/utils/svn_spec.rb +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -2,11 +2,17 @@ require "utils/svn" describe Utils do describe "#self.svn_available?" do - it "processes value when @svn is not defined" do + it "returns true if svn --version command succeeds" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) expect(described_class.svn_available?).to be_truthy end - it "returns value of @svn when @svn is defined" do + it "returns false if svn --version command does not succeed" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + expect(described_class.svn_available?).to be_falsey + end + + it "returns svn version if already set" do described_class.instance_variable_set(:@svn, true) expect(described_class.svn_available?).to be_truthy end @@ -15,17 +21,16 @@ describe Utils do describe "#self.svn_remote_exists" do let(:url) { "https://dl.bintray.com/homebrew/mirror/" } - it "gives true when @svn is false" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + it "returns true when svn is not available" do described_class.instance_variable_set(:@svn, false) expect(described_class.svn_remote_exists(url)).to be_truthy end - it "gives false when url is obscure" do - expect(described_class.svn_remote_exists(url)).to be_falsy + it "returns false when remote does not exist" do + expect(described_class.svn_remote_exists(url)).to be_falsey end - it "gives true when quiet_system succeeds with given url" do + it "returns true when remote exists" do allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) expect(described_class.svn_remote_exists(url)).to be_truthy end -- cgit v1.2.3 From 53be6bb4bd69eaf8cc8e5c3c1ac9ecd1ddb1582c Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 04:40:27 +0530 Subject: Added check for svn availability --- Library/Homebrew/test/utils/svn_spec.rb | 43 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb index 3ff9ac655..6f841cc92 100644 --- a/Library/Homebrew/test/utils/svn_spec.rb +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -2,37 +2,40 @@ require "utils/svn" describe Utils do describe "#self.svn_available?" do - it "returns true if svn --version command succeeds" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) - expect(described_class.svn_available?).to be_truthy - end - - it "returns false if svn --version command does not succeed" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) - expect(described_class.svn_available?).to be_falsey + before(:each) do + if described_class.instance_variable_defined?(:@svn) + described_class.send(:remove_instance_variable, :@svn) + end end - it "returns svn version if already set" do - described_class.instance_variable_set(:@svn, true) + it "returns svn version if svn available" do expect(described_class.svn_available?).to be_truthy end end describe "#self.svn_remote_exists" do - let(:url) { "https://dl.bintray.com/homebrew/mirror/" } - it "returns true when svn is not available" do - described_class.instance_variable_set(:@svn, false) - expect(described_class.svn_remote_exists(url)).to be_truthy + allow(Utils).to receive(:svn_available?).and_return(false) + expect(described_class.svn_remote_exists("blah")).to be_truthy end - it "returns false when remote does not exist" do - expect(described_class.svn_remote_exists(url)).to be_falsey - end + context "when svn is available" do + before do + allow(Utils).to receive(:svn_available?).and_return(true) + end + + it "returns false when remote does not exist" do + expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_falsey + end + + it "returns true when remote exists", :needs_network do + remote = "http://github.com/Homebrew/install" + svn = HOMEBREW_SHIMS_PATH/"scm/svn" + + HOMEBREW_CACHE.cd { system svn, "checkout", remote } - it "returns true when remote exists" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) - expect(described_class.svn_remote_exists(url)).to be_truthy + expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_truthy + end end end end -- cgit v1.2.3 From d533973395e549c558c2282a46acc12df4e7d6da Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 24 Aug 2017 01:31:12 +0530 Subject: Used clear_svn_version_cache to remove @svn --- Library/Homebrew/test/utils/svn_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb index 6f841cc92..4edb365a0 100644 --- a/Library/Homebrew/test/utils/svn_spec.rb +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -3,9 +3,7 @@ require "utils/svn" describe Utils do describe "#self.svn_available?" do before(:each) do - if described_class.instance_variable_defined?(:@svn) - described_class.send(:remove_instance_variable, :@svn) - end + described_class.clear_svn_version_cache end it "returns svn version if svn available" do -- cgit v1.2.3 From a4d4da64aab707e2f39fcc32fec6418cc39e8010 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 04:41:49 +0530 Subject: Added tests for os_prefix_ci --- Library/Homebrew/test/utils/analytics_spec.rb | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Library/Homebrew/test/utils/analytics_spec.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb new file mode 100644 index 000000000..cee09e286 --- /dev/null +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -0,0 +1,34 @@ +require "utils/analytics" + +describe Utils::Analytics do + describe "::os_prefix_ci" do + context "when anonymous_os_prefix_ci is not set" do + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do + expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") + end + + it "includes CI when ENV['CI'] is set" do + allow(ENV).to receive(:[]).with("CI").and_return("true") + expect(described_class.os_prefix_ci).to include("CI") + end + + it "does not include prefix when HOMEBREW_PREFIX is usr/local" do + allow(HOMEBREW_PREFIX).to receive(:to_s).and_return("/usr/local") + expect(described_class.os_prefix_ci).not_to include("non-/usr/local") + end + end + + context "when anonymous_os_prefix_ci is set" do + let(:anonymous_os_prefix_ci) { "macOS 10.11.6, non-/usr/local, CI" } + + it "returns anonymous_os_prefix_ci" do + described_class.instance_variable_set(:@anonymous_os_prefix_ci, anonymous_os_prefix_ci) + expect(described_class.os_prefix_ci).to eq(anonymous_os_prefix_ci) + end + end + end + + describe "::" do + + end +end \ No newline at end of file -- cgit v1.2.3 From 2660f5ae3ea5e0ce466e6f9b3b736a12ad3a341a Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 17:47:28 +0530 Subject: Added tests for report and report_event --- Library/Homebrew/test/utils/analytics_spec.rb | 50 ++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index cee09e286..96a9a4f7f 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -1,19 +1,27 @@ require "utils/analytics" +require "formula_installer" describe Utils::Analytics do describe "::os_prefix_ci" do context "when anonymous_os_prefix_ci is not set" do + before(:each) do + if described_class.instance_variable_defined?(:@anonymous_os_prefix_ci) + described_class.send(:remove_instance_variable, :@anonymous_os_prefix_ci) + end + end + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do + stub_const("HOMEBREW_PREFIX", "blah") expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") end it "includes CI when ENV['CI'] is set" do - allow(ENV).to receive(:[]).with("CI").and_return("true") + ENV["CI"] = "true" expect(described_class.os_prefix_ci).to include("CI") end it "does not include prefix when HOMEBREW_PREFIX is usr/local" do - allow(HOMEBREW_PREFIX).to receive(:to_s).and_return("/usr/local") + stub_const("HOMEBREW_PREFIX", "/usr/local") expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end end @@ -28,7 +36,39 @@ describe Utils::Analytics do end end - describe "::" do - + describe "::report_event" do + let(:f) { formula { url "foo-1.0" } } + let(:options) { FormulaInstaller.new(f).display_options(f) } + let(:action) { "#{f.full_name} #{options}".strip } + + context "when ENV vars is set" do + it "returns nil when HOMEBREW_NO_ANALYTICS is true" do + ENV["HOMEBREW_NO_ANALYTICS"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + end + + context "when ENV vars are nil" do + before do + ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is not set" do + expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) + end + end end -end \ No newline at end of file +end -- cgit v1.2.3 From a4d8d7ba576e1418a18eb605b8eddc6c10447608 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 15 Aug 2017 21:05:52 +0530 Subject: Added tests for report_build_error --- Library/Homebrew/test/utils/analytics_spec.rb | 47 +++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 96a9a4f7f..eb675b370 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -25,15 +25,6 @@ describe Utils::Analytics do expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end end - - context "when anonymous_os_prefix_ci is set" do - let(:anonymous_os_prefix_ci) { "macOS 10.11.6, non-/usr/local, CI" } - - it "returns anonymous_os_prefix_ci" do - described_class.instance_variable_set(:@anonymous_os_prefix_ci, anonymous_os_prefix_ci) - expect(described_class.os_prefix_ci).to eq(anonymous_os_prefix_ci) - end - end end describe "::report_event" do @@ -66,9 +57,45 @@ describe Utils::Analytics do ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil end - it "returns nil when HOMEBREW_ANALYTICS_DEBUG is not set" do + it "returns waiting thread when HOMEBREW_ANALYTICS_DEBUG is not set" do expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) end end end + + describe "::report_build_error" do + context "when tap is installed" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { formula { url "foo-1.0" } } + + it "reports event if BuildError raised for a formula with a public remote repository" do + allow_any_instance_of(Tap).to receive(:custom_remote?).and_return(false) + expect(described_class).to respond_to(:report_event) + described_class.report_build_error(err) + end + + it "does not report event if BuildError raised for a formula with a private remote repository" do + expect(described_class.report_build_error(err)).to be_nil + end + end + + context "when formula does not have a tap" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { double(Formula, name: "foo", path: "blah", tap: nil) } + + it "does not report event if BuildError is raised" do + expect(described_class.report_build_error(err)).to be_nil + end + end + + context "when tap for a formula is not installed" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { double(Formula, name: "foo", path: "blah", tap: CoreTap.instance) } + + it "does not report event if BuildError is raised" do + allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) + expect(described_class.report_build_error(err)).to be_nil + end + end + end end -- cgit v1.2.3 From 59f3c661a31d2d0d7f649fbe75daae171b2cfd23 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 20 Aug 2017 22:04:09 +0530 Subject: Used ENV.delete to remove set ENV vars --- Library/Homebrew/test/utils/analytics_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index eb675b370..228c352b4 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -44,8 +44,8 @@ describe Utils::Analytics do end it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do - ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil - ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") + ENV.delete("HOMEBREW_NO_ANALYTICS") ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" expect(described_class.report_event("install", action)).to be_nil end @@ -53,8 +53,8 @@ describe Utils::Analytics do context "when ENV vars are nil" do before do - ENV["HOMEBREW_NO_ANALYTICS"] = nil - ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") + ENV.delete("HOMEBREW_NO_ANALYTICS") end it "returns waiting thread when HOMEBREW_ANALYTICS_DEBUG is not set" do -- cgit v1.2.3 From db28126b4a31c3d8ff910283fc50ab4de1f63db2 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 24 Aug 2017 01:44:48 +0530 Subject: Used clear_anonymous_os_prefix_ci_cache to remove @anonymous_os_prefix_ci --- Library/Homebrew/test/utils/analytics_spec.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 228c352b4..bb6cda0b1 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -5,9 +5,7 @@ describe Utils::Analytics do describe "::os_prefix_ci" do context "when anonymous_os_prefix_ci is not set" do before(:each) do - if described_class.instance_variable_defined?(:@anonymous_os_prefix_ci) - described_class.send(:remove_instance_variable, :@anonymous_os_prefix_ci) - end + described_class.clear_anonymous_os_prefix_ci_cache end it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do @@ -20,7 +18,7 @@ describe Utils::Analytics do expect(described_class.os_prefix_ci).to include("CI") end - it "does not include prefix when HOMEBREW_PREFIX is usr/local" do + it "does not include prefix when HOMEBREW_PREFIX is /usr/local" do stub_const("HOMEBREW_PREFIX", "/usr/local") expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end @@ -50,17 +48,6 @@ describe Utils::Analytics do expect(described_class.report_event("install", action)).to be_nil end end - - context "when ENV vars are nil" do - before do - ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") - ENV.delete("HOMEBREW_NO_ANALYTICS") - end - - it "returns waiting thread when HOMEBREW_ANALYTICS_DEBUG is not set" do - expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) - end - end end describe "::report_build_error" do -- cgit v1.2.3 From 784250d55099f16d8b9c3553a219d603c200cb6b Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 25 Aug 2017 17:55:54 +0530 Subject: Used already existing clear_git_available_cache to remove @git --- Library/Homebrew/test/utils/git_spec.rb | 37 +++++++++------------------------ 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 65dd3bf41..e511212f4 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -4,37 +4,36 @@ describe Git do before(:each) do git = HOMEBREW_SHIMS_PATH/"scm/git" - @file = "blah.rb" - HOMEBREW_CACHE.cd do system git, "init" - File.open(@file, "w") { |f| f.write("blah") } - system git, "add", HOMEBREW_CACHE/@file + File.open(file, "w") { |f| f.write("blah") } + system git, "add", HOMEBREW_CACHE/file system git, "commit", "-m", "'File added'" @h1 = `git rev-parse HEAD` - File.open(@file, "w") { |f| f.write("brew") } - system git, "add", HOMEBREW_CACHE/@file + File.open(file, "w") { |f| f.write("brew") } + system git, "add", HOMEBREW_CACHE/file system git, "commit", "-m", "'written to File'" @h2 = `git rev-parse HEAD` end end + let(:file) { "blah.rb" } let(:hash1) { @h1[0..6] } let(:hash2) { @h2[0..6] } describe "#last_revision_commit_of_file" do it "gives last revision commit when before_commit is nil" do expect( - described_class.last_revision_commit_of_file(HOMEBREW_CACHE, @file), + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, file), ).to eq(hash1) end it "gives revision commit based on before_commit when it is not nil" do expect( described_class.last_revision_commit_of_file(HOMEBREW_CACHE, - @file, + file, before_commit: hash2), ).to eq(hash2) end @@ -44,13 +43,13 @@ describe Git do it "returns last revision of file" do expect( described_class.last_revision_of_file(HOMEBREW_CACHE, - HOMEBREW_CACHE/@file), + HOMEBREW_CACHE/file), ).to eq("blah") end it "returns last revision of file based on before_commit" do expect( - described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/@file, + described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/file, before_commit: "0..3"), ).to eq("brew") end @@ -59,7 +58,7 @@ end describe Utils do before(:each) do - described_class.clear_git_version_cache + described_class.clear_git_available_cache end describe "::git_available?" do @@ -148,20 +147,4 @@ describe Utils do end end end - - describe "::clear_git_available_cache" do - it "removes @git_path and @git_version if defined" do - described_class.clear_git_available_cache - - expect(described_class.instance_variable_get(:@git_path)).to be_nil - expect(described_class.instance_variable_get(:@git_version)).to be_nil - end - - it "removes @git if defined" do - described_class.git_available? - described_class.clear_git_available_cache - - expect(described_class.instance_variable_get(:@git)).to be_nil - end - end end -- cgit v1.2.3 From 68dd0ac918639e6c1cbe7ba1800cda3646ba4e0b Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 31 Aug 2017 03:03:00 +0200 Subject: Changed warning message as recommended by @reitermarkus --- Library/Homebrew/test/cask/cli/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 06f0b4b32..85bb42c56 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -30,7 +30,7 @@ describe Hbc::CLI::Search, :cask do local-caffeine local-transmission EOS - .and output(/^Warning: Online search failed: reason/).to_stderr + .and output(/^Warning: Error searching on GitHub: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do -- cgit v1.2.3 From a26cde8299c998043bf7073341b029b609135e8a Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Thu, 31 Aug 2017 22:29:36 -0700 Subject: search_remote_tap spec: fix test offline Even though we stub the JSON response, the method being tested always returns [] immediately if HOMEBREW_NO_GITHUB_API is set. --- Library/Homebrew/test/cmd/search_remote_tap_spec.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb index b0beb122c..eb256b924 100644 --- a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb +++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb @@ -2,6 +2,9 @@ require "cmd/search" describe Homebrew do specify "#search_taps" do + # Otherwise the tested method returns [], regardless of our stub + ENV.delete("HOMEBREW_NO_GITHUB_API") + json_response = { "items" => [ { -- cgit v1.2.3 From 8e5ad9ad9be3587001fb92b4367ddb7cc4c7fc8c Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 2 Sep 2017 02:29:56 +0200 Subject: Minor tests formatting change --- Library/Homebrew/test/cask/cli/search_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 85bb42c56..6dc980590 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -42,18 +42,16 @@ describe Hbc::CLI::Search, :cask do end it "doesn't output anything to non-TTY stdout when there are no matches" do - expect { - Hbc::CLI::Search.run("foo-bar-baz") - }.to not_to_output.to_stdout - .and not_to_output.to_stderr + expect { Hbc::CLI::Search.run("foo-bar-baz") } + .to not_to_output.to_stdout + .and not_to_output.to_stderr end it "lists all Casks available offline with no search term" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) - expect { - Hbc::CLI::Search.run - }.to output(/local-caffeine/).to_stdout.as_tty - .and not_to_output.to_stderr + expect { Hbc::CLI::Search.run } + .to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do -- cgit v1.2.3 From b582ed513b3b28197369cb3cf808e9c4025ee581 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 5 Aug 2017 14:58:09 +0530 Subject: audit: Add tests for rubocop methods in line_cop.rb --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 271 +++++++++++++++++++++++ 1 file changed, 271 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index b0ed8f4d1..31aafbcf8 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -200,5 +200,276 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with invalid rebuild" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + rebuild 0 + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + end + EOS + + expected_offenses = [{ message: "'rebuild 0' should be removed", + severity: :convention, + line: 5, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with OS.linux? check" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + if OS.linux? + nil + end + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + end + EOS + + expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS", + severity: :convention, + line: 5, + column: 7, + source: source }] + + inspect_source(cop, source, "/homebrew-core/") + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with fails_with :llvm" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + fails_with :llvm do + build 2335 + cause "foo" + end + end + EOS + + expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed", + severity: :convention, + line: 7, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with def test" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + + def test + assert_equals "1", "1" + end + end + EOS + + expected_offenses = [{ message: "Use new-style test definitions (test do)", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with def options" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + + def options + [["--bar", "desc"]] + end + end + EOS + + expected_offenses = [{ message: "Use new-style option definitions", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with deprecated skip_clean call" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + skip_clean :all + end + EOS + + expected_offenses = [{ message: <<-EOS.undent.chomp, + `skip_clean :all` is deprecated; brew no longer strips symbols + Pass explicit paths to prevent Homebrew from removing empty folders. + EOS + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with build.universal?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build.universal? + "foo" + end + end + EOS + + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.", + severity: :convention, + line: 4, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ENV.universal_binary" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.universal_binary + end + end + EOS + + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.", + severity: :convention, + line: 5, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ENV.universal_binary" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.x11 + end + end + EOS + + expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"', + severity: :convention, + line: 5, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ruby-macho alternatives" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"', + severity: :convention, + line: 4, + column: 10, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with npm install without language::Node args" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + expected_offenses = [{ message: "Use Language::Node for npm install args", + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end end end -- cgit v1.2.3 From 337d5c64708f3ad1d7074e17b1cd5be24e0ee488 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 30 Aug 2017 15:48:41 +0530 Subject: audit: Fetch formula name from file path rather than class name in cops --- Library/Homebrew/test/rubocops/conflicts_cop_spec.rb | 4 ++-- Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb index 4fbab6c9e..3af0f9669 100644 --- a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb @@ -22,7 +22,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo@2.0.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -36,7 +36,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do desc 'Bar' end EOS - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo@2.0.rb") expect(cop.offenses).to eq([]) end end diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index 74ce478fb..48342e8bc 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -37,7 +37,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do msg = <<-EOS.undent Description is too long. "name: desc" should be less than 80 characters. - Length is calculated as Foo + desc. (currently 95) + Length is calculated as foo + desc. (currently 95) EOS expected_offenses = [{ message: msg, severity: :convention, @@ -45,7 +45,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -62,7 +62,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do msg = <<-EOS.undent Description is too long. "name: desc" should be less than 80 characters. - Length is calculated as Foo + desc. (currently 98) + Length is calculated as foo + desc. (currently 98) EOS expected_offenses = [{ message: msg, severity: :convention, @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -156,7 +156,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -176,7 +176,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(cop, source, "/homebrew-core/Formula/foo.rb") expect(corrected_source).to eq(correct_source) end end -- cgit v1.2.3 From 4ec26aea4025d19e70cdf59da6dfd7be3a389e44 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 4 Sep 2017 13:47:05 +0530 Subject: audit: Port audit_class to rubocop, add tests and autocorrect --- Library/Homebrew/test/dev-cmd/audit_spec.rb | 64 ------------------- Library/Homebrew/test/rubocops/class_cop_spec.rb | 81 ++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 64 deletions(-) create mode 100644 Library/Homebrew/test/rubocops/class_cop_spec.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 037865fdf..3e99bd06b 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -150,70 +150,6 @@ describe FormulaAuditor do end end - describe "#audit_class" do - specify "missing test" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems).to eq([]) - - fa = formula_auditor "foo", <<-EOS.undent, strict: true - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems).to eq(["A `test do` test block should be added"]) - end - - specify "GithubGistFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < GithubGistFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["GithubGistFormula is deprecated, use Formula instead"]) - end - - specify "ScriptFileFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < ScriptFileFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["ScriptFileFormula is deprecated, use Formula instead"]) - end - - specify "AmazonWebServicesFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < AmazonWebServicesFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["AmazonWebServicesFormula is deprecated, use Formula instead"]) - end - end - describe "#line_problems" do specify "pkgshare" do fa = formula_auditor "foo", <<-EOS.undent, strict: true diff --git a/Library/Homebrew/test/rubocops/class_cop_spec.rb b/Library/Homebrew/test/rubocops/class_cop_spec.rb new file mode 100644 index 000000000..676dd4f6e --- /dev/null +++ b/Library/Homebrew/test/rubocops/class_cop_spec.rb @@ -0,0 +1,81 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/class_cop" + +describe RuboCop::Cop::FormulaAudit::ClassName do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "with deprecated inheritance" do + formulas = [{ + "class" => "GithubGistFormula", + }, { + "class" => "ScriptFileFormula", + }, { + "class" => "AmazonWebServicesFormula", + }] + + formulas.each do |formula| + source = <<-EOS.undent + class Foo < #{formula["class"]} + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "#{formula["class"]} is deprecated, use Formula instead", + severity: :convention, + line: 1, + column: 12, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| + expect_offense(expected, actual) + end + end + end + + it "with deprecated inheritance and autocorrect" do + source = <<-EOS.undent + class Foo < AmazonWebServicesFormula + url 'http://example.com/foo-1.0.tgz' + end + EOS + corrected_source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + new_source = autocorrect_source(cop, source) + expect(new_source).to eq(corrected_source) + end + end +end + +describe RuboCop::Cop::FormulaAuditStrict::Test do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "without a test block" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + expected_offenses = [{ message: described_class::MSG, + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + end +end -- cgit v1.2.3 From a6d1ddf32611109b3284b045fdc5123c40e23b9e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 6 Sep 2017 11:06:46 +0000 Subject: git_spec.rb: use HTTPS for Git remote test --- Library/Homebrew/test/utils/git_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index e511212f4..48fc1338e 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -130,7 +130,7 @@ describe Utils do context "when git is available" do it "returns true when git remote exists", :needs_network do git = HOMEBREW_SHIMS_PATH/"scm/git" - url = "http://github.com/Homebrew/homebrew.github.io" + url = "https://github.com/Homebrew/homebrew.github.io" repo = HOMEBREW_CACHE/"hey" repo.mkpath -- cgit v1.2.3 From 49d2d7b94d85dd150956ea14d66a34870d2f70fd Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 5 Sep 2017 17:44:27 +0100 Subject: home_spec: use different test formula. Instead of `testball` use a formula named `testballhome` to avoid this clashing with any other formula named testball. --- Library/Homebrew/test/cmd/home_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cmd/home_spec.rb b/Library/Homebrew/test/cmd/home_spec.rb index 5a4070492..cf9453af2 100644 --- a/Library/Homebrew/test/cmd/home_spec.rb +++ b/Library/Homebrew/test/cmd/home_spec.rb @@ -7,10 +7,10 @@ describe "brew home", :integration_test do end it "opens the homepage for a given Formula" do - setup_test_formula "testball" + setup_test_formula "testballhome" - expect { brew "home", "testball", "HOMEBREW_BROWSER" => "echo" } - .to output("#{Formula["testball"].homepage}\n").to_stdout + expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" } + .to output("#{Formula["testballhome"].homepage}\n").to_stdout .and not_to_output.to_stderr .and be_a_success end -- cgit v1.2.3 From 7b1cf6df5a73b03ad87333636df627c86de50599 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:30:30 +0000 Subject: spelling: comparison --- Library/Homebrew/test/cask/depends_on_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index c603cf6e1..fb92a9a24 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -31,7 +31,7 @@ describe "Satisfy Dependencies and Requirements", :cask do it { is_expected.not_to raise_error } end - context "given a comparisson" do + context "given a comparison" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-comparison.rb") } it { is_expected.not_to raise_error } end -- cgit v1.2.3 From 70ce9fe7f9b96acc62ad622a564ac41b7cad9521 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:35:30 +0000 Subject: spelling: intermediate --- Library/Homebrew/test/pathname_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/pathname_spec.rb b/Library/Homebrew/test/pathname_spec.rb index 0bc19c5ac..69314e5f4 100644 --- a/Library/Homebrew/test/pathname_spec.rb +++ b/Library/Homebrew/test/pathname_spec.rb @@ -295,7 +295,7 @@ describe FileUtils do let(:dst) { mktmpdir } describe "#mkdir" do - it "creates indermediate directories" do + it "creates intermediate directories" do described_class.mkdir dst/"foo/bar/baz" do expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created" expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure" -- cgit v1.2.3 From a337620d97d9e3ae4575ff79768c0ef14d82fd0b Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:38:28 +0000 Subject: spelling: omitted --- Library/Homebrew/test/requirement_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 71372aa69..11a3da8f4 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -48,7 +48,7 @@ describe Requirement do it { is_expected.to be_fatal } end - context "#fatal is ommitted" do + context "#fatal is omitted" do it { is_expected.not_to be_fatal } end end @@ -184,7 +184,7 @@ describe Requirement do it { is_expected.to have_a_default_formula } end - context "#default_formula ommitted" do + context "#default_formula omitted" do it { is_expected.not_to have_a_default_formula } end end -- cgit v1.2.3 From b9a33b03a4812e87c88dc009dc0661d4fc7d46fc Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:39:18 +0000 Subject: spelling: parameters --- Library/Homebrew/test/utils/github_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 9322898ee..a132894f9 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -2,7 +2,7 @@ require "utils/github" describe GitHub do describe "::search_code", :needs_network do - it "queries GitHub code with the passed paramaters" do + it "queries GitHub code with the passed parameters" do results = subject.search_code(repo: "Homebrew/brew", path: "/", filename: "readme", language: "markdown") -- cgit v1.2.3 From 130fec083166a9d29545155a26a105dcd3dfb192 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:40:29 +0000 Subject: spelling: preserves --- Library/Homebrew/test/dependency_expansion_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/dependency_expansion_spec.rb b/Library/Homebrew/test/dependency_expansion_spec.rb index f955237a9..d6ecdf552 100644 --- a/Library/Homebrew/test/dependency_expansion_spec.rb +++ b/Library/Homebrew/test/dependency_expansion_spec.rb @@ -69,7 +69,7 @@ describe Dependency do end end - it "merges dependencies and perserves env_proc" do + it "merges dependencies and preserves env_proc" do env_proc = double dep = described_class.new("foo", [], env_proc) allow(dep).to receive(:to_formula).and_return(double(deps: [], name: "foo")) -- cgit v1.2.3 From 8e4150b20b811175d4778ec73f3018b8ef878742 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:42:24 +0000 Subject: spelling: should --- Library/Homebrew/test/cmd/commands_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index cf6f56740..46ed3ddcf 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -68,7 +68,7 @@ describe Homebrew do expect(cmds).to include("t1"), "Executable files should be included" expect(cmds).to include("t2"), "Executable Ruby files should be included" - expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shoudn't be included" + expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shouldn't be included" expect(cmds).not_to include("t4"), "Non-executable files shouldn't be included" end end -- cgit v1.2.3 From 194a2c2adebdcd585fcff781841725b13a91d28a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 10 Sep 2017 21:56:12 +0200 Subject: Make `brew cask search` spec deterministic. --- Library/Homebrew/test/cask/cli/search_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 6dc980590..3d58e6a15 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -4,6 +4,8 @@ describe Hbc::CLI::Search, :cask do end it "lists the available Casks that match the search term" do + allow(GitHub).to receive(:search_code).and_return([]) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout.as_tty @@ -14,6 +16,8 @@ describe Hbc::CLI::Search, :cask do end it "outputs a plain list when stdout is not a TTY" do + allow(GitHub).to receive(:search_code).and_return([]) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout @@ -24,6 +28,7 @@ describe Hbc::CLI::Search, :cask do it "returns matches even when online search failed" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout -- cgit v1.2.3 From 53ecdd843f6e6d6dd93e09a5394de3c31bc0e51a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 6 Apr 2017 00:33:31 +0200 Subject: Treat every `Artifact` instance as a single artifact. --- .../Homebrew/test/cask/artifact/alt_target_spec.rb | 2 +- Library/Homebrew/test/cask/artifact/app_spec.rb | 21 +++++++++-------- Library/Homebrew/test/cask/artifact/binary_spec.rb | 21 +++++++++++------ .../test/cask/artifact/generic_artifact_spec.rb | 12 +++++----- .../test/cask/artifact/nested_container_spec.rb | 3 ++- Library/Homebrew/test/cask/artifact/pkg_spec.rb | 8 +++---- .../test/cask/artifact/postflight_block_spec.rb | 6 +++-- .../test/cask/artifact/preflight_block_spec.rb | 6 +++-- Library/Homebrew/test/cask/artifact/suite_spec.rb | 4 +++- .../test/cask/artifact/two_apps_correct_spec.rb | 2 +- .../test/cask/artifact/uninstall_no_zap_spec.rb | 2 +- .../cask/artifact/uninstall_zap_shared_examples.rb | 26 +++++++++++----------- Library/Homebrew/test/cask/audit_spec.rb | 9 ++------ Library/Homebrew/test/cask/cli/info_spec.rb | 10 ++++----- Library/Homebrew/test/cask/cli/list_spec.rb | 3 ++- Library/Homebrew/test/cask/dsl_spec.rb | 24 +++++++++++--------- 16 files changed, 85 insertions(+), 74 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index 9e8d83bb4..02be796ed 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -3,7 +3,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 0add472e2..f67ffd31b 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -2,13 +2,13 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } let(:command) { Hbc::SystemCommand } let(:force) { false } - let(:app) { Hbc::Artifact::App.new(cask, command: command, force: force) } + let(:app) { described_class.for_cask(cask).first } let(:source_path) { cask.staged_path.join("Caffeine.app") } let(:target_path) { Hbc.appdir.join("Caffeine.app") } - let(:install_phase) { app.install_phase } - let(:uninstall_phase) { app.uninstall_phase } + let(:install_phase) { app.install_phase(command: command, force: force) } + let(:uninstall_phase) { app.uninstall_phase(command: command, force: force) } before(:each) do InstallHelper.install_without_artifacts(cask) @@ -105,8 +105,8 @@ describe Hbc::Artifact::App, :cask do describe "target is user-owned but contains read-only files" do before(:each) do - system "/usr/bin/touch", "--", "#{target_path}/foo" - system "/bin/chmod", "--", "0555", target_path + FileUtils.touch "#{target_path}/foo" + FileUtils.chmod 0555, target_path end it "overwrites the existing app" do @@ -138,7 +138,7 @@ describe Hbc::Artifact::App, :cask do end after(:each) do - system "/bin/chmod", "--", "0755", target_path + FileUtils.chmod 0755, target_path end end end @@ -206,8 +206,8 @@ describe Hbc::Artifact::App, :cask do end describe "summary" do - let(:description) { app.summary[:english_description] } - let(:contents) { app.summary[:contents] } + let(:description) { app.class.english_description } + let(:contents) { app.summarize_installed } it "returns the correct english_description" do expect(description).to eq("Apps") @@ -217,14 +217,13 @@ describe Hbc::Artifact::App, :cask do it "returns the path to the app" do install_phase - expect(contents).to eq(["#{target_path} (#{target_path.abv})"]) + expect(contents).to eq("#{target_path} (#{target_path.abv})") end end describe "app is missing" do it "returns a warning and the supposed path to the app" do - expect(contents.size).to eq(1) - expect(contents[0]).to match(/.*Missing App.*: #{target_path}/) + expect(contents).to match(/.*Missing App.*: #{target_path}/) end end end diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index ce00e3935..5ffaca861 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -26,7 +26,8 @@ describe Hbc::Artifact::Binary, :cask do end it "links the binary to the proper directory" do - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist @@ -45,7 +46,8 @@ describe Hbc::Artifact::Binary, :cask do expect(FileUtils).to receive(:chmod) .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink expect(expected_path.readlink).to be_executable @@ -56,7 +58,8 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.touch expected_path expect { - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } }.to raise_error(Hbc::CaskError) expect(expected_path).not_to be :symlink? @@ -65,7 +68,8 @@ describe Hbc::Artifact::Binary, :cask do it "clobbers an existing symlink" do expected_path.make_symlink("/tmp") - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(File.readlink(expected_path)).not_to eq("/tmp") end @@ -73,7 +77,8 @@ describe Hbc::Artifact::Binary, :cask do it "creates parent directory if it doesn't exist" do FileUtils.rmdir Hbc.binarydir - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path.exist?).to be true end @@ -86,8 +91,10 @@ describe Hbc::Artifact::Binary, :cask do } it "links the binary to the proper directory" do - Hbc::Artifact::App.new(cask).install_phase - Hbc::Artifact::Binary.new(cask).install_phase + Hbc::Artifact::App.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index cb2ef9850..bec8c2742 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Artifact, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } let(:install_phase) { - -> { Hbc::Artifact::Artifact.new(cask).install_phase } + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path) { cask.staged_path.join("Caffeine.app") } @@ -12,11 +12,11 @@ describe Hbc::Artifact::Artifact, :cask do InstallHelper.install_without_artifacts(cask) end - describe "with no target" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") } - - it "fails to install with no target" do - expect(install_phase).to raise_error(Hbc::CaskInvalidError) + context "without target" do + it "fails to load" do + expect { + Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") + }.to raise_error(Hbc::CaskInvalidError, /target required for Generic Artifact/) end end diff --git a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb index be7ba5ff8..41d143764 100644 --- a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb +++ b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb @@ -5,7 +5,8 @@ describe Hbc::Artifact::NestedContainer, :cask do InstallHelper.install_without_artifacts(c) end - Hbc::Artifact::NestedContainer.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory end diff --git a/Library/Homebrew/test/cask/artifact/pkg_spec.rb b/Library/Homebrew/test/cask/artifact/pkg_spec.rb index 3e62616ea..c6a45c49a 100644 --- a/Library/Homebrew/test/cask/artifact/pkg_spec.rb +++ b/Library/Homebrew/test/cask/artifact/pkg_spec.rb @@ -8,7 +8,7 @@ describe Hbc::Artifact::Pkg, :cask do describe "install_phase" do it "runs the system installer on the specified pkgs" do - pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + pkg = described_class.for_cask(cask).first expect(fake_system_command).to receive(:run!).with( "/usr/sbin/installer", @@ -17,7 +17,7 @@ describe Hbc::Artifact::Pkg, :cask do print_stdout: true, ) - pkg.install_phase + pkg.install_phase(command: fake_system_command) end end @@ -25,7 +25,7 @@ describe Hbc::Artifact::Pkg, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") } it "passes the choice changes xml to the system installer" do - pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + pkg = described_class.for_cask(cask).first file = double(path: Pathname.new("/tmp/choices.xml")) @@ -57,7 +57,7 @@ describe Hbc::Artifact::Pkg, :cask do print_stdout: true, ) - pkg.install_phase + pkg.install_phase(command: fake_system_command) end end end diff --git a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb index 51b1431f0..4a44bb59b 100644 --- a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb @@ -11,7 +11,8 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::Postflight) @@ -30,7 +31,8 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.new(cask).uninstall_phase + described_class.for_cask(cask) + .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::UninstallPostflight) diff --git a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb index b13c4ab9d..d7d4e72d9 100644 --- a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb @@ -11,7 +11,8 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::Preflight @@ -30,7 +31,8 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.new(cask).uninstall_phase + described_class.for_cask(cask) + .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::UninstallPreflight diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 8c217a9e0..2f913fecc 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -1,7 +1,9 @@ describe Hbc::Artifact::Suite, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") } - let(:install_phase) { -> { Hbc::Artifact::Suite.new(cask).install_phase } } + let(:install_phase) { + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + } let(:target_path) { Hbc.appdir.join("Caffeine") } let(:source_path) { cask.staged_path.join("Caffeine") } diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index a1fdd3b74..f6e0d3c97 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -3,7 +3,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index 8cd0b1e41..d6a8393da 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Zap, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } let(:zap_artifact) { - Hbc::Artifact::Zap.new(cask) + described_class.for_cask(cask).first } before(:each) do diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 0e522bc21..06eec4a01 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -1,12 +1,12 @@ shared_examples "#uninstall_phase or #zap_phase" do - let(:artifact_name) { described_class.artifact_name } - let(:artifact) { described_class.new(cask, command: fake_system_command) } + let(:artifact_dsl_key) { described_class.dsl_key } + let(:artifact) { described_class.for_cask(cask).first } let(:fake_system_command) { Hbc::FakeSystemCommand } - subject { artifact.public_send(:"#{artifact_name}_phase") } + subject { artifact.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) } context "using :launchctl" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-launchctl.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-launchctl.rb") } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } let(:unknown_response) { "launchctl list returned unknown response\n" } @@ -61,7 +61,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :pkgutil" do let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-pkgutil.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-pkgutil.rb") } let(:main_pkg_id) { "my.fancy.package.main" } let(:agent_pkg_id) { "my.fancy.package.agent" } @@ -85,7 +85,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :kext" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-kext.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-kext.rb") } let(:kext_id) { "my.fancy.package.kernelextension" } it "is supported" do @@ -110,7 +110,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :quit" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-quit.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-quit.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:quit_application_script) do %Q(tell application id "#{bundle_id}" to quit) @@ -130,7 +130,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :signal" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-signal.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-signal.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } let(:unix_pids) { [12_345, 67_890] } @@ -170,10 +170,10 @@ shared_examples "#uninstall_phase or #zap_phase" do end let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-#{directive}.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-#{directive}.rb") } before(:each) do - allow_any_instance_of(Hbc::Artifact::UninstallBase).to receive(:trash_paths) + allow_any_instance_of(Hbc::Artifact::AbstractUninstall).to receive(:trash_paths) .and_wrap_original do |method, *args| result = method.call(*args) FileUtils.rm_rf result.stdout.split("\0") @@ -196,7 +196,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :rmdir" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-rmdir.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-rmdir.rb") } let(:empty_directory) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") } let(:ds_store) { empty_directory.join(".DS_Store") } @@ -223,7 +223,7 @@ shared_examples "#uninstall_phase or #zap_phase" do [:script, :early_script].each do |script_type| context "using #{script_type.inspect}" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:token) { "with-#{artifact_name}-#{script_type}".tr("_", "-") } + let(:token) { "with-#{artifact_dsl_key}-#{script_type}".tr("_", "-") } let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } @@ -250,7 +250,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :login_item" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-login-item.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-login-item.rb") } it "is supported" do Hbc::FakeSystemCommand.expects_command( diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index ddc773e3e..7e140acb2 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -265,19 +265,14 @@ describe Hbc::Audit, :cask do end describe "generic artifact checks" do - context "with no target" do - let(:cask_token) { "generic-artifact-no-target" } - it { is_expected.to fail_with(/target required for generic artifact/) } - end - context "with relative target" do let(:cask_token) { "generic-artifact-relative-target" } - it { is_expected.to fail_with(/target must be absolute path for generic artifact/) } + it { is_expected.to fail_with(/target must be absolute path for Generic Artifact/) } end context "with absolute target" do let(:cask_token) { "generic-artifact-absolute-target" } - it { should_not fail_with(/target required for generic artifact/) } + it { should_not fail_with(/target required for Generic Artifact/) } end end diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index bffe900ec..aec7080de 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -10,7 +10,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) EOS end @@ -24,7 +24,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) local-transmission: 2.61 http://example.com/local-transmission Not installed @@ -32,7 +32,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Transmission.app (app) + Transmission.app (App) EOS } @@ -60,7 +60,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) ==> Caveats Here are some things you might want to know. @@ -86,7 +86,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) EOS end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index ecca3035f..fd6997f41 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -48,7 +48,8 @@ describe Hbc::CLI::List, :cask do it "lists the installed files for those Casks" do casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile)) - Hbc::Artifact::App.new(transmission).install_phase + Hbc::Artifact::App.for_cask(transmission) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect { Hbc::CLI::List.run("local-transmission", "local-caffeine") diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 7f2207a87..aec1e917f 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -186,12 +186,12 @@ describe Hbc::DSL, :cask do app "Bar.app" end - expect(Array(cask.artifacts[:app])).to eq([["Foo.app"], ["Bar.app"]]) + expect(cask.artifacts[:app].map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) end it "allow app stanzas to be empty" do cask = Hbc::Cask.new("cask-with-no-apps") - expect(Array(cask.artifacts[:app])).to eq([]) + expect(cask.artifacts[:app]).to be_empty end end @@ -219,7 +219,7 @@ describe Hbc::DSL, :cask do pkg "Bar.pkg" end - expect(Array(cask.artifacts[:pkg])).to eq([["Foo.pkg"], ["Bar.pkg"]]) + expect(cask.artifacts[:pkg].map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) end end @@ -471,10 +471,10 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts[:installer].first.script[:executable]).to eq("/usr/bin/true") - expect(cask.artifacts[:installer].first.script[:args]).to eq(["--flag"]) - expect(cask.artifacts[:installer].to_a[1].script[:executable]).to eq("/usr/bin/false") - expect(cask.artifacts[:installer].to_a[1].script[:args]).to eq(["--flag"]) + expect(cask.artifacts[:installer].first.path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts[:installer].first.args[:args]).to eq(["--flag"]) + expect(cask.artifacts[:installer].to_a[1].path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts[:installer].to_a[1].args[:args]).to eq(["--flag"]) end end @@ -482,7 +482,9 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-manual" } it "allows installer manual to be specified" do - expect(cask.artifacts[:installer].first.manual).to eq("Caffeine.app") + installer = cask.artifacts[:installer].first + expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) + expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) end end end @@ -492,7 +494,7 @@ describe Hbc::DSL, :cask do let(:token) { "stage-only" } it "allows stage_only stanza to be specified" do - expect(cask.artifacts[:stage_only].first).to eq([true]) + expect(cask.artifacts[:stage_only]).not_to be_empty end end @@ -518,7 +520,7 @@ describe Hbc::DSL, :cask do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts[:binary].first).to eq(["#{Hbc.appdir}/some/path"]) + expect(cask.artifacts[:binary].first.source).to eq(Hbc.appdir/"some/path") end end @@ -531,7 +533,7 @@ describe Hbc::DSL, :cask do binary "#{appdir}/some/path" end - expect(cask.artifacts[:binary].first).to eq(["#{original_appdir}/some/path"]) + expect(cask.artifacts[:binary].first.source).to eq(original_appdir/"some/path") ensure Hbc.appdir = original_appdir end -- cgit v1.2.3 From b0c98ba6319e0e53cc0a262dd08bbb339d4bd7b5 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 4 Aug 2017 14:59:18 +0200 Subject: Fix `_stanza`. --- Library/Homebrew/test/cask/conflicts_with_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/conflicts_with_spec.rb b/Library/Homebrew/test/cask/conflicts_with_spec.rb index 0dc51cb2d..00dc252fe 100644 --- a/Library/Homebrew/test/cask/conflicts_with_spec.rb +++ b/Library/Homebrew/test/cask/conflicts_with_spec.rb @@ -8,7 +8,7 @@ describe "conflicts_with", :cask do Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb") } - it "installs the dependency of a Cask and the Cask itself", :focus do + it "installs the dependency of a Cask and the Cask itself" do Hbc::Installer.new(local_caffeine).install expect(local_caffeine).to be_installed -- cgit v1.2.3 From ef67b77d95c6cad9e1ba027189a44876119d1739 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 11 Sep 2017 08:37:15 +0200 Subject: Make Cask commands fail early if a Cask is not found. --- Library/Homebrew/test/cask/cli/audit_spec.rb | 4 +++- Library/Homebrew/test/cask/cli/cat_spec.rb | 3 +-- Library/Homebrew/test/cask/cli/create_spec.rb | 2 +- Library/Homebrew/test/cask/cli/edit_spec.rb | 2 +- Library/Homebrew/test/cask/cli/fetch_spec.rb | 2 +- Library/Homebrew/test/cask/cli/install_spec.rb | 18 +++++------------- Library/Homebrew/test/cask/cli/uninstall_spec.rb | 9 +++------ Library/Homebrew/test/cask/cli/zap_spec.rb | 3 +-- 8 files changed, 16 insertions(+), 27 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 01f506c8c..30ab437cb 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,8 +1,10 @@ describe Hbc::CLI::Audit, :cask do - let(:cask) { double("cask", token: nil) } + let(:cask) { Hbc::Cask.new(nil) } describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do + expect(cask).to be_a Hbc::Cask + allow(Hbc).to receive(:all).and_return([cask, cask]) expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb index b726a0b36..5a4b29c6f 100644 --- a/Library/Homebrew/test/cask/cli/cat_spec.rb +++ b/Library/Homebrew/test/cask/cli/cat_spec.rb @@ -35,8 +35,7 @@ describe Hbc::CLI::Cat, :cask do it "raises an exception when the Cask does not exist" do expect { Hbc::CLI::Cat.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Cat incomplete.") + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb index d77b0a2aa..17d426f78 100644 --- a/Library/Homebrew/test/cask/cli/create_spec.rb +++ b/Library/Homebrew/test/cask/cli/create_spec.rb @@ -39,7 +39,7 @@ describe Hbc::CLI::Create, :cask do it "raises an exception when more than one Cask is given" do expect { described_class.run("additional-cask", "another-cask") - }.to raise_error(/Only one Cask can be created at a time./) + }.to raise_error(/Only one Cask can be created at a time\./) end it "raises an exception when the Cask already exists" do diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index 5d5cbf4b9..51542807f 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -12,7 +12,7 @@ describe Hbc::CLI::Edit, :cask do it "raises an error when given more than one argument" do expect { described_class.new("local-caffeine", "local-transmission") - }.to raise_error(/Only one Cask can be created at a time./) + }.to raise_error(/Only one Cask can be edited at a time\./) end it "raises an exception when the Cask doesnt exist" do diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb index f71c23fb6..faaa69b35 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -42,7 +42,7 @@ describe Hbc::CLI::Fetch, :cask do it "properly handles Casks that are not present" do expect { Hbc::CLI::Fetch.run("notacask") - }.to raise_error(Hbc::CaskError, "Fetch incomplete.") + }.to raise_error(Hbc::CaskUnavailableError) end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index 64feacce9..e30489789 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -56,27 +56,19 @@ describe Hbc::CLI::Install, :cask do it "properly handles Casks that are not present" do expect { Hbc::CLI::Install.run("notacask") - }.to raise_error(Hbc::CaskError, "Install incomplete.") + }.to raise_error(Hbc::CaskUnavailableError) end it "returns a suggestion for a misspelled Cask" do expect { - begin - Hbc::CLI::Install.run("localcaffeine") - rescue Hbc::CaskError - nil - end - }.to output(/Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean:\nlocal-caffeine/).to_stderr + Hbc::CLI::Install.run("localcaffeine") + }.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/) end it "returns multiple suggestions for a Cask fragment" do expect { - begin - Hbc::CLI::Install.run("local-caf") - rescue Hbc::CaskError - nil - end - }.to output(/Cask 'local-caf' is unavailable: No Cask with this name exists\. Did you mean one of:\nlocal-caffeine/).to_stderr + Hbc::CLI::Install.run("local") + }.to raise_error(Hbc::CaskUnavailableError, /Cask 'local' is unavailable: No Cask with this name exists\. Did you mean one of these\?\nlocal-caffeine\nlocal-transmission/) end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 1a1c57e88..2ec506839 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -16,14 +16,12 @@ describe Hbc::CLI::Uninstall, :cask do it "shows an error when a bad Cask is provided" do expect { Hbc::CLI::Uninstall.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "shows an error when a Cask is provided that's not installed" do expect { Hbc::CLI::Uninstall.run("local-caffeine") } - .to output(/is not installed/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + .to raise_error(Hbc::CaskNotInstalledError, /is not installed/) end it "tries anyway on a non-present Cask when --force is given" do @@ -76,8 +74,7 @@ describe Hbc::CLI::Uninstall, :cask do Hbc.appdir.join("MyFancyApp.app").rmtree expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") } - .to output(/does not exist/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/) expect(cask).to be_installed diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index fdc5b4125..502bf8e69 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -1,8 +1,7 @@ describe Hbc::CLI::Zap, :cask do it "shows an error when a bad Cask is provided" do expect { Hbc::CLI::Zap.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Zap incomplete.") + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "can zap and unlink multiple Casks at once" do -- cgit v1.2.3 From e12d2746b65d46f07e3ecc737d07926118dfb278 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 15 Sep 2017 08:06:58 +0100 Subject: os/mac/diagnostic: allow custom Ruby for devs. This avoids `brew doctor` warnings on High Sierra but in general this is a good idea for future versions and to allow Homebrew developers to test things out with different versions of Ruby. --- Library/Homebrew/test/os/mac/diagnostic_spec.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/os/mac/diagnostic_spec.rb b/Library/Homebrew/test/os/mac/diagnostic_spec.rb index d6186e46b..83d95c2ef 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_spec.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_spec.rb @@ -47,15 +47,10 @@ describe Homebrew::Diagnostic::Checks do end specify "#check_ruby_version" do - allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.13")) - stub_const("RUBY_VERSION", "2.3.3p222") + allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.12")) + stub_const("RUBY_VERSION", "1.8.6") expect(subject.check_ruby_version) - .to match <<-EOS.undent - Ruby version 2.3.3p222 is unsupported on 10.13. Homebrew - is developed and tested on Ruby 2.0, and may not work correctly - on other Rubies. Patches are accepted as long as they don't cause breakage - on supported Rubies. - EOS + .to match "Ruby version 1.8.6 is unsupported on 10.12" end end -- cgit v1.2.3 From acf1b278ae0c27f19e7d20a9d23c005201dc818c Mon Sep 17 00:00:00 2001 From: Dan Wendorf Date: Sat, 8 Jul 2017 19:33:44 -0700 Subject: List cask full-names `brew cask list` supports the `--full-name` flag which will include the tap name for casks not part of the core caskroom/cask tap. For example, if cask "foo-beta" is installed from the caskroom/versions cask, `brew cask list --full-name` will report the name as "caskroom/versions/foo-beta". --- Library/Homebrew/test/cask/cask_spec.rb | 34 ++++++++++++++++++++++ Library/Homebrew/test/cask/cli/list_spec.rb | 20 +++++++++++++ .../fixtures/third-party/Casks/third-party-cask.rb | 9 ++++++ .../helper/spec/shared_context/homebrew_cask.rb | 8 +++++ Library/Homebrew/test/utils_spec.rb | 29 ++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index a6ecc207f..5858a7c6d 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -171,4 +171,38 @@ describe Hbc::Cask, :cask do end end end + + describe "full_name" do + context "when it is a core cask" do + it "is the cask token" do + c = Hbc::CaskLoader.load("local-caffeine") + expect(c.full_name).to eq("local-caffeine") + end + end + + context "when it is from a non-core tap" do + it "returns the fully-qualified name of the cask" do + c = Hbc::CaskLoader.load("third-party/tap/third-party-cask") + expect(c.full_name).to eq("third-party/tap/third-party-cask") + end + end + + context "when it is from no known tap" do + it "retuns the cask token" do + file = Tempfile.new(%w[tapless-cask .rb]) + + begin + cask_name = File.basename(file.path, ".rb") + file.write "cask '#{cask_name}'" + file.close + + c = Hbc::CaskLoader.load(file.path) + expect(c.full_name).to eq(cask_name) + ensure + file.close + file.unlink + end + end + end + end end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index fd6997f41..d2d7efd3b 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -14,6 +14,26 @@ describe Hbc::CLI::List, :cask do EOS end + it "lists full names" do + casks = %w[ + local-caffeine + third-party/tap/third-party-cask + local-transmission + ].map { |c| Hbc::CaskLoader.load(c) } + + casks.each do |c| + InstallHelper.install_with_caskfile(c) + end + + expect { + Hbc::CLI::List.run("--full-name") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + third-party/tap/third-party-cask + EOS + end + describe "lists versions" do let(:casks) { ["local-caffeine", "local-transmission"] } let(:expected_output) { diff --git a/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb new file mode 100644 index 000000000..d7add0522 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb @@ -0,0 +1,9 @@ +cask 'third-party-cask' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/ThirdParty.dmg' + homepage 'http://example.com/' + + app 'ThirdParty.app' +end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index c51d339a7..fc83149d0 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -18,6 +18,7 @@ HOMEBREW_CASK_DIRS = [ RSpec.shared_context "Homebrew-Cask" do around(:each) do |example| + third_party_tap = Tap.fetch("third-party", "tap") begin dirs = HOMEBREW_CASK_DIRS.map do |dir| Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap do |path| @@ -31,11 +32,18 @@ RSpec.shared_context "Homebrew-Cask" do FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path end + third_party_tap.tap do |tap| + FileUtils.mkdir_p tap.path.dirname + FileUtils.ln_sf TEST_FIXTURE_DIR.join("third-party"), tap.path + end + example.run ensure FileUtils.rm_rf dirs Hbc.default_tap.path.unlink FileUtils.rm_rf Hbc.default_tap.path.parent + third_party_tap.path.unlink + FileUtils.rm_rf third_party_tap.path.parent end end end diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 37bd83c4f..3b5355b15 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -296,4 +296,33 @@ describe "globally-scoped helper methods" do expect(ENV["PATH"]).not_to eq("/bin") end end + + describe "#tap_and_name_comparison" do + describe "both strings are only names" do + it "alphabetizes the strings" do + expect(%w[a b].sort(&tap_and_name_comparison)).to eq(%w[a b]) + expect(%w[b a].sort(&tap_and_name_comparison)).to eq(%w[a b]) + end + end + + describe "both strings include tap" do + it "alphabetizes the strings" do + expect(%w[a/z/z b/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + expect(%w[b/z/z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + + expect(%w[z/a/z z/b/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + expect(%w[z/b/z z/a/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + + expect(%w[z/z/a z/z/b].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + expect(%w[z/z/b z/z/a].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + end + end + + describe "only one string includes tap" do + it "prefers the string without tap" do + expect(%w[a/z/z z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + expect(%w[z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + end + end + end end -- cgit v1.2.3 From 626cb6ca91f99df6f7c646d95cb5e82d0dd6532d Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 10 Sep 2017 18:55:01 +0000 Subject: audit: Add more tests for FormulaAudit/Miscellaneous cop --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 31aafbcf8..d93962688 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -380,6 +380,21 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with build.universal? exempted formula" do + source = <<-EOS.undent + class Wine < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build.universal? + "foo" + end + end + EOS + + inspect_source(cop, source, "/homebrew-core/Formula/wine.rb") + expect(cop.offenses).to eq([]) + end + it "with ENV.universal_binary" do source = <<-EOS.undent class Foo < Formula @@ -450,6 +465,19 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with ruby-macho alternatives audit exempted formula" do + source = <<-EOS.undent + class Cctools < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + inspect_source(cop, source, "/homebrew-core/Formula/cctools.rb") + expect(cop.offenses).to eq([]) + end + it "with npm install without language::Node args" do source = <<-EOS.undent class Foo < Formula @@ -471,5 +499,18 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with npm install without language::Node args in kibana" do + source = <<-EOS.undent + class KibanaAT44 < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + inspect_source(cop, source, "/homebrew-core/Formula/kibana@4.4.rb") + expect(cop.offenses).to eq([]) + end end end -- cgit v1.2.3 From 557105640b5154e3fe1299aa31abdc106aa71df5 Mon Sep 17 00:00:00 2001 From: Naoto Kaneko Date: Fri, 22 Sep 2017 16:57:27 +0900 Subject: Add a failure message to be_detected_from matcher --- Library/Homebrew/test/version_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index cee57e935..6d6996316 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -241,8 +241,18 @@ describe Version do describe "::detect" do matcher :be_detected_from do |url, specs = {}| - match do |version| - Version.detect(url, specs) == version + detected = Version.detect(url, specs) + + match do |expected| + detected == expected + end + + failure_message do |expected| + format = <<-EOS + expected: %s + detected: %s + EOS + format % [expected, detected] end end -- cgit v1.2.3 From 5fa4d60c7b6c6d0e8488ad3a7d6649233af4fb2e Mon Sep 17 00:00:00 2001 From: Naoto Kaneko Date: Fri, 22 Sep 2017 17:53:48 +0900 Subject: Replace String#% with Kernel.#format --- Library/Homebrew/test/version_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index 6d6996316..d670d79c8 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -248,11 +248,11 @@ describe Version do end failure_message do |expected| - format = <<-EOS + message = <<-EOS expected: %s detected: %s EOS - format % [expected, detected] + format(message, expected, detected) end end -- cgit v1.2.3 From 9f57840486b764eb1f637deb972ea33939b40d01 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 22 Aug 2017 17:03:22 +0530 Subject: test: Tests for os/mac/keg --- Library/Homebrew/test/os/mac/keg_spec.rb | 56 +++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 15 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/os/mac/keg_spec.rb b/Library/Homebrew/test/os/mac/keg_spec.rb index 562c2ba6a..4321c61cd 100644 --- a/Library/Homebrew/test/os/mac/keg_spec.rb +++ b/Library/Homebrew/test/os/mac/keg_spec.rb @@ -5,28 +5,54 @@ describe Keg do subject { described_class.new(keg_path) } - describe "#mach_o_files" do - let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } + let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } + let(:file) { keg_path/"lib/i386.dylib" } - before(:each) { (keg_path/"lib").mkpath } + before(:each) do + (keg_path/"lib").mkpath + cp dylib_path("i386"), file + subject.link + end - after(:each) { subject.unlink } + after(:each) { subject.unlink } - it "skips hardlinks" do - cp dylib_path("i386"), keg_path/"lib/i386.dylib" - ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" + describe "#change_dylib_id" do + it "does nothing if given id is same as file's dylib id" do + id = file.dylib_id + file.change_dylib_id(id) + expect(file.dylib_id).to eq(id) + end + end - subject.link - expect(subject.mach_o_files.count).to eq(1) + describe "#change_install_name" do + it "does nothing if given name is same as file's install name" do + file.ensure_writable do + subject.each_install_name_for(file) do |name| + file.change_install_name(name, name) + expect(name).to eq(name) + end + end end - it "isn't confused by symlinks" do - cp dylib_path("i386"), keg_path/"lib/i386.dylib" - ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" - ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" + it "does nothing when install name start with '/'" do + file.ensure_writable do + subject.each_install_name_for(file) do |name| + new_name = subject.fixed_name(file, name) + file.change_install_name(name, new_name) + expect(name).not_to eq(new_name) + end + end + end + end + + describe "#require_relocation?" do + it "is set to false at initialization" do + expect(subject.require_relocation?).to be false + end - subject.link - expect(subject.mach_o_files.count).to eq(1) + it "is set to true after linkage is fixed" do + subject.fix_dynamic_linkage + expect(subject.require_relocation?).to be true end end end -- cgit v1.2.3 From 5377a42f7f3c3b561b011c75f0a386e5b64d3f58 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 27 Sep 2017 02:57:12 -0700 Subject: Revert "Added tests for os/mac/keg" --- Library/Homebrew/test/os/mac/keg_spec.rb | 56 +++++++++----------------------- 1 file changed, 15 insertions(+), 41 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/os/mac/keg_spec.rb b/Library/Homebrew/test/os/mac/keg_spec.rb index 4321c61cd..562c2ba6a 100644 --- a/Library/Homebrew/test/os/mac/keg_spec.rb +++ b/Library/Homebrew/test/os/mac/keg_spec.rb @@ -5,54 +5,28 @@ describe Keg do subject { described_class.new(keg_path) } - let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } - let(:file) { keg_path/"lib/i386.dylib" } + describe "#mach_o_files" do + let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } - before(:each) do - (keg_path/"lib").mkpath - cp dylib_path("i386"), file - subject.link - end + before(:each) { (keg_path/"lib").mkpath } - after(:each) { subject.unlink } + after(:each) { subject.unlink } - describe "#change_dylib_id" do - it "does nothing if given id is same as file's dylib id" do - id = file.dylib_id - file.change_dylib_id(id) - expect(file.dylib_id).to eq(id) - end - end + it "skips hardlinks" do + cp dylib_path("i386"), keg_path/"lib/i386.dylib" + ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" - describe "#change_install_name" do - it "does nothing if given name is same as file's install name" do - file.ensure_writable do - subject.each_install_name_for(file) do |name| - file.change_install_name(name, name) - expect(name).to eq(name) - end - end + subject.link + expect(subject.mach_o_files.count).to eq(1) end - it "does nothing when install name start with '/'" do - file.ensure_writable do - subject.each_install_name_for(file) do |name| - new_name = subject.fixed_name(file, name) - file.change_install_name(name, new_name) - expect(name).not_to eq(new_name) - end - end - end - end - - describe "#require_relocation?" do - it "is set to false at initialization" do - expect(subject.require_relocation?).to be false - end + it "isn't confused by symlinks" do + cp dylib_path("i386"), keg_path/"lib/i386.dylib" + ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" + ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" - it "is set to true after linkage is fixed" do - subject.fix_dynamic_linkage - expect(subject.require_relocation?).to be true + subject.link + expect(subject.mach_o_files.count).to eq(1) end end end -- cgit v1.2.3