Commit 4dd6d1af authored by Albert Salim's avatar Albert Salim

Add mappings to test_file_finder

- initializers
- migrations
- schema
- factories
parent 4b5250cc
...@@ -88,6 +88,54 @@ RSpec.describe Tooling::TestFileFinder do ...@@ -88,6 +88,54 @@ RSpec.describe Tooling::TestFileFinder do
end end
end end
context 'when given a factory file' do
let(:file) { 'spec/factories/users.rb' }
it 'returns spec/factories_spec.rb file' do
expect(subject.test_files).to contain_exactly('spec/factories_spec.rb')
end
end
context 'when given an ee factory file' do
let(:file) { 'ee/spec/factories/users.rb' }
it 'returns spec/factories_spec.rb file' do
expect(subject.test_files).to contain_exactly('spec/factories_spec.rb')
end
end
context 'when given db/structure.sql' do
let(:file) { 'db/structure.sql' }
it 'returns spec/db/schema_spec.rb' do
expect(subject.test_files).to contain_exactly('spec/db/schema_spec.rb')
end
end
context 'when given an initializer' do
let(:file) { 'config/initializers/action_mailer_hooks.rb' }
it 'returns the matching initializer spec' do
expect(subject.test_files).to contain_exactly('spec/initializers/action_mailer_hooks_spec.rb')
end
end
context 'when given a migration file' do
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')
end
end
context 'when given a post-migration file' do
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')
end
end
context 'with foss_test_only: true' do context 'with foss_test_only: true' do
subject { Tooling::TestFileFinder.new(file, foss_test_only: true) } subject { Tooling::TestFileFinder.new(file, foss_test_only: true) }
......
...@@ -12,7 +12,7 @@ module Tooling ...@@ -12,7 +12,7 @@ module Tooling
end end
def test_files def test_files
impacted_tests = ee_impact | non_ee_impact impacted_tests = ee_impact | non_ee_impact | either_impact
impacted_tests.impact(@file) impacted_tests.impact(@file)
end end
...@@ -72,6 +72,16 @@ module Tooling ...@@ -72,6 +72,16 @@ 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{^spec/(.+)_spec.rb$}) { |match| match[0] } impact.associate(%r{^spec/(.+)_spec.rb$}) { |match| match[0] }
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" }
end
end
def either_impact
ImpactedTestFile.new do |impact|
impact.associate(%r{^(#{EE_PREFIX})?spec/factories/.+\.rb$}) { 'spec/factories_spec.rb' }
impact.associate('db/structure.sql') { 'spec/db/schema_spec.rb' }
end 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