From 0713a7c3a9eb1bcfdf6adde0c3365549c19a3ee1 Mon Sep 17 00:00:00 2001 From: Leandro Camargo Date: Mon, 21 Nov 2016 02:38:03 -0200 Subject: Add specs to cover the implemented feature and fix a small bug --- spec/models/ci/build_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'spec/models/ci') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index f031876e812..9e5481017e2 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -221,6 +221,39 @@ describe Ci::Build, :models do end end + describe '#coverage_regex' do + subject { build.coverage_regex } + let(:project_regex) { '\(\d+\.\d+\) covered' } + let(:build_regex) { 'Code coverage: \d+\.\d+' } + + context 'when project has build_coverage_regex set' do + before { project.build_coverage_regex = project_regex } + + context 'and coverage_regex attribute is not set' do + it { is_expected.to eq(project_regex) } + end + + context 'but coverage_regex attribute is also set' do + before { build.coverage_regex = build_regex } + it { is_expected.to eq(build_regex) } + end + end + + context 'when neither project nor build has coverage regex set' do + it { is_expected.to be_nil } + end + end + + describe '#update_coverage' do + it 'grants coverage_regex method is called inside of it' do + build.coverage_regex = '\(\d+.\d+\%\) covered' + allow(build).to receive(:trace) { 'Coverage 1033 / 1051 LOC (98.29%) covered' } + allow(build).to receive(:coverage_regex).and_call_original + allow(build).to receive(:update_attributes).with(coverage: 98.29) { true } + expect(build.update_coverage).to be true + end + end + describe 'deployment' do describe '#last_deployment' do subject { build.last_deployment } -- cgit v1.2.1