diff options
Diffstat (limited to 'spec/bundler/commands/init_spec.rb')
-rw-r--r-- | spec/bundler/commands/init_spec.rb | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/spec/bundler/commands/init_spec.rb b/spec/bundler/commands/init_spec.rb index 8a8f0effa0..64849beeb9 100644 --- a/spec/bundler/commands/init_spec.rb +++ b/spec/bundler/commands/init_spec.rb @@ -1,19 +1,13 @@ # frozen_string_literal: true RSpec.describe "bundle init" do - it "generates a Gemfile", :bundler => "< 3" do + it "generates a Gemfile" do bundle! :init expect(out).to include("Writing new Gemfile") expect(bundled_app("Gemfile")).to be_file end - it "generates a gems.rb", :bundler => "3" do - bundle! :init - expect(out).to include("Writing new gems.rb") - expect(bundled_app("gems.rb")).to be_file - end - - context "when a Gemfile already exists", :bundler => "< 3" do + context "when a Gemfile already exists" do before do create_file "Gemfile", <<-G gem "rails" @@ -26,28 +20,11 @@ RSpec.describe "bundle init" do it "notifies the user that an existing Gemfile already exists" do bundle :init - expect(out).to include("Gemfile already exists") + expect(err).to include("Gemfile already exists") end end - context "when gems.rb already exists", :bundler => ">= 3" 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 "when a Gemfile exists in a parent directory", :bundler => "< 3" do + 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 @@ -77,29 +54,12 @@ RSpec.describe "bundle init" do bundle :init end - expect(out).to include("directory is not writable") + expect(err).to include("directory is not writable") expect(Dir[bundled_app("#{subdir}/*")]).to be_empty end end - context "when a gems.rb file exists in a parent directory", :bundler => ">= 3" 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 => "< 3" do + context "given --gemspec option" do let(:spec_file) { tmp.join("test.gemspec") } it "should generate from an existing gemspec" do @@ -115,11 +75,7 @@ RSpec.describe "bundle init" do bundle :init, :gemspec => spec_file - gemfile = if Bundler::VERSION[0, 2].to_i < 3 - bundled_app("Gemfile").read - else - bundled_app("gems.rb").read - end + gemfile = bundled_app("Gemfile").read expect(gemfile).to match(%r{source 'https://rubygems.org'}) expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) @@ -144,9 +100,49 @@ RSpec.describe "bundle init" do end context "when init_gems_rb setting is enabled" do - before { bundle "config init_gems_rb true" } + before { bundle "config set init_gems_rb true" } + + it "generates a gems.rb" do + bundle! :init + expect(out).to include("Writing new gems.rb") + expect(bundled_app("gems.rb")).to be_file + 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(err).to include("gems.rb already exists") + end + end + + context "when a gems.rb file 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 - context "given --gemspec option", :bundler => "< 3" do + context "given --gemspec option" do let(:spec_file) { tmp.join("test.gemspec") } before do |