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

Commit

Permalink
Let users generate gemfiles in paths whos parent path contains a Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Colby Swandale committed Dec 9, 2017
1 parent 953acf7 commit 2122a05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 1 addition & 5 deletions lib/bundler/cli/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ def run
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
23 changes: 20 additions & 3 deletions spec/commands/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,35 @@

context "when a Gemfile already exists" do
before do
gemfile <<-G
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("Gemfile")) }
expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
end

it "notifies the user that an existing Gemfile already exists" do
bundle :init
expect(out).to include("Gemfile already exists")
expect(out).to include("gems.rb already exists")
end
end

context "when a Gemfile exists in a parent directory" 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

Expand Down

0 comments on commit 2122a05

Please sign in to comment.