Skip to content

Commit

Permalink
Apply rubocop suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berger committed Mar 29, 2023
1 parent c309f7f commit 2a93903
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/ptools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self.binary?(file)
# File.which('ruby') # => '/usr/local/bin/ruby'
# File.which('foo') # => nil
#
def self.which(program, path = ENV['PATH'])
def self.which(program, path = ENV.fetch('PATH', nil))
raise ArgumentError, 'path cannot be empty' if path.nil? || path.empty?

# Bail out early if an absolute path is provided.
Expand Down Expand Up @@ -143,7 +143,7 @@ def self.which(program, path = ENV['PATH'])
# File.whereis('ruby') # => ['/usr/bin/ruby', '/usr/local/bin/ruby']
# File.whereis('foo') # => nil
#
def self.whereis(program, path = ENV['PATH'])
def self.whereis(program, path = ENV.fetch('PATH', nil))
raise ArgumentError, 'path cannot be empty' if path.nil? || path.empty?

paths = []
Expand Down Expand Up @@ -423,7 +423,7 @@ def self.nl_for_platform(platform)
#
def self.bmp?(file)
data = File.read(file, 6, nil, :encoding => 'binary')
data[0,2] == 'BM' && File.size(file) == data[2,4].unpack('i').first
data[0, 2] == 'BM' && File.size(file) == data[2, 4].unpack1('i')
end

# Is the file a jpeg file?
Expand Down
2 changes: 1 addition & 1 deletion spec/binary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

RSpec.describe File, :binary do
let(:dirname) { described_class.dirname(__FILE__) }
let(:bin_file) { File::ALT_SEPARATOR ? described_class.join(ENV['windir'], 'notepad.exe') : '/bin/ls' }
let(:bin_file) { File::ALT_SEPARATOR ? described_class.join(ENV.fetch('windir', nil), 'notepad.exe') : '/bin/ls' }

before do
@txt_file = described_class.join(dirname, 'txt', 'english.txt')
Expand Down
2 changes: 1 addition & 1 deletion spec/head_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end

example 'head method returns the expected results' do
expect(described_class.head(test_file)).to be_kind_of(Array)
expect(described_class.head(test_file)).to be_a(Array)
expect(described_class.head(test_file)).to eq(@expected_head1)
expect(described_class.head(test_file, 5)).to eq(@expected_head2)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/tail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
end

example 'tail returns the expected values' do
expect(described_class.tail(test_file1)).to be_kind_of(Array)
expect(described_class.tail(test_file1)).to be_a(Array)
expect(described_class.tail(test_file1)).to eq(@expected_tail1)
expect(described_class.tail(test_file1, 5)).to eq(@expected_tail2)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/wc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

example 'wc with no option returns expected results' do
expect(described_class.wc(test_file)).to be_kind_of(Array)
expect(described_class.wc(test_file)).to be_a(Array)
expect(described_class.wc(test_file)).to eq([166, 166, 25, 25])
end

Expand Down
4 changes: 2 additions & 2 deletions spec/whereis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
example 'whereis basic functionality' do
expect(described_class).to respond_to(:whereis)
expect{ described_class.whereis('ruby') }.not_to raise_error
expect(described_class.whereis('ruby')).to be_kind_of(Array).or be_nil
expect(described_class.whereis('ruby')).to be_a(Array).or be_nil
end

example 'whereis accepts an optional second argument' do
Expand All @@ -43,7 +43,7 @@

example 'whereis returns expected values' do
expect{ @actual_locs = described_class.whereis(ruby) }.not_to raise_error
expect(@actual_locs).to be_kind_of(Array)
expect(@actual_locs).to be_a(Array)
expect((@expected_locs & @actual_locs).size > 0).to be true
end

Expand Down
4 changes: 2 additions & 2 deletions spec/which_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
example 'which method basic functionality' do
expect(described_class).to respond_to(:which)
expect{ described_class.which(@ruby) }.not_to raise_error
expect(described_class.which(@ruby)).to be_kind_of(String)
expect(described_class.which(@ruby)).to be_a(String)
end

example 'which accepts an optional path to search' do
Expand Down Expand Up @@ -92,7 +92,7 @@
end

example 'resolves with with ~', :unix_only => true do
old_home = ENV['HOME']
old_home = Dir.home
ENV['HOME'] = Dir::Tmpname.tmpdir
program = Tempfile.new(['program', '.sh'])
described_class.chmod(755, program.path)
Expand Down

0 comments on commit 2a93903

Please sign in to comment.