From 5b472ccbe6479f08ce42a714936c772f2684c9a8 Mon Sep 17 00:00:00 2001 From: Gerard Caulfield Date: Fri, 1 Jul 2016 12:00:56 +1000 Subject: [PATCH] Allow non `.aprc` `File.readable?` calls `stub_dotfile!` was blocking all calls to `File.readable?` instead of just calls to load the `.aprc` file. This meant that trying to use other libraries, such as pry, which relied on `File.readable?` would fail in instances where `stub_dotfile!` had been called. This change fixes that, while keeping the original intended behaviour. --- lib/awesome_print/inspector.rb | 2 +- spec/spec_helper.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/awesome_print/inspector.rb b/lib/awesome_print/inspector.rb index 30a269f..b79bf2c 100644 --- a/lib/awesome_print/inspector.rb +++ b/lib/awesome_print/inspector.rb @@ -173,7 +173,7 @@ module AwesomePrint # Load ~/.aprc file with custom defaults that override default options. #------------------------------------------------------------------------------ def merge_custom_defaults! - dotfile = File.join(ENV["HOME"], ".aprc") + dotfile = File.join(ENV['HOME'], '.aprc') load dotfile if File.readable?(dotfile) merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash) rescue => e diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b564bd..b9d65c2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -71,7 +71,8 @@ def normalize_object_id_strings(str, options) end def stub_dotfile! - dotfile = File.join(ENV["HOME"], ".aprc") + dotfile = File.join(ENV['HOME'], '.aprc') + allow(File).to receive(:readable?).and_call_original expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false) end