Fix build coverage regex.
Added a spec for regex captures as well. Fixes #2644
This commit is contained in:
parent
05e0b6d014
commit
5a3237fd8d
|
@ -170,7 +170,8 @@ module Ci
|
||||||
|
|
||||||
def extract_coverage(text, regex)
|
def extract_coverage(text, regex)
|
||||||
begin
|
begin
|
||||||
matches = regex.match(text).to_a.last
|
matches = text.scan(Regexp.new(regex)).last
|
||||||
|
matches = matches.last if matches.kind_of?(Array)
|
||||||
coverage = matches.gsub(/\d+(\.\d+)?/).first
|
coverage = matches.gsub(/\d+(\.\d+)?/).first
|
||||||
|
|
||||||
if coverage.present?
|
if coverage.present?
|
||||||
|
|
|
@ -189,6 +189,12 @@ describe Ci::Build, models: true do
|
||||||
|
|
||||||
it { is_expected.to eq(98.29) }
|
it { is_expected.to eq(98.29) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'using a regex capture' do
|
||||||
|
subject { build.extract_coverage('TOTAL 9926 3489 65%', 'TOTAL\s+\d+\s+\d+\s+(\d{1,3}\%)') }
|
||||||
|
|
||||||
|
it { is_expected.to eq(65) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :variables do
|
describe :variables do
|
||||||
|
|
Loading…
Reference in New Issue