spec/rake/funnel/integration/teamcity/service_messages_spec.rb in rake-funnel-0.22.1 vs spec/rake/funnel/integration/teamcity/service_messages_spec.rb in rake-funnel-0.22.2

- old
+ new

@@ -1,18 +1,18 @@ describe Rake::Funnel::Integration::TeamCity::ServiceMessages do # rubocop:disable RSpec/FilePath before do allow(Rake::Funnel::Integration::TeamCity).to receive(:running?).and_return(teamcity_running?) - allow($stdout).to receive(:puts) + allow(described_class).to receive(:print) end context 'when running outside TeamCity' do let(:teamcity_running?) { false } it 'should not publish messages' do described_class.progress_start 'foo' - expect($stdout).not_to have_received(:puts) + expect(described_class).not_to have_received(:print) end end context 'when running inside TeamCity' do let(:teamcity_running?) { true } @@ -20,156 +20,156 @@ describe 'escaping' do context 'when publishing messages without special characters' do it 'should not escape' do described_class.progress_start 'the message' - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart 'the message']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart 'the message']\n") end end context 'when publishing messages with special characters' do it 'should escape apostrophes' do described_class.progress_start "'" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|'']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|'']\n") end it 'should escape line feeds' do described_class.progress_start "\n" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|n']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|n']\n") end it 'should escape carriage returns' do described_class.progress_start "\r" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|r']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|r']\n") end it 'should escape next lines' do described_class.progress_start "\u0085" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|x']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|x']\n") end it 'should escape line separators' do described_class.progress_start "\u2028" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|l']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|l']\n") end it 'should escape paragraph separators' do described_class.progress_start "\u2029" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|p']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|p']\n") end it 'should escape vertical bars' do described_class.progress_start '|' - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '||']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '||']\n") end it 'should escape opening brackets' do described_class.progress_start '[' - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|[']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|[']\n") end it 'should escape closing brackets' do described_class.progress_start ']' - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|]']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|]']\n") end it 'should escape all special characters in a string' do described_class.progress_start "[\r|\n]" - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressStart '|[|r|||n|]']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressStart '|[|r|||n|]']\n") end end end describe 'parameters' do context 'when reporting a message without parameters' do it 'should print the service message' do described_class.enable_service_messages - expect($stdout).to \ - have_received(:puts) - .with('##teamcity[enableServiceMessages]') + expect(described_class).to \ + have_received(:print) + .with("##teamcity[enableServiceMessages]\n") end end context 'when reporting a message with an unnamed parameter' do it 'should print the service message' do described_class.progress_message 'the message' - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressMessage 'the message']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressMessage 'the message']\n") end end context 'when reporting a message with an unnamed non-string parameter' do it 'should print the service message' do described_class.progress_message 42 - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[progressMessage '42']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[progressMessage '42']\n") end end context 'when reporting a message with a named parameter' do it 'should print the service message' do described_class.block_opened(name: 'block name') - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[blockOpened name='block name']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[blockOpened name='block name']\n") end end context 'when reporting a message with multiple named parameters' do it 'should print the service message' do described_class.test_started(name: 'test name', captureStandardOutput: true) - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[testStarted name='test name' captureStandardOutput='true']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[testStarted name='test name' captureStandardOutput='true']\n") end end context 'when reporting a message with Ruby-style named parameters' do it 'should print the service message' do described_class.test_started(capture_standard_output: true) - expect($stdout).to \ - have_received(:puts) - .with("##teamcity[testStarted captureStandardOutput='true']") + expect(described_class).to \ + have_received(:print) + .with("##teamcity[testStarted captureStandardOutput='true']\n") end end end end end