spec/rake/funnel/extensions/shell_spec.rb in rake-funnel-0.21.0 vs spec/rake/funnel/extensions/shell_spec.rb in rake-funnel-0.21.1

- old
+ new

@@ -1,15 +1,13 @@ require 'open3' -include Rake::Funnel - describe Rake::Funnel::Extensions::Shell do before do allow(Open3).to receive(:popen2e).and_yield(nil, stdout_and_stderr, exit) allow($stdout).to receive(:puts) - allow($stderr).to receive(:puts) + allow(Kernel).to receive(:warn) allow(Rake).to receive(:rake_output_message) end let(:exit) { OpenStruct.new(value: OpenStruct.new(success?: true, exitstatus: 0)) } @@ -124,17 +122,17 @@ let(:error_lines) { /error/ } before do begin subject.shell('foo', error_lines: error_lines) - rescue ExecutionError # rubocop:disable Lint/HandleExceptions + rescue Rake::Funnel::ExecutionError # rubocop:disable Lint/HandleExceptions end end context 'no lines indicating errors' do it 'should not log to stderr' do - expect($stderr).not_to have_received(:puts) + expect(Kernel).not_to have_received(:warn) end end context 'lines indicating errors' do let(:stdout_and_stderr) { StringIO.new("output 1\nerror\noutput 2\n") } @@ -142,19 +140,19 @@ it 'should log to stdout before error' do expect($stdout).to have_received(:puts).with(/output 1/) end it 'should log to stderr on error' do - expect($stderr).to have_received(:puts).with(/error/) + expect(Kernel).to have_received(:warn).with(/error/) end it 'should not log to stdout on error' do expect($stdout).not_to have_received(:puts).with(/error/) end it 'should colorize error lines' do - expect($stderr).to have_received(:puts).with('error'.bold.red) + expect(Kernel).to have_received(:warn).with('error'.bold.red) end it 'should log to stdout after error' do expect($stdout).to have_received(:puts).with(/output 2/) end @@ -162,11 +160,11 @@ context 'lines with different encoding' do let(:stdout_and_stderr) { StringIO.new('error äöüß'.encode('CP850')) } it 'should log to stdout before error' do - expect($stderr).to have_received(:puts).with(/error/) + expect(Kernel).to have_received(:warn).with(/error/) end end end describe 'callback block' do @@ -193,11 +191,11 @@ describe 'failure' do context 'error lines logged' do context 'without block' do it 'should fail' do - expect { subject.shell('foo', error_lines: /.*/) }.to raise_error(ExecutionError) + expect { subject.shell('foo', error_lines: /.*/) }.to raise_error(Rake::Funnel::ExecutionError) end end context 'with block' do it 'should not fail' do @@ -216,10 +214,10 @@ context 'error exit' do let(:exit) { OpenStruct.new(value: OpenStruct.new(success?: false, exitstatus: 1)) } context 'without block' do it 'should fail' do - expect { subject.shell('foo') }.to raise_error(ExecutionError) + expect { subject.shell('foo') }.to raise_error(Rake::Funnel::ExecutionError) end it 'should report the exit code' do expect { subject.shell('foo') } .to(raise_error { |e| expect(e.exit_code).to eq(exit.value.exitstatus) })