From 6cd36428505b1b3548b1e15fe7e0a850b2e2aeaa Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 8 Feb 2017 07:14:28 +0100 Subject: [PATCH] =?UTF-8?q?Create=20custom=20matchers=20for=20=E2=80=9Cval?= =?UTF-8?q?id=20symlink=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb | 4 ++-- Library/Homebrew/cask/spec/spec_helper.rb | 1 + Library/Homebrew/cask/spec/support/file_helper.rb | 8 -------- Library/Homebrew/cask/spec/support/file_matchers.rb | 9 +++++++++ Library/Homebrew/cask/test/cask/artifact/suite_test.rb | 2 +- Library/Homebrew/cask/test/test_helper.rb | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 Library/Homebrew/cask/spec/support/file_helper.rb create mode 100644 Library/Homebrew/cask/spec/support/file_matchers.rb diff --git a/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb index 95ac2b5f53..b606aba1b6 100644 --- a/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/cask/spec/cask/artifact/binary_spec.rb @@ -20,7 +20,7 @@ describe Hbc::Artifact::Binary do shutup do Hbc::Artifact::Binary.new(cask).install_phase end - expect(FileHelper.valid_alias?(expected_path)).to be true + expect(expected_path).to be_a_valid_symlink end it "avoids clobbering an existing binary by linking over it" do @@ -82,7 +82,7 @@ describe Hbc::Artifact::Binary do Hbc::Artifact::Binary.new(cask).install_phase end - expect(FileHelper.valid_alias?(expected_path)).to be true + expect(expected_path).to be_a_valid_symlink end end end diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb index eefee3d60e..548691f19c 100644 --- a/Library/Homebrew/cask/spec/spec_helper.rb +++ b/Library/Homebrew/cask/spec/spec_helper.rb @@ -34,4 +34,5 @@ end RSpec.configure do |config| config.order = :random config.include(Test::Helper::Shutup) + config.include(FileMatchers) end diff --git a/Library/Homebrew/cask/spec/support/file_helper.rb b/Library/Homebrew/cask/spec/support/file_helper.rb deleted file mode 100644 index abe7b26180..0000000000 --- a/Library/Homebrew/cask/spec/support/file_helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -module FileHelper - module_function - - def valid_alias?(candidate) - return false unless candidate.symlink? - candidate.readlink.exist? - end -end diff --git a/Library/Homebrew/cask/spec/support/file_matchers.rb b/Library/Homebrew/cask/spec/support/file_matchers.rb new file mode 100644 index 0000000000..d3e62f45af --- /dev/null +++ b/Library/Homebrew/cask/spec/support/file_matchers.rb @@ -0,0 +1,9 @@ +module FileMatchers + extend RSpec::Matchers::DSL + + matcher :be_a_valid_symlink do + match do |path| + path.symlink? && path.readlink.exist? + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/suite_test.rb b/Library/Homebrew/cask/test/cask/artifact/suite_test.rb index 0584dcbeb0..6259baa4be 100644 --- a/Library/Homebrew/cask/test/cask/artifact/suite_test.rb +++ b/Library/Homebrew/cask/test/cask/artifact/suite_test.rb @@ -20,7 +20,7 @@ describe Hbc::Artifact::Suite do end target_path.must_be :directory? - TestHelper.valid_alias?(target_path).must_equal false + TestHelper.valid_symlink?(target_path).must_equal false source_path.wont_be :exist? end diff --git a/Library/Homebrew/cask/test/test_helper.rb b/Library/Homebrew/cask/test/test_helper.rb index 71ce5752e8..f600a1c5c8 100644 --- a/Library/Homebrew/cask/test/test_helper.rb +++ b/Library/Homebrew/cask/test/test_helper.rb @@ -58,7 +58,7 @@ class TestHelper "file://" + local_binary_path(name) end - def self.valid_alias?(candidate) + def self.valid_symlink?(candidate) return false unless candidate.symlink? candidate.readlink.exist? end