2013-02-26 15:53:46 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Gitlab::Popen', no_db: true do
|
|
|
|
let (:path) { Rails.root.join('tmp').to_s }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it { @status.should be_zero }
|
2013-02-27 01:24:12 -05:00
|
|
|
it { @output.should 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
|
|
|
|
|
|
|
|
it { @status.should == 1 }
|
|
|
|
it { @output.should include('No such file or directory') }
|
|
|
|
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
|
|
|
|
expect { @klass.new.popen('ls', path) }.to raise_error
|
|
|
|
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
|
|
|
|
|
|
|
|
it { @status.should be_zero }
|
|
|
|
it { @output.should include('spec') }
|
|
|
|
end
|
|
|
|
|
2013-02-26 15:53:46 -05:00
|
|
|
end
|
|
|
|
|