2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-04 08:10:58 -05:00
|
|
|
RSpec.describe "bundle inject", :bundler => "< 3" do
|
2018-11-02 19:07:56 -04:00
|
|
|
before :each do
|
|
|
|
gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack"
|
|
|
|
G
|
|
|
|
end
|
|
|
|
|
|
|
|
context "without a lockfile" do
|
|
|
|
it "locks with the injected gems" do
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock).not_to exist
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "inject 'rack-obama' '> 0'"
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock.read).to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a lockfile" do
|
|
|
|
before do
|
|
|
|
bundle "install"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "adds the injected gems to the Gemfile" do
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_gemfile.read).not_to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "inject 'rack-obama' '> 0'"
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_gemfile.read).to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "locks with the injected gems" do
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock.read).not_to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "inject 'rack-obama' '> 0'"
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock.read).to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with injected gems already in the Gemfile" do
|
|
|
|
it "doesn't add existing gems" do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "inject 'rack' '> 0'", :raise_on_error => false
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to match(/cannot specify the same gem twice/i)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "incorrect arguments" do
|
|
|
|
it "fails when more than 2 arguments are passed" do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "inject gem_name 1 v", :raise_on_error => false
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to eq(<<-E.strip)
|
2018-11-02 19:07:56 -04:00
|
|
|
ERROR: "bundle inject" was called with arguments ["gem_name", "1", "v"]
|
|
|
|
Usage: "bundle inject GEM VERSION"
|
|
|
|
E
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with source option" do
|
|
|
|
it "add gem with source option in gemfile" do
|
2019-05-06 12:06:21 -04:00
|
|
|
bundle "inject 'foo' '>0' --source #{file_uri_for(gem_repo1)}"
|
2020-05-08 01:19:04 -04:00
|
|
|
gemfile = bundled_app_gemfile.read
|
2019-05-06 12:06:21 -04:00
|
|
|
str = "gem \"foo\", \"> 0\", :source => \"#{file_uri_for(gem_repo1)}\""
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(gemfile).to include str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with group option" do
|
|
|
|
it "add gem with group option in gemfile" do
|
|
|
|
bundle "inject 'rack-obama' '>0' --group=development"
|
2020-05-08 01:19:04 -04:00
|
|
|
gemfile = bundled_app_gemfile.read
|
2018-11-02 19:07:56 -04:00
|
|
|
str = "gem \"rack-obama\", \"> 0\", :group => :development"
|
|
|
|
expect(gemfile).to include str
|
|
|
|
end
|
|
|
|
|
|
|
|
it "add gem with multiple groups in gemfile" do
|
|
|
|
bundle "inject 'rack-obama' '>0' --group=development,test"
|
2020-05-08 01:19:04 -04:00
|
|
|
gemfile = bundled_app_gemfile.read
|
2018-11-02 19:07:56 -04:00
|
|
|
str = "gem \"rack-obama\", \"> 0\", :groups => [:development, :test]"
|
|
|
|
expect(gemfile).to include str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when frozen" do
|
|
|
|
before do
|
|
|
|
bundle "install"
|
2019-01-04 08:10:58 -05:00
|
|
|
if Bundler.feature_flag.bundler_3_mode?
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set --local deployment true"
|
2018-11-02 19:07:56 -04:00
|
|
|
else
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "config set --local frozen true"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "injects anyway" do
|
|
|
|
bundle "inject 'rack-obama' '> 0'"
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_gemfile.read).to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "locks with the injected gems" do
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock.read).not_to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
bundle "inject 'rack-obama' '> 0'"
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock.read).to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "restores frozen afterwards" do
|
|
|
|
bundle "inject 'rack-obama' '> 0'"
|
2022-02-27 20:32:28 -05:00
|
|
|
config = Psych.load(bundled_app(".bundle/config").read)
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(config["BUNDLE_DEPLOYMENT"] || config["BUNDLE_FROZEN"]).to eq("true")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't allow Gemfile changes" do
|
|
|
|
gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack-obama"
|
|
|
|
G
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "inject 'rack' '> 0'", :raise_on_error => false
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to match(/trying to install in deployment mode after changing/)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(bundled_app_lock.read).not_to match(/rack-obama/)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|