From cc4fb35ae46fbbdeabbc564cae09507450838070 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 4 Mar 2017 22:59:13 +0100 Subject: [PATCH] Move Cask `shared_examples` to `test/support`. --- .../cask/spec/cask/dsl/caveats_spec.rb | 1 + .../cask/spec/cask/dsl/postflight_spec.rb | 2 + .../cask/spec/cask/dsl/preflight_spec.rb | 2 + .../cask/dsl/uninstall_postflight_spec.rb | 1 + .../spec/cask/dsl/uninstall_preflight_spec.rb | 2 + .../spec/shared_examples/hbc_dsl_base.rb} | 0 .../spec/shared_examples/hbc_staged.rb} | 38 +++++++++---------- 7 files changed, 25 insertions(+), 21 deletions(-) rename Library/Homebrew/{cask/spec/support/shared_examples/dsl_base.rb => test/support/helper/spec/shared_examples/hbc_dsl_base.rb} (100%) rename Library/Homebrew/{cask/spec/support/shared_examples/staged.rb => test/support/helper/spec/shared_examples/hbc_staged.rb} (80%) diff --git a/Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb index 777491d66e..07940cd0af 100644 --- a/Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb +++ b/Library/Homebrew/cask/spec/cask/dsl/caveats_spec.rb @@ -1,4 +1,5 @@ require "spec_helper" +require "test/support/helper/spec/shared_examples/hbc_dsl_base" describe Hbc::DSL::Caveats do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } diff --git a/Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb index 116a7c8a80..d7a8f219dd 100644 --- a/Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb +++ b/Library/Homebrew/cask/spec/cask/dsl/postflight_spec.rb @@ -1,4 +1,6 @@ require "spec_helper" +require "test/support/helper/spec/shared_examples/hbc_dsl_base" +require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::Postflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } diff --git a/Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb index 90d2634dbb..81b0c79757 100644 --- a/Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb +++ b/Library/Homebrew/cask/spec/cask/dsl/preflight_spec.rb @@ -1,4 +1,6 @@ require "spec_helper" +require "test/support/helper/spec/shared_examples/hbc_dsl_base" +require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::Preflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } diff --git a/Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb index 4b7dd75574..448e1b411e 100644 --- a/Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb +++ b/Library/Homebrew/cask/spec/cask/dsl/uninstall_postflight_spec.rb @@ -1,4 +1,5 @@ require "spec_helper" +require "test/support/helper/spec/shared_examples/hbc_dsl_base" describe Hbc::DSL::UninstallPostflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } diff --git a/Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb index a4930e99e9..aac34e76a6 100644 --- a/Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb +++ b/Library/Homebrew/cask/spec/cask/dsl/uninstall_preflight_spec.rb @@ -1,4 +1,6 @@ require "spec_helper" +require "test/support/helper/spec/shared_examples/hbc_dsl_base" +require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::UninstallPreflight do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } diff --git a/Library/Homebrew/cask/spec/support/shared_examples/dsl_base.rb b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_dsl_base.rb similarity index 100% rename from Library/Homebrew/cask/spec/support/shared_examples/dsl_base.rb rename to Library/Homebrew/test/support/helper/spec/shared_examples/hbc_dsl_base.rb diff --git a/Library/Homebrew/cask/spec/support/shared_examples/staged.rb b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb similarity index 80% rename from Library/Homebrew/cask/spec/support/shared_examples/staged.rb rename to Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb index d815ef7a0c..31083ee585 100644 --- a/Library/Homebrew/cask/spec/support/shared_examples/staged.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb @@ -1,21 +1,17 @@ -require "spec_helper" - require "hbc/staged" shared_examples Hbc::Staged do - let(:fake_pathname_exists) { - fake_pathname = Pathname.new("/path/to/file/that/exists") - allow(fake_pathname).to receive(:exist?).and_return(true) - allow(fake_pathname).to receive(:expand_path).and_return(fake_pathname) - fake_pathname - } + let(:existing_path) { Pathname.new("/path/to/file/that/exists") } + let(:non_existent_path) { Pathname.new("/path/to/file/that/does/not/exist") } - let(:fake_pathname_does_not_exist) { - fake_pathname = Pathname.new("/path/to/file/that/does/not/exist") - allow(fake_pathname).to receive(:exist?).and_return(false) - allow(fake_pathname).to receive(:expand_path).and_return(fake_pathname) - fake_pathname - } + before(:each) do + allow(existing_path).to receive(:exist?).and_return(true) + allow(existing_path).to receive(:expand_path) + .and_return(existing_path) + allow(non_existent_path).to receive(:exist?).and_return(false) + allow(non_existent_path).to receive(:expand_path) + .and_return(non_existent_path) + end it "can run system commands with list-form arguments" do Hbc::FakeSystemCommand.expects_command( @@ -56,7 +52,7 @@ shared_examples Hbc::Staged do end it "can set the permissions of a file" do - fake_pathname = fake_pathname_exists + fake_pathname = existing_path allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( @@ -69,7 +65,7 @@ shared_examples Hbc::Staged do end it "can set the permissions of multiple files" do - fake_pathname = fake_pathname_exists + fake_pathname = existing_path allow(staged).to receive(:Pathname).and_return(fake_pathname) Hbc::FakeSystemCommand.expects_command( @@ -82,13 +78,13 @@ shared_examples Hbc::Staged do end it "cannot set the permissions of a file that does not exist" do - fake_pathname = fake_pathname_does_not_exist + fake_pathname = non_existent_path allow(staged).to receive(:Pathname).and_return(fake_pathname) staged.set_permissions(fake_pathname.to_s, "777") end it "can set the ownership of a file" do - fake_pathname = fake_pathname_exists + fake_pathname = existing_path allow(staged).to receive(:current_user).and_return("fake_user") allow(staged).to receive(:Pathname).and_return(fake_pathname) @@ -103,7 +99,7 @@ shared_examples Hbc::Staged do end it "can set the ownership of multiple files" do - fake_pathname = fake_pathname_exists + fake_pathname = existing_path allow(staged).to receive(:current_user).and_return("fake_user") allow(staged).to receive(:Pathname).and_return(fake_pathname) @@ -118,7 +114,7 @@ shared_examples Hbc::Staged do end it "can set the ownership of a file with a different user and group" do - fake_pathname = fake_pathname_exists + fake_pathname = existing_path allow(staged).to receive(:Pathname).and_return(fake_pathname) @@ -133,7 +129,7 @@ shared_examples Hbc::Staged do it "cannot set the ownership of a file that does not exist" do allow(staged).to receive(:current_user).and_return("fake_user") - fake_pathname = fake_pathname_does_not_exist + fake_pathname = non_existent_path allow(staged).to receive(:Pathname).and_return(fake_pathname) shutup do