2013-02-26 15:53:46 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe 'Gitlab::Popen', lib: true, no_db: true do
|
2015-06-22 08:39:07 -04:00
|
|
|
let(:path) { Rails.root.join('tmp').to_s }
|
2013-02-26 15:53:46 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
@klass = Class.new(Object)
|
|
|
|
@klass.send(:include, Gitlab::Popen)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'zero status' do
|
|
|
|
before do
|
2014-02-25 05:57:42 -05:00
|
|
|
@output, @status = @klass.new.popen(%W(ls), path)
|
2013-02-26 15:53:46 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@status).to be_zero }
|
|
|
|
it { expect(@output).to include('cache') }
|
2013-02-26 15:53:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'non-zero status' do
|
|
|
|
before do
|
2014-02-25 05:57:42 -05:00
|
|
|
@output, @status = @klass.new.popen(%W(cat NOTHING), path)
|
2013-02-26 15:53:46 -05:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@status).to eq(1) }
|
|
|
|
it { expect(@output).to include('No such file or directory') }
|
2013-02-26 15:53:46 -05:00
|
|
|
end
|
2014-02-25 05:57:42 -05:00
|
|
|
|
|
|
|
context 'unsafe string command' do
|
|
|
|
it 'raises an error when it gets called with a string argument' do
|
2015-06-17 21:29:18 -04:00
|
|
|
expect { @klass.new.popen('ls', path) }.to raise_error(RuntimeError)
|
2014-02-25 05:57:42 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-25 05:58:22 -05:00
|
|
|
context 'without a directory argument' do
|
|
|
|
before do
|
|
|
|
@output, @status = @klass.new.popen(%W(ls))
|
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@status).to be_zero }
|
|
|
|
it { expect(@output).to include('spec') }
|
2014-02-25 05:58:22 -05:00
|
|
|
end
|
2013-02-26 15:53:46 -05:00
|
|
|
end
|