BigW Consortium Gitlab

popen_spec.rb 1.02 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe 'Gitlab::Popen', lib: true, no_db: true do
4
  let(:path) { Rails.root.join('tmp').to_s }
5 6 7 8 9 10 11 12

  before do
    @klass = Class.new(Object)
    @klass.send(:include, Gitlab::Popen)
  end

  context 'zero status' do
    before do
13
      @output, @status = @klass.new.popen(%W(ls), path)
14 15
    end

16 17
    it { expect(@status).to be_zero }
    it { expect(@output).to include('cache') }
18 19 20 21
  end

  context 'non-zero status' do
    before do
22
      @output, @status = @klass.new.popen(%W(cat NOTHING), path)
23 24
    end

25 26
    it { expect(@status).to eq(1) }
    it { expect(@output).to include('No such file or directory') }
27
  end
28 29 30

  context 'unsafe string command' do
    it 'raises an error when it gets called with a string argument' do
31
      expect { @klass.new.popen('ls', path) }.to raise_error(RuntimeError)
32 33 34
    end
  end

35 36 37 38 39
  context 'without a directory argument' do
    before do
      @output, @status = @klass.new.popen(%W(ls))
    end

40 41
    it { expect(@status).to be_zero }
    it { expect(@output).to include('spec') }
42
  end
43
end