Commit 3bc1b6c7 authored by Albert Salim's avatar Albert Salim

Match multiple migration conventions

parent 8dba90d8
...@@ -124,7 +124,11 @@ RSpec.describe Tooling::TestFileFinder do ...@@ -124,7 +124,11 @@ RSpec.describe Tooling::TestFileFinder do
let(:file) { 'db/migrate/20191023152913_add_default_and_free_plans.rb' } let(:file) { 'db/migrate/20191023152913_add_default_and_free_plans.rb' }
it 'returns the matching migration spec' do 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
end end
...@@ -132,7 +136,11 @@ RSpec.describe Tooling::TestFileFinder do ...@@ -132,7 +136,11 @@ RSpec.describe Tooling::TestFileFinder do
let(:file) { 'db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb' } let(:file) { 'db/post_migrate/20200608072931_backfill_imported_snippet_repositories.rb' }
it 'returns the matching migration spec' do 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
end end
......
...@@ -37,7 +37,8 @@ module Tooling ...@@ -37,7 +37,8 @@ module Tooling
def impact(file) def impact(file)
@pattern_matchers.each_with_object(Set.new) do |(pattern, block), result| @pattern_matchers.each_with_object(Set.new) do |(pattern, block), result|
if (match = pattern.match(file)) if (match = pattern.match(file))
result << block.call(match) test_files = block.call(match)
result.merge(Array(test_files))
end end
end.to_a end.to_a
end end
...@@ -72,9 +73,13 @@ module Tooling ...@@ -72,9 +73,13 @@ module Tooling
impact.associate(%r{app/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" } 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{(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(%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('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
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment