summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-12-11 23:36:21 +0000
committerSHIBATA Hiroshi <hsbt@ruby-lang.org>2017-12-12 11:43:40 +0900
commit8e852c8041f49f2663038464877c8879e4cf5f5b (patch)
treea1ddd2cd595f1ab6bc332e986bfbf78f265bb657
parentce967788bf62e030556825d160e7aa448c80b311 (diff)
downloadbundler-8e852c8041f49f2663038464877c8879e4cf5f5b.tar.gz
Auto merge of #6207 - bundler:colby/init-gemfile-path-child, r=segiddins
Let users generate gemfiles inside paths whos parent contains a Gemfile ### What was the end-user problem that led to this PR? Users are unable to generate a new Gemfile with `bundle init` if there is a Gemfile in any parent folder. Closes #6205 ### What is your fix for the problem, implemented in this PR? Don't use `SharedHelpers.default_gemfile` as that searches up the paths for a Gemfile. Instead only check the current directory.
-rw-r--r--lib/bundler/cli/init.rb6
-rw-r--r--spec/commands/init_spec.rb66
2 files changed, 40 insertions, 32 deletions
diff --git a/lib/bundler/cli/init.rb b/lib/bundler/cli/init.rb
index 50e01f54fb..fa53e7c74b 100644
--- a/lib/bundler/cli/init.rb
+++ b/lib/bundler/cli/init.rb
@@ -36,11 +36,7 @@ module Bundler
private
def gemfile
- @gemfile ||= begin
- Bundler.default_gemfile
- rescue GemfileNotFound
- Bundler.feature_flag.init_gems_rb? ? "gems.rb" : "Gemfile"
- end
+ @gemfile ||= Bundler.feature_flag.init_gems_rb? ? "gems.rb" : "Gemfile"
end
end
end
diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb
index 0441e62e13..c1cd7b90c8 100644
--- a/spec/commands/init_spec.rb
+++ b/spec/commands/init_spec.rb
@@ -13,9 +13,9 @@ RSpec.describe "bundle init" do
expect(bundled_app("gems.rb")).to be_file
end
- context "when a Gemfile already exists" do
+ context "when a Gemfile already exists", :bundler => "< 2" do
before do
- gemfile <<-G
+ create_file "Gemfile", <<-G
gem "rails"
G
end
@@ -30,14 +30,14 @@ RSpec.describe "bundle init" do
end
end
- context "when a gems.rb already exists" do
+ context "when gems.rb already exists", :bundler => ">= 2" do
before do
- create_file "gems.rb", <<-G
+ create_file("gems.rb", <<-G)
gem "rails"
G
end
- it "does not change existing gem.rb files" do
+ it "does not change existing Gemfiles" do
expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
end
@@ -47,6 +47,40 @@ RSpec.describe "bundle init" do
end
end
+ context "when a Gemfile exists in a parent directory", :bundler => "< 2" do
+ let(:subdir) { "child_dir" }
+
+ it "lets users generate a Gemfile in a child directory" do
+ bundle! :init
+
+ FileUtils.mkdir bundled_app(subdir)
+
+ Dir.chdir bundled_app(subdir) do
+ bundle! :init
+ end
+
+ expect(out).to include("Writing new Gemfile")
+ expect(bundled_app("#{subdir}/Gemfile")).to be_file
+ end
+ end
+
+ context "when a gems.rb file exists in a parent directory", :bundler => ">= 2" do
+ let(:subdir) { "child_dir" }
+
+ it "lets users generate a Gemfile in a child directory" do
+ bundle! :init
+
+ FileUtils.mkdir bundled_app(subdir)
+
+ Dir.chdir bundled_app(subdir) do
+ bundle! :init
+ end
+
+ expect(out).to include("Writing new gems.rb")
+ expect(bundled_app("#{subdir}/gems.rb")).to be_file
+ end
+ end
+
context "given --gemspec option", :bundler => "< 2" do
let(:spec_file) { tmp.join("test.gemspec") }
@@ -94,28 +128,6 @@ RSpec.describe "bundle init" do
context "when init_gems_rb setting is enabled" do
before { bundle "config init_gems_rb true" }
- it "generates a gems.rb file" do
- bundle :init
- expect(bundled_app("gems.rb")).to exist
- end
-
- context "when gems.rb already exists" do
- before do
- create_file("gems.rb", <<-G)
- gem "rails"
- G
- end
-
- it "does not change existing Gemfiles" do
- expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
- end
-
- it "notifies the user that an existing gems.rb already exists" do
- bundle :init
- expect(out).to include("gems.rb already exists")
- end
- end
-
context "given --gemspec option", :bundler => "< 2" do
let(:spec_file) { tmp.join("test.gemspec") }