summaryrefslogtreecommitdiff
path: root/spec/commands/init_spec.rb
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-12-11 22:26:31 +1100
committerColby Swandale <colby@taplaboratories.com>2017-12-11 23:00:44 +1100
commitcbf30a8a8fa00de33254f96bd290e67815f75998 (patch)
treeec21ee4c63e47b4b21b6faef371321fb52bf94ab /spec/commands/init_spec.rb
parent2122a050d285165e676a632e2c0152c2499a2524 (diff)
downloadbundler-cbf30a8a8fa00de33254f96bd290e67815f75998.tar.gz
scope specs to their bundler version and remove duplicate testcolby/init-gemfile-path-child
Diffstat (limited to 'spec/commands/init_spec.rb')
-rw-r--r--spec/commands/init_spec.rb75
1 files changed, 35 insertions, 40 deletions
diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb
index f4ff436179..c1cd7b90c8 100644
--- a/spec/commands/init_spec.rb
+++ b/spec/commands/init_spec.rb
@@ -13,24 +13,41 @@ 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
- create_file "gems.rb", <<-G
+ create_file "Gemfile", <<-G
gem "rails"
G
end
it "does not change existing Gemfiles" do
- expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
+ expect { bundle :init }.not_to change { File.read(bundled_app("Gemfile")) }
end
it "notifies the user that an existing Gemfile already exists" do
bundle :init
+ expect(out).to include("Gemfile already exists")
+ end
+ end
+
+ context "when gems.rb already exists", :bundler => ">= 2" 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" do
+ 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
@@ -42,25 +59,25 @@ RSpec.describe "bundle init" do
bundle! :init
end
- expect(out).to include("Writing new gems.rb")
- expect(bundled_app("#{subdir}/gems.rb")).to be_file
+ expect(out).to include("Writing new Gemfile")
+ expect(bundled_app("#{subdir}/Gemfile")).to be_file
end
end
- context "when a gems.rb already exists" do
- before do
- create_file "gems.rb", <<-G
- gem "rails"
- G
- end
+ context "when a gems.rb file exists in a parent directory", :bundler => ">= 2" do
+ let(:subdir) { "child_dir" }
- it "does not change existing gem.rb files" do
- expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
- end
+ it "lets users generate a Gemfile in a child directory" do
+ bundle! :init
- it "notifies the user that an existing gems.rb already exists" do
- bundle :init
- expect(out).to include("gems.rb already exists")
+ 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
@@ -111,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") }