Commit ce5d473e authored by Rémy Coutable's avatar Rémy Coutable

Allow Quality::TestLevel to have several prefixes

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 26b5a0c8
...@@ -63,7 +63,14 @@ RSpec.describe Quality::TestLevel do ...@@ -63,7 +63,14 @@ RSpec.describe Quality::TestLevel do
context 'with a prefix' do context 'with a prefix' do
it 'returns a pattern' do it 'returns a pattern' do
expect(described_class.new('ee/').pattern(:system)) expect(described_class.new('ee/').pattern(:system))
.to eq("ee/spec/{features}{,/**/}*_spec.rb") .to eq("{ee/}spec/{features}{,/**/}*_spec.rb")
end
end
context 'with several prefixes' do
it 'returns a pattern' do
expect(described_class.new(['', 'ee/', 'jh/']).pattern(:system))
.to eq("{,ee/,jh/}spec/{features}{,/**/}*_spec.rb")
end end
end end
...@@ -138,7 +145,14 @@ RSpec.describe Quality::TestLevel do ...@@ -138,7 +145,14 @@ RSpec.describe Quality::TestLevel do
context 'with a prefix' do context 'with a prefix' do
it 'returns a regexp' do it 'returns a regexp' do
expect(described_class.new('ee/').regexp(:system)) expect(described_class.new('ee/').regexp(:system))
.to eq(%r{ee/spec/(features)}) .to eq(%r{(ee/)spec/(features)})
end
end
context 'with several prefixes' do
it 'returns a regexp' do
expect(described_class.new(['', 'ee/', 'jh/']).regexp(:system))
.to eq(%r{(|ee/|jh/)spec/(features)})
end end
end end
......
...@@ -60,20 +60,20 @@ module Quality ...@@ -60,20 +60,20 @@ module Quality
system: ['features'] system: ['features']
}.freeze }.freeze
attr_reader :prefix attr_reader :prefixes
def initialize(prefix = nil) def initialize(prefixes = nil)
@prefix = prefix @prefixes = Array(prefixes)
@patterns = {} @patterns = {}
@regexps = {} @regexps = {}
end end
def pattern(level) def pattern(level)
@patterns[level] ||= "#{prefix}spec/#{folders_pattern(level)}{,/**/}*#{suffix(level)}" @patterns[level] ||= "#{prefixes_for_pattern}spec/#{folders_pattern(level)}{,/**/}*#{suffix(level)}"
end end
def regexp(level) def regexp(level)
@regexps[level] ||= Regexp.new("#{prefix}spec/#{folders_regex(level)}").freeze @regexps[level] ||= Regexp.new("#{prefixes_for_regex}spec/#{folders_regex(level)}").freeze
end end
def level_for(file_path) def level_for(file_path)
...@@ -102,6 +102,20 @@ module Quality ...@@ -102,6 +102,20 @@ module Quality
private private
def prefixes_for_pattern
return '' if prefixes.empty?
"{#{prefixes.join(',')}}"
end
def prefixes_for_regex
return '' if prefixes.empty?
regex_prefix = prefixes.map(&Regexp.method(:escape)).join('|')
"(#{regex_prefix})"
end
def suffix(level) def suffix(level)
case level case level
when :frontend_fixture when :frontend_fixture
......
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