spec/rake/funnel/extensions/shell_spec.rb in rake-funnel-0.18.0 vs spec/rake/funnel/extensions/shell_spec.rb in rake-funnel-0.19.0
- old
+ new
@@ -1,17 +1,17 @@
require 'open3'
include Rake::Funnel
describe Rake::Funnel::Extensions::Shell do
- before {
+ 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(Rake).to receive(:rake_output_message)
- }
+ end
let(:exit) { OpenStruct.new(value: OpenStruct.new(success?: true, exitstatus: 0)) }
let(:stdout_and_stderr) { StringIO.new("output 1\noutput 2\n") }
@@ -85,27 +85,27 @@
expect($stdout).to have_received(:puts).with('output 1'.green)
end
end
describe 'log file' do
- before {
+ before do
allow(subject).to receive(:mkdir_p)
allow(File).to receive(:open)
- }
+ end
let(:log_file) { nil }
before { subject.shell('foo', log_file: log_file) }
context 'no log file' do
it 'should not create path to log file' do
- expect(subject).to_not have_received(:mkdir_p)
+ expect(subject).not_to have_received(:mkdir_p)
end
it 'should not write log file' do
- expect(subject).to_not have_received(:mkdir_p)
- expect(File).to_not have_received(:open)
+ expect(subject).not_to have_received(:mkdir_p)
+ expect(File).not_to have_received(:open)
end
end
context 'with log file' do
let(:log_file) { 'tmp/log.txt' }
@@ -121,20 +121,20 @@
end
describe 'error detection' do
let(:error_lines) { /error/ }
- before {
+ before do
begin
subject.shell('foo', error_lines: error_lines)
- rescue ExecutionError
+ rescue ExecutionError # rubocop:disable Lint/HandleExceptions
end
- }
+ end
context 'no lines indicating errors' do
it 'should not log to stderr' do
- expect($stderr).to_not have_received(:puts)
+ expect($stderr).not_to have_received(:puts)
end
end
context 'lines indicating errors' do
let(:stdout_and_stderr) { StringIO.new("output 1\nerror\noutput 2\n") }
@@ -146,11 +146,11 @@
it 'should log to stderr on error' do
expect($stderr).to have_received(:puts).with(/error/)
end
it 'should not log to stdout on error' do
- expect($stdout).to_not have_received(:puts).with(/error/)
+ 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)
end
@@ -203,11 +203,14 @@
it 'should not fail' do
expect { subject.shell('foo', error_lines: /.*/) {} }.not_to raise_error
end
it 'should yield the error' do
- expect { |b| subject.shell('foo', error_lines: /.*/, &b) }.to yield_with_args(false, 'foo', 0, /output/)
+ expect { |b| subject.shell('foo', error_lines: /.*/, &b) }.to yield_with_args(false,
+ 'foo',
+ 0,
+ /output/)
end
end
end
context 'error exit' do
@@ -217,28 +220,34 @@
it 'should fail' do
expect { subject.shell('foo') }.to raise_error(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) }
+ expect { subject.shell('foo') }
+ .to(raise_error { |e| expect(e.exit_code).to eq(exit.value.exitstatus) })
end
it 'should report the command that was run' do
- expect { subject.shell('foo') }.to raise_error { |e| expect(e.command).to eq('foo') }
+ expect { subject.shell('foo') }
+ .to(raise_error { |e| expect(e.command).to eq('foo') })
end
it 'should report logged lines' do
- expect { subject.shell('foo') }.to raise_error { |e| expect(e.output).to eq(stdout_and_stderr.string) }
+ expect { subject.shell('foo') }
+ .to(raise_error { |e| expect(e.output).to eq(stdout_and_stderr.string) })
end
end
context 'with block' do
it 'should not fail' do
expect { subject.shell('foo') {} }.not_to raise_error
end
it 'should yield the error' do
- expect { |b| subject.shell('foo', error_lines: /.*/, &b) }.to yield_with_args(false, 'foo', 1, /output/)
+ expect { |b| subject.shell('foo', error_lines: /.*/, &b) }.to yield_with_args(false,
+ 'foo',
+ 1,
+ /output/)
end
end
end
end
end