Fix rubocop-rspec offenses or disable them

This commit is contained in:
Claudio Bley 2020-12-22 21:22:41 +01:00
parent 45f5162644
commit e39703a3b5
7 changed files with 60 additions and 36 deletions

View file

@ -117,3 +117,15 @@ Metrics/PerceivedComplexity:
Style/Documentation:
Enabled: false
RSpec/NamedSubject:
Enabled: false
RSpec/SubjectStub:
Enabled: false
RSpec/ExampleLength:
Enabled: false
RSpec/ContextWording:
Enabled: false

View file

@ -56,7 +56,7 @@ RSpec.describe ColorLS::Core do
executable?: false
)
expect(::Dir).to receive(:entries).and_return([camera])
allow(::Dir).to receive(:entries).and_return([camera])
allow(ColorLS::FileInfo).to receive(:new).and_return(dir_info)
allow(ColorLS::FileInfo).to receive(:new).with(File.join(imagenes, camera), link_info: false) { file_info }

View file

@ -19,12 +19,13 @@ RSpec.describe ColorLS::Flags 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 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 multiple files per line' do
expect($stdout).to receive(:tty?).and_return(true)
allow($stdout).to receive(:tty?).and_return(true)
expect { subject }.not_to output(/(.*\n){3}/).to_stdout
end
@ -137,8 +138,8 @@ RSpec.describe ColorLS::Flags do
end
it 'returns no user / group info' do
expect(::Etc).to receive(:getpwuid).and_return(nil)
expect(::Etc).to receive(:getgrgid).and_return(nil)
allow(::Etc).to receive(:getpwuid).and_return(nil)
allow(::Etc).to receive(:getgrgid).and_return(nil)
expect { subject }.to output(/\s+ \d+ \s+ \d+ .* a.txt/mx).to_stdout
end
@ -191,7 +192,7 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['--sort=size', '--group-directories-first', '-1', FIXTURES] }
it 'sorts results by size' do
expect($stdout).to receive(:tty?).and_return(true)
allow($stdout).to receive(:tty?).and_return(true)
expect { subject }.to output(/symlinks.+a-file.+z-file/m).to_stdout
end
@ -272,6 +273,7 @@ RSpec.describe ColorLS::Flags do
let(:args) { ['--tree=1', FIXTURES] }
it('displays file hierarchy') { expect { subject }.to output(/├──/).to_stdout }
it {
expect do
subject
@ -303,7 +305,7 @@ RSpec.describe ColorLS::Flags do
context 'symlinked directory with trailing separator' do
let(:args) { ['-x', File.join(FIXTURES, 'symlinks', 'Supportlink', File::SEPARATOR)] }
it 'should show the file in the linked directory' do
it 'shows the file in the linked directory' do
if File.symlink? File.join(FIXTURES, 'symlinks', 'Supportlink')
expect { subject }.to output(/yaml_sort_checker.rb/).to_stdout
else
@ -315,7 +317,7 @@ RSpec.describe ColorLS::Flags do
context 'when passing invalid flags' do
let(:args) { ['--snafu'] }
it 'should issue a warning, hint about `--help` and exit' do
it 'issues a warning, hint about `--help` and exit' do # rubocop:todo RSpec/MultipleExpectations
allow(::Kernel).to receive(:warn) do |message|
expect(message).to output '--snafu'
end
@ -324,10 +326,10 @@ RSpec.describe ColorLS::Flags do
end
end
context 'for invalid locale' do
context 'with invalid locale' do
let(:args) { [FIXTURES] }
it 'should warn but not raise an error' do
it 'warns but not raise an error' do
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
@ -337,7 +339,7 @@ RSpec.describe ColorLS::Flags do
context 'with unrecognized files' do
let(:args) { ['--report', FIXTURES] }
it 'should show a report with unrecognized files' do
it 'shows a report with unrecognized files' do
expect { subject }.to output(/Unrecognized files\s+: 3/).to_stdout
end
end
@ -345,7 +347,7 @@ RSpec.describe ColorLS::Flags do
context 'with non-existent path' do
let(:args) { ['not_exist_file'] }
it 'should exit with status code 2' do
it 'exits with status code 2' do # rubocop:todo RSpec/MultipleExpectations
expect { subject }.to output(/ Specified path 'not_exist_file' doesn't exist./).to_stderr
expect(subject).to eq 2
end
@ -384,6 +386,7 @@ RSpec.describe ColorLS::Flags do
it 'lists without group info' do
expect { subject }.not_to output(/sys/).to_stdout
end
it 'lists with user info' do
expect { subject }.to output(/user/).to_stdout
end
@ -422,6 +425,7 @@ RSpec.describe ColorLS::Flags do
it 'lists with group info' do
expect { subject }.to output(/sys/).to_stdout
end
it 'lists without user info' do
expect { subject }.not_to output(/user/).to_stdout
end
@ -460,6 +464,7 @@ RSpec.describe ColorLS::Flags do
it 'lists without group info' do
expect { subject }.not_to output(/sys/).to_stdout
end
it 'lists without user info' do
expect { subject }.not_to output(/user/).to_stdout
end
@ -498,6 +503,7 @@ RSpec.describe ColorLS::Flags do
it 'lists without group info' do
expect { subject }.not_to output(/sys/).to_stdout
end
it 'lists with user info' do
expect { subject }.to output(/user/).to_stdout
end

View file

@ -3,24 +3,24 @@
require 'spec_helper'
RSpec.describe ColorLS::Git do
before(:all) do
before(:all) do # rubocop:todo RSpec/BeforeAfterAll
`echo` # initialize $CHILD_STATUS
expect($CHILD_STATUS).to be_success
expect($CHILD_STATUS).to be_success # rubocop:todo RSpec/ExpectInHook
end
def git_status(*entries)
StringIO.new entries.map { |line| "#{line}\u0000" }.join
end
context 'file in repository root' do
it 'should return `M`' do
context 'with file in repository root' do
it 'returns `M`' do
allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
allow(subject).to receive(:git_subdir_status).and_yield(git_status(' M foo.txt'))
expect(subject.status('/repo/')).to include('foo.txt' => Set['M'])
end
it 'should return `M`' do
it 'returns `??`' do
allow(subject).to receive(:git_prefix).with('/repo/').and_return('')
allow(subject).to receive(:git_subdir_status).and_yield(git_status('?? foo.txt'))
@ -28,15 +28,15 @@ RSpec.describe ColorLS::Git do
end
end
context 'file in subdir' do
it 'should return `M` for subdir' do
context 'with file in subdir' do
it 'returns `M` for subdir' do
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'))
expect(subject.status('/repo/')).to include('subdir' => Set['M'])
end
it 'should return `M` and `D` for subdir' do
it 'returns `M` and `D` for subdir' do
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'))

View file

@ -2,6 +2,8 @@
require 'spec_helper'
# rubocop:todo RSpec/MultipleDescribes
RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do
subject { described_class.new(array, array.map(&:length), width) }
@ -20,7 +22,7 @@ RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do
let(:array) { [first] }
let(:width) { 11 }
it 'should be on a single line' do
it 'is on a single line' do
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first], [first.size]])
end
end
@ -31,7 +33,7 @@ RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do
let(:array) { [first] }
let(:width) { 1 }
it 'should be on a single column' do
it 'is on a single column' do
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first], [first.size]])
end
end
@ -42,7 +44,7 @@ RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do
let(:array) { [first, 'a'] }
let(:width) { 100 }
it 'should be on a single line' do
it 'is on a single line' do
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first, 'a'], [first.size, 1]])
end
end
@ -53,7 +55,7 @@ RSpec.describe(ColorLS::HorizontalLayout, '#each_line') do
let(:array) { [first, 'a', first] }
let(:width) { first.size + 1 }
it 'should be on two lines' do
it 'is on two lines' do
max_widths = [first.size, 1]
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first, 'a'], max_widths], [[first], max_widths])
end
@ -78,7 +80,7 @@ RSpec.describe(ColorLS::VerticalLayout, '#each_line') do
let(:array) { [first] }
let(:width) { 11 }
it 'should be on a single line' do
it 'is on a single line' do
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first], [first.size]])
end
end
@ -89,7 +91,7 @@ RSpec.describe(ColorLS::VerticalLayout, '#each_line') do
let(:array) { [first] }
let(:width) { 1 }
it 'should be on a single column' do
it 'is on a single column' do
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first], [first.size]])
end
end
@ -100,7 +102,7 @@ RSpec.describe(ColorLS::VerticalLayout, '#each_line') do
let(:array) { [first, 'a'] }
let(:width) { 100 }
it 'should be on a single line' do
it 'is on a single line' do
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first, 'a'], [first.size, 1]])
end
end
@ -111,9 +113,11 @@ RSpec.describe(ColorLS::VerticalLayout, '#each_line') do
let(:array) { [first, 'a', first] }
let(:width) { first.size * 2 }
it 'should be on two lines' do
it 'is on two lines' do
max_widths = [first.size, first.size]
expect { |b| subject.each_line(&b) }.to yield_successive_args([[first, first], max_widths], [['a'], max_widths])
end
end
end
# rubocop:enable RSpec/MultipleDescribes

View file

@ -2,14 +2,16 @@
require 'colorls/monkeys'
RSpec.describe String, '#uniq' do
RSpec.describe String do # rubocop:disable RSpec/FilePath
describe '#uniq' do
it 'removes all duplicate characters' do
expect('abca'.uniq).to be == 'abc'
end
end
end
RSpec.describe String, '#colorize' do
describe String, '#colorize' do
it 'colors a string with red' do
expect('hello'.colorize(:red)).to be == Rainbow('hello').red
end
end
end

View file

@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe ColorLS::Yaml do
::FILENAMES = {
filenames = {
file_aliases: :value,
folder_aliases: :value,
folders: :key,
@ -12,7 +12,7 @@ RSpec.describe ColorLS::Yaml do
let(:base_directory) { 'lib/yaml' }
FILENAMES.each do |filename, sort_type|
filenames.each do |filename, sort_type|
describe filename do
let(:checker) { YamlSortChecker.new("#{base_directory}/#{filename}.yaml") }