diff --git a/spec/tooling/lib/tooling/test_file_finder_spec.rb b/spec/tooling/lib/tooling/test_file_finder_spec.rb index b5909e7d7e00aae8c3739fa9726dfa96a8050999..3e6eb4bb5214886a14a0c3adec53c2f9775e6318 100644 --- a/spec/tooling/lib/tooling/test_file_finder_spec.rb +++ b/spec/tooling/lib/tooling/test_file_finder_spec.rb @@ -124,7 +124,11 @@ let(:file) { 'db/migrate/20191023152913_add_default_and_free_plans.rb' } it 'returns the matching migration spec' do - expect(subject.test_files).to contain_exactly('spec/migrations/add_default_and_free_plans_spec.rb') + test_files = %w[ + spec/migrations/add_default_and_free_plans_spec.rb + spec/migrations/20191023152913_add_default_and_free_plans_spec.rb + ] + expect(subject.test_files).to contain_exactly(*test_files) end end @@ -132,7 +136,11 @@ let(:file) { 'db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb' } it 'returns the matching migration spec' do - expect(subject.test_files).to contain_exactly('spec/migrations/backfill_imported_snippet_repositories_spec.rb') + test_files = %w[ + spec/migrations/backfill_imported_snippet_repositories_spec.rb + spec/migrations/20200608072931_backfill_imported_snippet_repositories_spec.rb + ] + expect(subject.test_files).to contain_exactly(*test_files) end end diff --git a/tooling/lib/tooling/test_file_finder.rb b/tooling/lib/tooling/test_file_finder.rb index 12963d93e81a749f3eac5e75726f55090cc229b8..36ace67caa30a6cb2dc7386b90a0d7f699be044c 100644 --- a/tooling/lib/tooling/test_file_finder.rb +++ b/tooling/lib/tooling/test_file_finder.rb @@ -37,7 +37,8 @@ def associate(pattern, &block) def impact(file) @pattern_matchers.each_with_object(Set.new) do |(pattern, block), result| if (match = pattern.match(file)) - result << block.call(match) + test_files = block.call(match) + result.merge(Array(test_files)) end end.to_a end @@ -72,9 +73,13 @@ def non_ee_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{db/post_migrate/([0-9]+)_(.+).rb$}) { |match| "spec/migrations/#{match[2]}_spec.rb" } - impact.associate(%r{db/migrate/([0-9]+)_(.+).rb$}) { |match| "spec/migrations/#{match[2]}_spec.rb" } impact.associate('db/structure.sql') { 'spec/db/schema_spec.rb' } + 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" + ] + end end end