From db0ae8839da2ab54396d7cc531f2174a24bc3447 Mon Sep 17 00:00:00 2001 From: Michal Olah Date: Fri, 23 Sep 2016 15:24:02 +0200 Subject: [PATCH] fixing NoMethodError on settings When the Settings object is initialized with no root directory it cannot read the local_config. This used to not be a problem due to the fact that the `#load_config` method did not try to exit early. Since now it does it returns nil when the config is not present setting the @local_config instance variable to nil. The fix is to return an empty hash the same way the `#load_config` method would return if it encountered a problem later on. The attached test proves that there is a problem and the fix make the problem go away. --- lib/bundler/settings.rb | 2 +- spec/bundler/settings_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index bed875420ee..db6a4ab6adf 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -296,7 +296,7 @@ def local_config_file }xo def load_config(config_file) - return unless config_file + return {} unless config_file SharedHelpers.filesystem_access(config_file, :read) do |file| valid_file = file.exist? && !file.size.zero? return {} if ignore_config? || !valid_file diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index 31ca13903c1..323bea7f109 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -54,6 +54,16 @@ end describe "#[]" do + context "when the local config file is not found" do + subject(:settings) { described_class.new } + + it "does not raise" do + expect { + subject['foo'] + }.not_to raise_error + end + end + context "when not set" do context "when default value present" do it "retrieves value" do