gitlab-org--gitlab-foss/spec/lib/gitlab/popen_spec.rb

44 lines
1 KiB
Ruby
Raw Normal View History

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
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
@output, @status = @klass.new.popen(%w(ls), path)
2013-02-26 15:53:46 -05:00
end
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
@output, @status = @klass.new.popen(%w(cat NOTHING), path)
2013-02-26 15:53:46 -05:00
end
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
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(RuntimeError)
end
end
context 'without a directory argument' do
before do
@output, @status = @klass.new.popen(%w(ls))
end
it { expect(@status).to be_zero }
it { expect(@output).to include('spec') }
end
2013-02-26 15:53:46 -05:00
end