From b7135eec493c1b2cad69b934bbf0d1aefbcbf8ab Mon Sep 17 00:00:00 2001
From: Markus Reiter <me@reitermark.us>
Date: Sun, 5 Mar 2017 03:46:13 +0100
Subject: [PATCH] Move `shared_examples` and `matcher` into specs.

---
 Library/Homebrew/cask/spec/cask/audit_spec.rb | 36 ++++++++++++++++-
 .../cask/spec/cask/dsl/version_spec.rb        | 13 +++++--
 .../cask/spec/support/audit_matchers.rb       | 39 -------------------
 .../spec/support/expectations_hash_helper.rb  | 10 -----
 4 files changed, 45 insertions(+), 53 deletions(-)
 delete mode 100644 Library/Homebrew/cask/spec/support/audit_matchers.rb
 delete mode 100644 Library/Homebrew/cask/spec/support/expectations_hash_helper.rb

diff --git a/Library/Homebrew/cask/spec/cask/audit_spec.rb b/Library/Homebrew/cask/spec/cask/audit_spec.rb
index 9eb9f01364..222294bdc1 100644
--- a/Library/Homebrew/cask/spec/cask/audit_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/audit_spec.rb
@@ -1,5 +1,39 @@
 describe Hbc::Audit do
-  include AuditMatchers
+  def include_msg?(messages, msg)
+    if msg.is_a?(Regexp)
+      Array(messages).any? { |m| m =~ msg }
+    else
+      Array(messages).include?(msg)
+    end
+  end
+
+  matcher :pass do
+    match do |audit|
+      !audit.errors? && !audit.warnings?
+    end
+  end
+
+  matcher :fail do
+    match(&:errors?)
+  end
+
+  matcher :warn do
+    match do |audit|
+      audit.warnings? && !audit.errors?
+    end
+  end
+
+  matcher :fail_with do |error_msg|
+    match do |audit|
+      include_msg?(audit.errors, error_msg)
+    end
+  end
+
+  matcher :warn_with do |warning_msg|
+    match do |audit|
+      include_msg?(audit.warnings, warning_msg)
+    end
+  end
 
   let(:cask) { instance_double(Hbc::Cask) }
   let(:download) { false }
diff --git a/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb b/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb
index 1dfbb44679..acf3db3abd 100644
--- a/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb
+++ b/Library/Homebrew/cask/spec/cask/dsl/version_spec.rb
@@ -1,7 +1,12 @@
 describe Hbc::DSL::Version do
-  include ExpectationsHashHelper
-
-  let(:version) { described_class.new(raw_version) }
+  shared_examples "expectations hash" do |input_name, expectations|
+    expectations.each do |input_value, expected_output|
+      context "when #{input_name} is #{input_value.inspect}" do
+        let(input_name.to_sym) { input_value }
+        it { is_expected.to eq expected_output }
+      end
+    end
+  end
 
   shared_examples "version equality" do
     let(:raw_version) { "1.2.3" }
@@ -36,6 +41,8 @@ describe Hbc::DSL::Version do
     end
   end
 
+  let(:version) { described_class.new(raw_version) }
+
   describe "#==" do
     subject { version == other }
     include_examples "version equality"
diff --git a/Library/Homebrew/cask/spec/support/audit_matchers.rb b/Library/Homebrew/cask/spec/support/audit_matchers.rb
deleted file mode 100644
index fc1e0e876c..0000000000
--- a/Library/Homebrew/cask/spec/support/audit_matchers.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-module AuditMatchers
-  extend RSpec::Matchers::DSL
-
-  matcher :pass do
-    match do |audit|
-      !audit.errors? && !audit.warnings?
-    end
-  end
-
-  matcher :fail do
-    match(&:errors?)
-  end
-
-  matcher :warn do
-    match do |audit|
-      audit.warnings? && !audit.errors?
-    end
-  end
-
-  matcher :fail_with do |error_msg|
-    match do |audit|
-      include_msg?(audit.errors, error_msg)
-    end
-  end
-
-  matcher :warn_with do |warning_msg|
-    match do |audit|
-      include_msg?(audit.warnings, warning_msg)
-    end
-  end
-
-  def include_msg?(messages, msg)
-    if msg.is_a?(Regexp)
-      Array(messages).any? { |m| m =~ msg }
-    else
-      Array(messages).include?(msg)
-    end
-  end
-end
diff --git a/Library/Homebrew/cask/spec/support/expectations_hash_helper.rb b/Library/Homebrew/cask/spec/support/expectations_hash_helper.rb
deleted file mode 100644
index 726b1d0539..0000000000
--- a/Library/Homebrew/cask/spec/support/expectations_hash_helper.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-module ExpectationsHashHelper
-  shared_examples "expectations hash" do |input_name, expectations|
-    expectations.each do |input_value, expected_output|
-      context "when #{input_name} is #{input_value.inspect}" do
-        let(input_name.to_sym) { input_value }
-        it { is_expected.to eq expected_output }
-      end
-    end
-  end
-end
-- 
GitLab