debian-mirror-gitlab/spec/lib/gitlab/popen_spec.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe 'Gitlab::Popen', lib: true, no_db: true do
2015-09-11 14:41:01 +05:30
let(:path) { Rails.root.join('tmp').to_s }
2014-09-02 18:07:02 +05:30
before do
@klass = Class.new(Object)
@klass.send(:include, Gitlab::Popen)
end
context 'zero status' do
before do
2016-08-24 12:49:21 +05:30
@output, @status = @klass.new.popen(%w(ls), path)
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
it { expect(@status).to be_zero }
it { expect(@output).to include('cache') }
2014-09-02 18:07:02 +05:30
end
context 'non-zero status' do
before do
2016-08-24 12:49:21 +05:30
@output, @status = @klass.new.popen(%w(cat NOTHING), path)
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
it { expect(@status).to eq(1) }
it { expect(@output).to include('No such file or directory') }
2014-09-02 18:07:02 +05:30
end
context 'unsafe string command' do
it 'raises an error when it gets called with a string argument' do
2015-09-11 14:41:01 +05:30
expect { @klass.new.popen('ls', path) }.to raise_error(RuntimeError)
2014-09-02 18:07:02 +05:30
end
end
context 'without a directory argument' do
before do
2016-08-24 12:49:21 +05:30
@output, @status = @klass.new.popen(%w(ls))
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
it { expect(@status).to be_zero }
it { expect(@output).to include('spec') }
2014-09-02 18:07:02 +05:30
end
2016-09-29 09:46:39 +05:30
context 'use stdin' do
before do
@output, @status = @klass.new.popen(%w[cat]) { |stdin| stdin.write 'hello' }
end
it { expect(@status).to be_zero }
it { expect(@output).to eq('hello') }
end
2014-09-02 18:07:02 +05:30
end