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
context 'with a prefix' do
it 'returns a pattern' do
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
......@@ -138,7 +145,14 @@ RSpec.describe Quality::TestLevel do
context 'with a prefix' do
it 'returns a regexp' do
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
......
......@@ -60,20 +60,20 @@ module Quality
system: ['features']
}.freeze
attr_reader :prefix
attr_reader :prefixes
def initialize(prefix = nil)
@prefix = prefix
def initialize(prefixes = nil)
@prefixes = Array(prefixes)
@patterns = {}
@regexps = {}
end
def pattern(level)
@patterns[level] ||= "#{prefix}spec/#{folders_pattern(level)}{,/**/}*#{suffix(level)}"
@patterns[level] ||= "#{prefixes_for_pattern}spec/#{folders_pattern(level)}{,/**/}*#{suffix(level)}"
end
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
def level_for(file_path)
......@@ -102,6 +102,20 @@ module Quality
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)
case level
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