2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "bundler/vendored_fileutils"
|
|
|
|
|
2020-05-16 06:47:24 -04:00
|
|
|
RSpec.describe "bundle pristine", :ruby_repo do
|
2018-11-02 19:07:56 -04:00
|
|
|
before :each do
|
|
|
|
build_lib "baz", :path => bundled_app do |s|
|
|
|
|
s.version = "1.0.0"
|
|
|
|
s.add_development_dependency "baz-dev", "=1.0.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
build_repo2 do
|
|
|
|
build_gem "weakling"
|
|
|
|
build_gem "baz-dev", "1.0.0"
|
|
|
|
build_gem "very_simple_binary", &:add_c_extension
|
|
|
|
build_git "foo", :path => lib_path("foo")
|
|
|
|
build_git "git_with_ext", :path => lib_path("git_with_ext"), &:add_c_extension
|
|
|
|
build_lib "bar", :path => lib_path("bar")
|
|
|
|
end
|
|
|
|
|
2020-06-03 14:46:03 -04:00
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo2)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "weakling"
|
|
|
|
gem "very_simple_binary"
|
2020-05-08 01:19:04 -04:00
|
|
|
gem "foo", :git => "#{lib_path("foo")}", :branch => "master"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "git_with_ext", :git => "#{lib_path("git_with_ext")}"
|
|
|
|
gem "bar", :path => "#{lib_path("bar")}"
|
|
|
|
|
|
|
|
gemspec
|
|
|
|
G
|
2020-05-08 01:19:04 -04:00
|
|
|
|
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when sourced from RubyGems" do
|
|
|
|
it "reverts using cached .gem file" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("weakling")
|
2018-11-02 19:07:56 -04:00
|
|
|
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
|
|
|
|
|
|
|
|
FileUtils.touch(changes_txt)
|
|
|
|
expect(changes_txt).to be_file
|
|
|
|
|
|
|
|
bundle "pristine"
|
|
|
|
expect(changes_txt).to_not be_file
|
|
|
|
end
|
|
|
|
|
2019-07-23 12:44:21 -04:00
|
|
|
it "does not delete the bundler gem" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "install"
|
|
|
|
bundle "pristine"
|
|
|
|
bundle "-v"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-01-04 08:10:58 -05:00
|
|
|
expected = if Bundler::VERSION < "3.0"
|
2018-11-02 19:07:56 -04:00
|
|
|
"Bundler version"
|
|
|
|
else
|
|
|
|
Bundler::VERSION
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(out).to start_with(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when sourced from git repo" do
|
|
|
|
it "reverts by resetting to current revision`" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("foo")
|
2018-11-02 19:07:56 -04:00
|
|
|
changed_file = Pathname.new(spec.full_gem_path).join("lib/foo.rb")
|
|
|
|
diff = "#Pristine spec changes"
|
|
|
|
|
|
|
|
File.open(changed_file, "a") {|f| f.puts diff }
|
|
|
|
expect(File.read(changed_file)).to include(diff)
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "pristine"
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(File.read(changed_file)).to_not include(diff)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "removes added files" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("foo")
|
2018-11-02 19:07:56 -04:00
|
|
|
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
|
|
|
|
|
|
|
|
FileUtils.touch(changes_txt)
|
|
|
|
expect(changes_txt).to be_file
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "pristine"
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(changes_txt).not_to be_file
|
|
|
|
end
|
2020-05-08 01:19:04 -04:00
|
|
|
|
|
|
|
it "displays warning and ignores changes when a local config exists" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("foo")
|
2020-05-08 01:19:04 -04:00
|
|
|
bundle "config set local.#{spec.name} #{lib_path(spec.name)}"
|
|
|
|
|
|
|
|
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
|
|
|
|
FileUtils.touch(changes_txt)
|
|
|
|
expect(changes_txt).to be_file
|
|
|
|
|
|
|
|
bundle "pristine"
|
|
|
|
expect(changes_txt).to be_file
|
2020-09-17 07:34:59 -04:00
|
|
|
expect(err).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is locally overridden.")
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when sourced from gemspec" do
|
|
|
|
it "displays warning and ignores changes when sourced from gemspec" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("baz")
|
2018-11-02 19:07:56 -04:00
|
|
|
changed_file = Pathname.new(spec.full_gem_path).join("lib/baz.rb")
|
|
|
|
diff = "#Pristine spec changes"
|
|
|
|
|
|
|
|
File.open(changed_file, "a") {|f| f.puts diff }
|
|
|
|
expect(File.read(changed_file)).to include(diff)
|
|
|
|
|
|
|
|
bundle "pristine"
|
|
|
|
expect(File.read(changed_file)).to include(diff)
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is sourced from local path.")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reinstall gemspec dependency" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("baz-dev")
|
2020-01-08 02:11:52 -05:00
|
|
|
changed_file = Pathname.new(spec.full_gem_path).join("lib/baz/dev.rb")
|
2018-11-02 19:07:56 -04:00
|
|
|
diff = "#Pristine spec changes"
|
|
|
|
|
|
|
|
File.open(changed_file, "a") {|f| f.puts "#Pristine spec changes" }
|
|
|
|
expect(File.read(changed_file)).to include(diff)
|
|
|
|
|
|
|
|
bundle "pristine"
|
|
|
|
expect(File.read(changed_file)).to_not include(diff)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when sourced from path" do
|
|
|
|
it "displays warning and ignores changes when sourced from local path" do
|
2020-05-15 08:31:12 -04:00
|
|
|
spec = find_spec("bar")
|
2018-11-02 19:07:56 -04:00
|
|
|
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
|
|
|
|
FileUtils.touch(changes_txt)
|
|
|
|
expect(changes_txt).to be_file
|
|
|
|
bundle "pristine"
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is sourced from local path.")
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(changes_txt).to be_file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when passing a list of gems to pristine" do
|
|
|
|
it "resets them" do
|
2020-05-15 08:31:12 -04:00
|
|
|
foo = find_spec("foo")
|
2018-11-02 19:07:56 -04:00
|
|
|
foo_changes_txt = Pathname.new(foo.full_gem_path).join("lib/changes.txt")
|
|
|
|
FileUtils.touch(foo_changes_txt)
|
|
|
|
expect(foo_changes_txt).to be_file
|
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
bar = find_spec("bar")
|
2018-11-02 19:07:56 -04:00
|
|
|
bar_changes_txt = Pathname.new(bar.full_gem_path).join("lib/changes.txt")
|
|
|
|
FileUtils.touch(bar_changes_txt)
|
|
|
|
expect(bar_changes_txt).to be_file
|
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
weakling = find_spec("weakling")
|
2018-11-02 19:07:56 -04:00
|
|
|
weakling_changes_txt = Pathname.new(weakling.full_gem_path).join("lib/changes.txt")
|
|
|
|
FileUtils.touch(weakling_changes_txt)
|
|
|
|
expect(weakling_changes_txt).to be_file
|
|
|
|
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "pristine foo bar weakling"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include("Cannot pristine bar (1.0). Gem is sourced from local path.")
|
|
|
|
expect(out).to include("Installing weakling 1.0")
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(weakling_changes_txt).not_to be_file
|
|
|
|
expect(foo_changes_txt).not_to be_file
|
|
|
|
expect(bar_changes_txt).to be_file
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises when one of them is not in the lockfile" do
|
2020-06-03 12:43:17 -04:00
|
|
|
bundle "pristine abcabcabc", :raise_on_error => false
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include("Could not find gem 'abcabcabc'.")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when a build config exists for one of the gems" do
|
2020-05-15 08:31:12 -04:00
|
|
|
let(:very_simple_binary) { find_spec("very_simple_binary") }
|
2018-11-02 19:07:56 -04:00
|
|
|
let(:c_ext_dir) { Pathname.new(very_simple_binary.full_gem_path).join("ext") }
|
|
|
|
let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" }
|
2019-04-14 02:01:35 -04:00
|
|
|
before { bundle "config set build.very_simple_binary -- #{build_opt}" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
# This just verifies that the generated Makefile from the c_ext gem makes
|
|
|
|
# use of the build_args from the bundle config
|
|
|
|
it "applies the config when installing the gem" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "pristine"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
makefile_contents = File.read(c_ext_dir.join("Makefile").to_s)
|
|
|
|
expect(makefile_contents).to match(/libpath =.*#{c_ext_dir}/)
|
|
|
|
expect(makefile_contents).to match(/LIBPATH =.*-L#{c_ext_dir}/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when a build config exists for a git sourced gem" do
|
2020-05-15 08:31:12 -04:00
|
|
|
let(:git_with_ext) { find_spec("git_with_ext") }
|
2018-11-02 19:07:56 -04:00
|
|
|
let(:c_ext_dir) { Pathname.new(git_with_ext.full_gem_path).join("ext") }
|
|
|
|
let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" }
|
2019-04-14 02:01:35 -04:00
|
|
|
before { bundle "config set build.git_with_ext -- #{build_opt}" }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
# This just verifies that the generated Makefile from the c_ext gem makes
|
|
|
|
# use of the build_args from the bundle config
|
|
|
|
it "applies the config when installing the gem" do
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "pristine"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
makefile_contents = File.read(c_ext_dir.join("Makefile").to_s)
|
|
|
|
expect(makefile_contents).to match(/libpath =.*#{c_ext_dir}/)
|
|
|
|
expect(makefile_contents).to match(/LIBPATH =.*-L#{c_ext_dir}/)
|
|
|
|
end
|
|
|
|
end
|
2020-05-15 08:31:12 -04:00
|
|
|
|
2021-04-21 07:54:29 -04:00
|
|
|
context "when BUNDLE_GEMFILE doesn't exist" do
|
|
|
|
before do
|
|
|
|
bundle "pristine", :env => { "BUNDLE_GEMFILE" => "does/not/exist" }, :raise_on_error => false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows a meaningful error" do
|
|
|
|
expect(err).to eq("#{bundled_app("does/not/exist")} not found")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
def find_spec(name)
|
|
|
|
without_env_side_effects do
|
|
|
|
Bundler.definition.specs[name].first
|
|
|
|
end
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|