Use rubocop's default include configuration and fix all offenses

This commit is contained in:
Claudio Bley 2020-12-22 14:33:53 +01:00
parent 09628b3ec1
commit 7f0af24ada
12 changed files with 215 additions and 176 deletions

View file

@ -3,15 +3,10 @@ require:
- rubocop-rake - rubocop-rake
AllCops: AllCops:
Include:
- 'lib/**/*'
- 'Rakefile'
Exclude: Exclude:
- 'vendor/**/*' - 'vendor/**/*'
- 'benchmarks/*' - 'benchmarks/*'
- 'profile/*' - 'profile/*'
- 'lib/yaml/*'
- 'lib/**/*.sh'
DisplayCopNames: true DisplayCopNames: true
NewCops: enable NewCops: enable
TargetRubyVersion: 2.5 TargetRubyVersion: 2.5

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org' source 'https://rubygems.org'
gemspec gemspec

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
lib = File.expand_path('lib', __dir__) lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'colorls/version' require 'colorls/version'
@ -21,7 +23,7 @@ POST_INSTALL_MESSAGE = %(
Man pages have been added. Checkout `man colorls`. Man pages have been added. Checkout `man colorls`.
******************************************************************* *******************************************************************
).freeze )
# rubocop:disable Metrics/BlockLength # rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
@ -47,7 +49,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.5.0' spec.required_ruby_version = '>= 2.5.0'
spec.files = IO.popen( spec.files = IO.popen(
%w[git ls-files -z], external_encoding: Encoding::ASCII_8BIT %w[git ls-files -z], external_encoding: Encoding::ASCII_8BIT
).read.split("\x0").reject do |f| ).read.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/}) f.match(%r{^(test|spec|features)/})

View file

@ -1,4 +1,5 @@
# coding: utf-8 # frozen_string_literal: false
require 'spec_helper' require 'spec_helper'
RSpec.describe ColorLS::Core do RSpec.describe ColorLS::Core do
@ -6,59 +7,59 @@ RSpec.describe ColorLS::Core do
context 'ls' do context 'ls' do
it 'works with Unicode characters' do it 'works with Unicode characters' do
camera = 'Cámara'.force_encoding(ColorLS::file_encoding) camera = 'Cámara'.force_encoding(ColorLS.file_encoding)
imagenes = 'Imágenes'.force_encoding(ColorLS::file_encoding) imagenes = 'Imágenes'.force_encoding(ColorLS.file_encoding)
dirInfo = instance_double( dir_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => true, directory?: true,
:owner => "user", owner: 'user',
:name => imagenes, name: imagenes,
:show => imagenes, show: imagenes,
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: false, setuid?: false,
setgid?: false, setgid?: false,
sticky?: false sticky?: false
), ),
:executable? => true executable?: true
) )
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => camera, name: camera,
:show => camera, show: camera,
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: false, setuid?: false,
setgid?: false, setgid?: false,
sticky?: false sticky?: false
), ),
:executable? => false executable?: false
) )
expect(::Dir).to receive(:entries).and_return([camera]) expect(::Dir).to receive(:entries).and_return([camera])
allow(ColorLS::FileInfo).to receive(:new).and_return(dirInfo) allow(ColorLS::FileInfo).to receive(:new).and_return(dir_info)
allow(ColorLS::FileInfo).to receive(:new).with(File.join(imagenes, camera), link_info: false) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with(File.join(imagenes, camera), link_info: false) { file_info }
expect { subject.ls('Imágenes') }.to output(/mara/).to_stdout expect { subject.ls('Imágenes') }.to output(/mara/).to_stdout
end end

View file

