From d0e448cf9c8883cb98f07160681bc69ba43b5a32 Mon Sep 17 00:00:00 2001
From: Albert Salim <asalim@gitlab.com>
Date: Wed, 1 Jul 2020 17:34:46 +0800
Subject: [PATCH] Detect view spec for haml

---
 .../tooling/lib/tooling/test_file_finder_spec.rb | 16 ++++++++++++++++
 tooling/lib/tooling/test_file_finder.rb          |  9 +++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/spec/tooling/lib/tooling/test_file_finder_spec.rb b/spec/tooling/lib/tooling/test_file_finder_spec.rb
index 3025c21d858f0..64b55b9b1d622 100644
--- a/spec/tooling/lib/tooling/test_file_finder_spec.rb
+++ b/spec/tooling/lib/tooling/test_file_finder_spec.rb
@@ -120,6 +120,22 @@
       end
     end
 
+    context 'when given a haml view' do
+      let(:file) { 'app/views/admin/users/_user.html.haml' }
+
+      it 'returns the matching view spec' do
+        expect(subject.test_files).to contain_exactly('spec/views/admin/users/_user.html.haml_spec.rb')
+      end
+    end
+
+    context 'when given a haml view in ee/' do
+      let(:file) { 'ee/app/views/admin/users/_user.html.haml' }
+
+      it 'returns the matching view spec' do
+        expect(subject.test_files).to contain_exactly('ee/spec/views/admin/users/_user.html.haml_spec.rb')
+      end
+    end
+
     context 'when given a migration file' do
       let(:file) { 'db/migrate/20191023152913_add_default_and_free_plans.rb' }
 
diff --git a/tooling/lib/tooling/test_file_finder.rb b/tooling/lib/tooling/test_file_finder.rb
index 36ace67caa30a..cf5de190c4aa6 100644
--- a/tooling/lib/tooling/test_file_finder.rb
+++ b/tooling/lib/tooling/test_file_finder.rb
@@ -72,9 +72,9 @@ def non_ee_impact
       ImpactedTestFile.new do |impact|
         impact.associate(%r{app/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" }
         impact.associate(%r{(tooling/)?lib/(.+)\.rb$}) { |match| "spec/#{match[1]}lib/#{match[2]}_spec.rb" }
-        impact.associate(%r{config/initializers/(.+).rb$}) { |match| "spec/initializers/#{match[1]}_spec.rb" }
+        impact.associate(%r{config/initializers/(.+)\.rb$}) { |match| "spec/initializers/#{match[1]}_spec.rb" }
         impact.associate('db/structure.sql') { 'spec/db/schema_spec.rb' }
-        impact.associate(%r{db/(?:post_)?migrate/([0-9]+)_(.+).rb$}) do |match|
+        impact.associate(%r{db/(?:post_)?migrate/([0-9]+)_(.+)\.rb$}) do |match|
           [
             "spec/migrations/#{match[2]}_spec.rb",
             "spec/migrations/#{match[1]}_#{match[2]}_spec.rb"
@@ -84,8 +84,9 @@ def non_ee_impact
     end
 
     def either_impact
-      ImpactedTestFile.new(prefix: %r{^(#{EE_PREFIX})?}) do |impact|
-        impact.associate(%r{spec/(.+)_spec.rb$}) { |match| match[0] }
+      ImpactedTestFile.new(prefix: %r{^(?<prefix>#{EE_PREFIX})?}) do |impact|
+        impact.associate(%r{app/views/(?<view>.+)\.haml$}) { |match| "#{match[:prefix]}spec/views/#{match[:view]}.haml_spec.rb" }
+        impact.associate(%r{spec/(.+)_spec\.rb$}) { |match| match[0] }
         impact.associate(%r{spec/factories/.+\.rb$}) { 'spec/factories_spec.rb' }
       end
     end
-- 
GitLab