diff --git a/lib/rubocop/file_finder.rb b/lib/rubocop/file_finder.rb index 05dbb3ccd0aa..b6724f791636 100644 --- a/lib/rubocop/file_finder.rb +++ b/lib/rubocop/file_finder.rb @@ -32,10 +32,10 @@ def find_last_file_upwards(filename, start_dir) def traverse_files_upwards(filename, start_dir) Pathname.new(start_dir).expand_path.ascend do |dir| - break if FileFinder.root_level?(dir) - file = dir + filename yield(file.to_s) if file.exist? + + break if FileFinder.root_level?(dir) end end end diff --git a/lib/rubocop/rspec/shared_contexts.rb b/lib/rubocop/rspec/shared_contexts.rb index d3fb2081d60e..7bc0b59349f0 100644 --- a/lib/rubocop/rspec/shared_contexts.rb +++ b/lib/rubocop/rspec/shared_contexts.rb @@ -12,16 +12,17 @@ # get mismatched pathnames when loading config files later on. tmpdir = File.realpath(tmpdir) + virtual_home = File.expand_path(File.join(tmpdir, 'home')) + Dir.mkdir(virtual_home) + ENV['HOME'] = virtual_home + ENV.delete('XDG_CONFIG_HOME') + + working_dir = File.join(tmpdir, 'work') + # Make upwards search for .rubocop.yml files stop at this directory. - RuboCop::FileFinder.root_level = tmpdir + RuboCop::FileFinder.root_level = working_dir begin - virtual_home = File.expand_path(File.join(tmpdir, 'home')) - Dir.mkdir(virtual_home) - ENV['HOME'] = virtual_home - ENV.delete('XDG_CONFIG_HOME') - - working_dir = File.join(tmpdir, 'work') Dir.mkdir(working_dir) Dir.chdir(working_dir) do