2017-10-07 21:32:18 -04:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
class TestGemBundlerVersionFinder < Gem::TestCase
|
|
|
|
def setup
|
2019-02-14 07:59:03 -05:00
|
|
|
super
|
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
@argv = ARGV.dup
|
|
|
|
@dollar_0 = $0
|
2021-05-28 06:47:49 -04:00
|
|
|
without_any_upwards_gemfiles
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
ARGV.replace @argv
|
|
|
|
$0 = @dollar_0
|
2019-02-14 07:59:03 -05:00
|
|
|
|
|
|
|
super
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bvf
|
|
|
|
Gem::BundlerVersionFinder
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bundler_version_defaults_to_nil
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bundler_version_with_env_var
|
|
|
|
ENV["BUNDLER_VERSION"] = "1.1.1.1"
|
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bundler_version_with_bundle_update_bundler
|
|
|
|
ARGV.replace %w[update --bundler]
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
$0 = "/foo/bar/bundle"
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
ARGV.replace %w[update --bundler=1.1.1.1 gem_name]
|
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
ARGV.replace %w[update --bundler 1.1.1.1 gem_name]
|
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
ARGV.replace %w[update --bundler\ 1.1.1.1 gem_name]
|
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
ARGV.replace %w[update --bundler\ 1.1.1.2 --bundler --bundler 1.1.1.1 gem_name]
|
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
$0 = "other"
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bundler_version_with_lockfile
|
2021-12-22 19:21:36 -05:00
|
|
|
bvf.stub(:lockfile_contents, "") do
|
2017-10-07 21:32:18 -04:00
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
end
|
2021-12-22 19:21:36 -05:00
|
|
|
bvf.stub(:lockfile_contents, "\n\nBUNDLED WITH\n 1.1.1.1\n") do
|
2017-10-07 21:32:18 -04:00
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
end
|
2021-12-22 19:21:36 -05:00
|
|
|
bvf.stub(:lockfile_contents, "\n\nBUNDLED WITH\n fjdkslfjdkslfjsldk\n") do
|
2017-10-07 21:32:18 -04:00
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-22 19:21:36 -05:00
|
|
|
def test_bundler_version
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
bvf.stub(:lockfile_contents, "\n\nBUNDLED WITH\n 1.1.1.1\n") do
|
|
|
|
assert_equal "1.1.1.1", bvf.bundler_version.to_s
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
$0 = "bundle"
|
|
|
|
ARGV.replace %w[update --bundler]
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
ARGV.replace %w[update --bundler=1.1.1.2]
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal "1.1.1.2", bvf.bundler_version.to_s
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
ENV["BUNDLER_VERSION"] = "1.1.1.3"
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal "1.1.1.3", bvf.bundler_version.to_s
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
def test_deleted_directory
|
2021-05-10 23:27:07 -04:00
|
|
|
pend "Cannot perform this test on windows" if win_platform?
|
|
|
|
pend "Cannot perform this test on Solaris" if /solaris/ =~ RUBY_PLATFORM
|
2020-03-24 02:39:24 -04:00
|
|
|
require "tmpdir"
|
|
|
|
|
|
|
|
orig_dir = Dir.pwd
|
|
|
|
|
|
|
|
begin
|
|
|
|
Dir.mktmpdir("some_dir") do |dir|
|
|
|
|
Dir.chdir(dir)
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
Dir.chdir(orig_dir)
|
|
|
|
end
|
|
|
|
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_nil bvf.bundler_version
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
|
2021-12-22 19:21:36 -05:00
|
|
|
def test_prioritize
|
2018-12-12 00:07:50 -05:00
|
|
|
versions = %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1]
|
2020-06-10 13:46:05 -04:00
|
|
|
specs = versions.map {|v| util_spec("bundler", v) }
|
2017-10-07 21:32:18 -04:00
|
|
|
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1], util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
bvf.stub(:bundler_version, v("2.1.1.1")) do
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1], util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("1.1.1.1")) do
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1], util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("1")) do
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1], util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("2.a")) do
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal %w[2.a 1 1.0 1.0.1.1 2 2.0 2.1.1 3 3.a 3.0 3.1.1], util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("3")) do
|
2021-12-22 19:21:36 -05:00
|
|
|
assert_equal %w[3 1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3.a 3.0 3.1.1], util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-22 19:21:36 -05:00
|
|
|
def util_prioritize_specs(specs)
|
2017-10-07 21:32:18 -04:00
|
|
|
specs = specs.dup
|
2021-12-22 19:21:36 -05:00
|
|
|
bvf.prioritize!(specs)
|
|
|
|
specs.map(&:version).map(&:to_s)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
2017-10-07 21:32:22 -04:00
|
|
|
end
|