@ -1,27 +1,30 @@
# coding: utf-8 # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe ColorLS::Flags do FIXTURES = 'spec/fixtures'
FIXTURES = 'spec/fixtures'.freeze
RSpec.describe ColorLS::Flags do
subject do subject do
begin described_class.new(*args).process
described_class.new(*args).process rescue SystemExit => e
rescue SystemExit => e raise "colorls exited with #{e.status}" unless e.success?
raise "colorls exited with #{e.status}" unless e.success?
end
end end
context 'with no flags' do context 'with no flags' do
let(:args) { [FIXTURES] } let(:args) { [FIXTURES] }
it('does not list file info') { expect { subject }.not_to output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout } it('does not list file info') {
expect do
subject
end.not_to output(/((r|-).*(w|-).*(x|-).*){3}/).to_stdout
}
it('does not display hidden files') { expect { subject }.not_to output(/\.hidden-file/).to_stdout } it('does not display hidden files') { expect { subject }.not_to output(/\.hidden-file/).to_stdout }
it('does not show a report') { expect { subject }.not_to output(/Found \d+ contents/).to_stdout } it('does not show a report') { expect { subject }.not_to output(/Found \d+ contents/).to_stdout }
it('displays dirs & files alphabetically') { expect { subject }.to output(/a-file.+symlinks.+z-file/m).to_stdout } it('displays dirs & files alphabetically') { expect { subject }.to output(/a-file.+symlinks.+z-file/m).to_stdout }
it 'displays multiple files per line' do it 'displays multiple files per line' do
expect(::STDOUT).to receive(:tty?).and_return(true) expect($stdout).to receive(:tty?).and_return(true)
expect { subject }.not_to output(/(.*\n){3}/).to_stdout expect { subject }.not_to output(/(.*\n){3}/).to_stdout
end end
@ -33,16 +36,22 @@ RSpec.describe ColorLS::Flags do
context 'with --reverse flag' do context 'with --reverse flag' do
let(:args) { ['--reverse', '-x', FIXTURES] } let(:args) { ['--reverse', '-x', FIXTURES] }
it('displays dirs & files in reverse alphabetical order') { expect { subject }.to output(/z-file.+symlinks.+a-file/m).to_stdout } it('displays dirs & files in reverse alphabetical order') {
expect do
subject
end.to output(/z-file.+symlinks.+a-file/m).to_stdout
}
end end
context 'with --format flag' do context 'with --format flag' do
let(:args) { ['--format=single-column', FIXTURES] } let(:args) { ['--format=single-column', FIXTURES] }
it { expect { subject }.to output(/.*a-file.*\n # on the first line it {
expect { subject }.to output(/.*a-file.*\n # on the first line
(?m:.*) # more lines... (?m:.*) # more lines...
.*z-file.*\n # on the last line .*z-file.*\n # on the last line
/x).to_stdout } /x).to_stdout
}
end end
context 'with --long flag & file path' do context 'with --long flag & file path' do
@ -61,59 +70,59 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['--long', "#{FIXTURES}/a.txt"] } let(:args) { ['--long', "#{FIXTURES}/a.txt"] }
it 'shows special permission bits' do it 'shows special permission bits' do
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => "a.txt", name: 'a.txt',
:show => "a.txt", show: 'a.txt',
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: true, setuid?: true,
setgid?: true, setgid?: true,
sticky?: true sticky?: true
), ),
:executable? => false executable?: false
) )
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { file_info }
expect { subject }.to output(/r-Sr-Sr-T .* a.txt/mx).to_stdout expect { subject }.to output(/r-Sr-Sr-T .* a.txt/mx).to_stdout
end end
it 'shows number of hardlinks' do it 'shows number of hardlinks' do
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => "a.txt", name: 'a.txt',
:show => "a.txt", show: 'a.txt',
:nlink => 5, # number of hardlinks nlink: 5, # number of hardlinks
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: true, setuid?: true,
setgid?: true, setgid?: true,
sticky?: true sticky?: true
), ),
:executable? => false executable?: false
) )
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { file_info }
expect { subject }.to output(/\S+\s+ 5 .* a.txt/mx).to_stdout expect { subject }.to output(/\S+\s+ 5 .* a.txt/mx).to_stdout
end end
@ -122,10 +131,10 @@ RSpec.describe ColorLS::Flags do
context 'with --long flag on windows' do context 'with --long flag on windows' do
let(:args) { ['--long', "#{FIXTURES}/a.txt"] } let(:args) { ['--long', "#{FIXTURES}/a.txt"] }
before { before do
ColorLS::FileInfo.class_variable_set :@@users, {} ColorLS::FileInfo.class_variable_set :@@users, {} # rubocop:disable Style/ClassVars
ColorLS::FileInfo.class_variable_set :@@groups, {} ColorLS::FileInfo.class_variable_set :@@groups, {} # rubocop:disable Style/ClassVars
} end
it 'returns no user / group info' do it 'returns no user / group info' do
expect(::Etc).to receive(:getpwuid).and_return(nil) expect(::Etc).to receive(:getpwuid).and_return(nil)
@ -144,13 +153,21 @@ RSpec.describe ColorLS::Flags do
context 'with --sort-dirs flag' do context 'with --sort-dirs flag' do
let(:args) { ['--sort-dirs', '-1', FIXTURES] } let(:args) { ['--sort-dirs', '-1', FIXTURES] }
it('sorts results alphabetically, directories first') { expect { subject }.to output(/symlinks.+a-file.+z-file/m).to_stdout } it('sorts results alphabetically, directories first') {
expect do
subject
end.to output(/symlinks.+a-file.+z-file/m).to_stdout
}
end end
context 'with --sort-files flag' do context 'with --sort-files flag' do
let(:args) { ['--sort-files', '-1', FIXTURES] } let(:args) { ['--sort-files', '-1', FIXTURES] }
it('sorts results alphabetically, files first') { expect { subject }.to output(/a-file.+z-file.+symlinks/m).to_stdout } it('sorts results alphabetically, files first') {
expect do
subject
end.to output(/a-file.+z-file.+symlinks/m).to_stdout
}
end end
context 'with --sort=time' do context 'with --sort=time' do
@ -174,7 +191,7 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['--sort=size', '--group-directories-first', '-1', FIXTURES] } let(:args) { ['--sort=size', '--group-directories-first', '-1', FIXTURES] }
it 'sorts results by size' do it 'sorts results by size' do
expect(::STDOUT).to receive(:tty?).and_return(true) expect($stdout).to receive(:tty?).and_return(true)
expect { subject }.to output(/symlinks.+a-file.+z-file/m).to_stdout expect { subject }.to output(/symlinks.+a-file.+z-file/m).to_stdout
end end
@ -213,7 +230,11 @@ RSpec.describe ColorLS::Flags do
context 'with --sort=extension flag' do context 'with --sort=extension flag' do
let(:args) { ['--sort=extension', '-1', FIXTURES] } let(:args) { ['--sort=extension', '-1', FIXTURES] }
it('sorts results by extension') { expect { subject }.to output(/a-file.+symlinks.+z-file.+a.md.+a.txt.+z.txt/m).to_stdout } it('sorts results by extension') {
expect do
subject
end.to output(/a-file.+symlinks.+z-file.+a.md.+a.txt.+z.txt/m).to_stdout
}
end end
context 'with --dirs flag' do context 'with --dirs flag' do
@ -251,7 +272,11 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['--tree=1', FIXTURES] } let(:args) { ['--tree=1', FIXTURES] }
it('displays file hierarchy') { expect { subject }.to output(/├──/).to_stdout } it('displays file hierarchy') { expect { subject }.to output(/├──/).to_stdout }
it { expect { subject }.not_to output(/ReadmeLink.md|Supportlink|doesnotexisttest.txt|third-level-file.txt/).to_stdout } it {
expect do
subject
end.not_to output(/ReadmeLink.md|Supportlink|doesnotexisttest.txt|third-level-file.txt/).to_stdout
}
end end
context 'with --tree=3 flag' do context 'with --tree=3 flag' do
@ -282,7 +307,7 @@ RSpec.describe ColorLS::Flags do
if File.symlink? File.join(FIXTURES, 'symlinks', 'Supportlink') if File.symlink? File.join(FIXTURES, 'symlinks', 'Supportlink')
expect { subject }.to output(/yaml_sort_checker.rb/).to_stdout expect { subject }.to output(/yaml_sort_checker.rb/).to_stdout
else else
skip "symlinks not supported" skip 'symlinks not supported'
end end
end end
end end
@ -292,7 +317,7 @@ RSpec.describe ColorLS::Flags do
it 'should issue a warning, hint about `--help` and exit' do it 'should issue a warning, hint about `--help` and exit' do
allow(::Kernel).to receive(:warn) do |message| allow(::Kernel).to receive(:warn) do |message|
expect(message).to output "--snafu" expect(message).to output '--snafu'
end end
expect { subject }.to raise_error('colorls exited with 2').and output(/--help/).to_stderr expect { subject }.to raise_error('colorls exited with 2').and output(/--help/).to_stderr
@ -303,7 +328,7 @@ RSpec.describe ColorLS::Flags do
let(:args) { [FIXTURES] } let(:args) { [FIXTURES] }
it 'should warn but not raise an error' do it 'should warn but not raise an error' do
allow(CLocale).to receive(:setlocale).with(CLocale::LC_COLLATE, '').and_raise(RuntimeError.new("setlocale error")) allow(CLocale).to receive(:setlocale).with(CLocale::LC_COLLATE, '').and_raise(RuntimeError.new('setlocale error'))
expect { subject }.to output(/setlocale error/).to_stderr.and output.to_stdout expect { subject }.to output(/setlocale error/).to_stderr.and output.to_stdout
end end
@ -321,7 +346,7 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['not_exist_file'] } let(:args) { ['not_exist_file'] }
it 'should exit with status code 2' do it 'should exit with status code 2' do
expect {subject}.to output(/ Specified path 'not_exist_file' doesn't exist./).to_stderr expect { subject }.to output(/ Specified path 'not_exist_file' doesn't exist./).to_stderr
expect(subject).to eq 2 expect(subject).to eq 2
end end
end end
@ -330,30 +355,30 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['-o', "#{FIXTURES}/a.txt"] } let(:args) { ['-o', "#{FIXTURES}/a.txt"] }
before do before do
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => "a.txt", name: 'a.txt',
:show => "a.txt", show: 'a.txt',
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: true, setuid?: true,
setgid?: true, setgid?: true,
sticky?: true sticky?: true
), ),
:executable? => false executable?: false
) )
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { file_info }
end end
it 'lists without group info' do it 'lists without group info' do
@ -368,30 +393,30 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['-g', "#{FIXTURES}/a.txt"] } let(:args) { ['-g', "#{FIXTURES}/a.txt"] }
before do before do
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => "a.txt", name: 'a.txt',
:show => "a.txt", show: 'a.txt',
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: true, setuid?: true,
setgid?: true, setgid?: true,
sticky?: true sticky?: true
), ),
:executable? => false executable?: false
) )
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { file_info }
end end
it 'lists with group info' do it 'lists with group info' do
@ -406,30 +431,30 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['-og', "#{FIXTURES}/a.txt"] } let(:args) { ['-og', "#{FIXTURES}/a.txt"] }
before do before do
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => "a.txt", name: 'a.txt',
:show => "a.txt", show: 'a.txt',
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: true, setuid?: true,
setgid?: true, setgid?: true,
sticky?: true sticky?: true
), ),
:executable? => false executable?: false
) )
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { file_info }
end end
it 'lists without group info' do it 'lists without group info' do
@ -444,30 +469,30 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['-l', '-G', "#{FIXTURES}/a.txt"] } let(:args) { ['-l', '-G', "#{FIXTURES}/a.txt"] }
before do before do
fileInfo = instance_double( file_info = instance_double(
'FileInfo', 'FileInfo',
:group => "sys", group: 'sys',
:mtime => Time.now, mtime: Time.now,
:directory? => false, directory?: false,
:owner => "user", owner: 'user',
:name => "a.txt", name: 'a.txt',
:show => "a.txt", show: 'a.txt',
:nlink => 1, nlink: 1,
:size => 128, size: 128,
:blockdev? => false, blockdev?: false,
:chardev? => false, chardev?: false,
:socket? => false, socket?: false,
:symlink? => false, symlink?: false,
:stats => OpenStruct.new( stats: OpenStruct.new(
mode: 0o444, # read for user, owner, other mode: 0o444, # read for user, owner, other
setuid?: true, setuid?: true,
setgid?: true, setgid?: true,
sticky?: true sticky?: true
), ),
:executable? => false executable?: false
) )
allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { file_info }
end end
it 'lists without group info' do it 'lists without group info' do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe ColorLS::Git do RSpec.describe ColorLS::Git do
@ -7,20 +9,20 @@ RSpec.describe ColorLS::Git do
end end
def git_status(*entries) def git_status(*entries)
StringIO.new entries.map { |line| line + "\x0" }.join StringIO.new entries.map { |line| "#{line}\u0000" }.join
end end
context 'file in repository root' do context 'file in repository root' do
it 'should return `M`' do it 'should return `M`' do
allow(subject).to receive(:git_prefix).with('/repo/').and_return('') allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
allow(subject).to receive(:git_subdir_status).and_yield(git_status(" M foo.txt")) allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M foo.txt'))
expect(subject.status('/repo/')).to include('foo.txt' => Set['M']) expect(subject.status('/repo/')).to include('foo.txt' => Set['M'])
end end
it 'should return `M`' do it 'should return `M`' do
allow(subject).to receive(:git_prefix).with('/repo/').and_return('') allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
allow(subject).to receive(:git_subdir_status).and_yield(git_status("?? foo.txt")) allow(subject).to receive(:git_subdir_status).and_yield(git_status('?? foo.txt'))
expect(subject.status('/repo/')).to include('foo.txt' => Set['??']) expect(subject.status('/repo/')).to include('foo.txt' => Set['??'])
end end
@ -29,14 +31,14 @@ RSpec.describe ColorLS::Git do
context 'file in subdir' do context 'file in subdir' do
it 'should return `M` for subdir' do it 'should return `M` for subdir' do
allow(subject).to receive(:git_prefix).with('/repo/').and_return('') allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
allow(subject).to receive(:git_subdir_status).and_yield(git_status(" M subdir/foo.txt")) allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M subdir/foo.txt'))
expect(subject.status('/repo/')).to include('subdir' => Set['M']) expect(subject.status('/repo/')).to include('subdir' => Set['M'])
end end
it 'should return `M` and `D` for subdir' do it 'should return `M` and `D` for subdir' do
allow(subject).to receive(:git_prefix).with('/repo/').and_return('') allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
allow(subject).to receive(:git_subdir_status).and_yield(git_status(" M subdir/foo.txt", "D subdir/other.c")) allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M subdir/foo.txt', 'D subdir/other.c'))
expect(subject.status('/repo/')).to include('subdir' => Set['M', 'D']) expect(subject.status('/repo/')).to include('subdir' => Set['M', 'D'])
end end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do

