mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-12 05:31:14 +02:00
60cf569776
When calling git any error messages should be suppressed (e.g. if an directory is not inside a git repository). Closing the stderr output when calling `IO.popen` works fine on POSIX systems, but on Windows it does not and spits out a warning for every invocation: ``` git.rb:44: warning: cannot close fd before spawn ``` Fixes #517.
48 lines
1.6 KiB
Ruby
48 lines
1.6 KiB
Ruby
# frozen_string_literal: false
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe ColorLS::Git do
|
|
before(:all) do # rubocop:todo RSpec/BeforeAfterAll
|
|
`echo` # initialize $CHILD_STATUS
|
|
expect($CHILD_STATUS).to be_success # rubocop:todo RSpec/ExpectInHook
|
|
end
|
|
|
|
context 'with file in repository root' do
|
|
it 'returns `M`' do
|
|
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
|
allow(subject).to receive(:git_subdir_status).and_yield('M', 'foo.txt')
|
|
|
|
expect(subject.status('/repo/')).to include('foo.txt' => Set['M'])
|
|
end
|
|
|
|
it 'returns `??`' do
|
|
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
|
allow(subject).to receive(:git_subdir_status).and_yield('??', 'foo.txt')
|
|
|
|
expect(subject.status('/repo/')).to include('foo.txt' => Set['??'])
|
|
end
|
|
end
|
|
|
|
context 'with file in subdir' do
|
|
it 'returns `M` for subdir' do
|
|
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
|
allow(subject).to receive(:git_subdir_status).and_yield('M', 'subdir/foo.txt')
|
|
|
|
expect(subject.status('/repo/')).to include('subdir' => Set['M'])
|
|
end
|
|
|
|
it 'returns `M` and `D` for subdir' do
|
|
allow(subject).to receive(:git_prefix).with('/repo/').and_return(['', true])
|
|
allow(subject).to receive(:git_subdir_status).and_yield('M', 'subdir/foo.txt').and_yield('D', 'subdir/other.c')
|
|
|
|
expect(subject.status('/repo/')).to include('subdir' => Set['M', 'D'])
|
|
end
|
|
end
|
|
|
|
context 'determining the git status' do
|
|
it 'does not output to stderr' do
|
|
expect { subject.status('.') }.not_to output.to_stderr
|
|
end
|
|
end
|
|
end
|