spec/rake/funnel/integration/teamcity/progress_report_spec.rb in rake-funnel-0.18.0 vs spec/rake/funnel/integration/teamcity/progress_report_spec.rb in rake-funnel-0.19.0

- old
+ new

@@ -1,34 +1,36 @@ +# rubocop:disable RSpec/FilePath + include Rake include Rake::Funnel::Integration include Rake::Funnel::Integration::TeamCity describe Rake::Funnel::Integration::TeamCity::ProgressReport do include DSL let(:teamcity_running?) { false } let(:teamcity_rake_runner?) { false } - before { + before do allow(TeamCity).to receive(:running?).and_return(teamcity_running?) allow(TeamCity).to receive(:rake_runner?).and_return(teamcity_rake_runner?) allow(ServiceMessages).to receive(:block_opened) allow(ServiceMessages).to receive(:block_closed) allow(ServiceMessages).to receive(:progress_start) allow(ServiceMessages).to receive(:progress_finish) allow(ServiceMessages).to receive(:build_problem) Task.clear - } + end - subject! { + subject! do described_class.new - } + end - after { + after do subject.disable! - } + end shared_examples :block_report do it 'should write block start' do expect(ServiceMessages).to have_received(:block_opened).with(name: 'task') end @@ -47,18 +49,18 @@ expect(ServiceMessages).not_to have_received(:block_closed) end end context 'when task succeeds' do - before { + before do task :task Task[:task].invoke - } + end it 'should not report build problems' do - expect(ServiceMessages).to_not have_received(:build_problem) + expect(ServiceMessages).not_to have_received(:build_problem) end context 'not on TeamCity' do it_behaves_like :no_block_report end @@ -79,42 +81,41 @@ end context 'when task fails' do class SpecificError < StandardError; end - before { + before do module Rake class ApplicationAbortedException < StandardError attr_reader :inner_exception def initialize(other_exception) @inner_exception = other_exception end end end - } + end let(:error) { SpecificError.new('task error' * 4000) } - before { + before do task :task do raise error end begin Task[:task].invoke - rescue ApplicationAbortedException => e - rescue SpecificError => e + rescue ApplicationAbortedException, SpecificError => e @raised_error = e end - } + end context 'not on TeamCity' do it_behaves_like :no_block_report it 'should not swallow the error' do - expect(@raised_error).to be_a_kind_of(SpecificError) + expect(@raised_error).to be_a_kind_of(SpecificError) # rubocop:disable RSpec/InstanceVariable end end context 'on TeamCity' do let(:teamcity_running?) { true } @@ -123,15 +124,19 @@ it 'should report build problems' do expect(ServiceMessages).to have_received(:build_problem) end it 'should report the error message' do - expect(ServiceMessages).to have_received(:build_problem).with(hash_including({ description: be_an_instance_of(String) })) + expect(ServiceMessages).to \ + have_received(:build_problem) + .with(hash_including(description: be_an_instance_of(String))) end it 'should report the first 4000 characters of the error message' do - expect(ServiceMessages).to have_received(:build_problem).with(hash_including({ description: have(4000).items })) + expect(ServiceMessages).to \ + have_received(:build_problem) + .with(hash_including(description: have(4000).items)) end end context 'without rake runner' do it_behaves_like :block_report @@ -141,34 +146,35 @@ end end context 'with rake runner' do let(:teamcity_rake_runner?) { true } - let(:error) { + let(:error) do ApplicationAbortedException.new(SpecificError.new('inner message')) - } + end - it 'should report the inner error as a build problem (as it will be wrapped in a ApplicationAbortedException)' do - expect(ServiceMessages).to have_received(:build_problem).with({ description: 'inner message' }) + it 'should report the inner error as a build problem (as it will be wrapped in a ApplicationAbortedException)' do # rubocop:disable Metrics/LineLength + expect(ServiceMessages).to \ + have_received(:build_problem).with(description: 'inner message') end it_behaves_like :no_block_report end end end context 'when progess report was disabled' do let(:teamcity_running?) { true } - before { + before do subject.disable! task :task Task[:task].invoke - } + end it 'should not write' do - expect(ServiceMessages).to_not have_received(:block_opened) + expect(ServiceMessages).not_to have_received(:block_opened) end end end