View file

@ -1,9 +1,11 @@
# frozen_string_literal: true
require 'colorls/monkeys' require 'colorls/monkeys'
RSpec.describe String, '#uniq' do RSpec.describe String, '#uniq' do
it 'removes all duplicate characters' do it 'removes all duplicate characters' do
expect('abca'.uniq).to be == 'abc' expect('abca'.uniq).to be == 'abc'
end end
end end
RSpec.describe String, '#colorize' do RSpec.describe String, '#colorize' do

View file

@ -1,11 +1,13 @@
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe ColorLS::Yaml do RSpec.describe ColorLS::Yaml do
::FILENAMES = { ::FILENAMES = {
file_aliases: :value, file_aliases: :value,
folder_aliases: :value, folder_aliases: :value,
folders: :key, folders: :key,
files: :key files: :key
}.freeze }.freeze
let(:base_directory) { 'lib/yaml' } let(:base_directory) { 'lib/yaml' }

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe ColorLS do RSpec.describe ColorLS do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'simplecov' require 'simplecov'
SimpleCov.start do SimpleCov.start do
@ -12,7 +14,7 @@ end
require 'bundler/setup' require 'bundler/setup'
require 'colorls' require 'colorls'
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file } Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |file| require file }
# disable rainbow globally to ease checking expected output # disable rainbow globally to ease checking expected output
Rainbow.enabled = false Rainbow.enabled = false

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'yaml' require 'yaml'
require 'diffy' require 'diffy'