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

Commit

Permalink
fixing NoMethodError on settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m1k3 committed Sep 23, 2016
1 parent 03633e1 commit db0ae88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/bundler/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db0ae88

Please sign in to comment.