Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
rubocop changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwann committed Nov 18, 2017
1 parent f608ae4 commit c7fea14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
25 changes: 15 additions & 10 deletions lib/bundler/cli/doctor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "rbconfig"
require 'find'
require "find"

module Bundler
class CLI::Doctor
Expand Down Expand Up @@ -93,18 +93,23 @@ def run
end
end

private
private

def check_home_permissions
if any_files_not_owned_by_current_user_but_still_rw?
Bundler.ui.warn 'Files exist in Bundler home that are owned by another ' \
'user, but are stil readable/writable'
end
check_for_files_not_owned_by_current_user_but_still_rw
check_for_files_not_readable_or_writable
end

if any_files_not_readable_or_writable?
raise ProductionError, 'Files exist in Bundler home that are not ' \
'readable/writable to the current user'
end
def check_for_files_not_owned_by_current_user_but_still_rw
return unless any_files_not_owned_by_current_user_but_still_rw?
Bundler.ui.warn "Files exist in Bundler home that are owned by another " \
"user, but are stil readable/writable"
end

def check_for_files_not_readable_or_writable
return unless any_files_not_readable_or_writable?
raise ProductionError, "Files exist in Bundler home that are not " \
"readable/writable to the current user"
end

def any_files_not_readable_or_writable?
Expand Down
18 changes: 9 additions & 9 deletions spec/commands/doctor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
gem "rack"
G

stat = double('stat')
unwritable_file = double('file')
stat = double("stat")
unwritable_file = double("file")
allow(Find).to receive(:find).with(Bundler.home.to_s) { [unwritable_file] }
allow(File).to receive(:stat).with(unwritable_file) { stat }
allow(stat).to receive(:uid) { Process.uid }
Expand Down Expand Up @@ -58,8 +58,8 @@
end

it "exits with an error if home contains files that are not read/write" do
stat = double('stat')
unwritable_file = double('file')
stat = double("stat")
unwritable_file = double("file")
doctor = Bundler::CLI::Doctor.new({})
allow(Find).to receive(:find).with(Bundler.home.to_s) { [unwritable_file] }
allow(File).to receive(:stat).with(unwritable_file) { stat }
Expand All @@ -68,19 +68,19 @@
allow(File).to receive(:readable?).with(unwritable_file) { false }
expect { doctor.run }.to raise_error(
Bundler::ProductionError,
'Files exist in Bundler home that are not readable/writable to the current user'
"Files exist in Bundler home that are not readable/writable to the current user"
)
end

it "exits with a warning if home contains files that are read/write but not owned by current user" do
stat = double('stat')
unwritable_file = double('file')
stat = double("stat")
unwritable_file = double("file")
allow(Find).to receive(:find).with(Bundler.home.to_s) { [unwritable_file] }
allow(File).to receive(:stat).with(unwritable_file) { stat }
allow(stat).to receive(:uid) { 00000 }
allow(stat).to receive(:uid) { 0o0000 }
allow(File).to receive(:writable?).with(unwritable_file) { true }
allow(File).to receive(:readable?).with(unwritable_file) { true }
expect { Bundler::CLI::Doctor.new({}).run }.not_to raise_error
expect(@stdout.string).to include('Files exist in Bundler home that are owned by another user, but are stil readable/writable')
expect(@stdout.string).to include("Files exist in Bundler home that are owned by another user, but are stil readable/writable")
end
end

0 comments on commit c7fea14

Please sign in to comment.