2017-10-07 21:32:18 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'rubygems/test_case'
|
|
|
|
|
|
|
|
class TestGemBundlerVersionFinder < Gem::TestCase
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
def setup
|
2019-02-14 07:59:03 -05:00
|
|
|
super
|
|
|
|
|
2017-10-07 21:32:18 -04:00
|
|
|
@argv = ARGV.dup
|
|
|
|
@env = ENV.to_hash.clone
|
|
|
|
ENV.delete("BUNDLER_VERSION")
|
|
|
|
@dollar_0 = $0
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
ARGV.replace @argv
|
|
|
|
ENV.replace @env
|
|
|
|
$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
|
|
|
|
bvf.stub(:lockfile_contents, [nil, ""]) do
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
end
|
|
|
|
bvf.stub(:lockfile_contents, [nil, "\n\nBUNDLED WITH\n 1.1.1.1\n"]) do
|
|
|
|
assert_equal v("1.1.1.1"), bvf.bundler_version
|
|
|
|
end
|
|
|
|
bvf.stub(:lockfile_contents, [nil, "\n\nBUNDLED WITH\n fjdkslfjdkslfjsldk\n"]) do
|
|
|
|
assert_nil bvf.bundler_version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bundler_version_with_reason
|
|
|
|
assert_nil bvf.bundler_version_with_reason
|
|
|
|
bvf.stub(:lockfile_contents, [nil, "\n\nBUNDLED WITH\n 1.1.1.1\n"]) do
|
|
|
|
assert_equal ["1.1.1.1", "your lockfile"], bvf.bundler_version_with_reason
|
|
|
|
|
|
|
|
$0 = "bundle"
|
|
|
|
ARGV.replace %w[update --bundler]
|
|
|
|
assert_nil bvf.bundler_version_with_reason
|
|
|
|
ARGV.replace %w[update --bundler=1.1.1.2]
|
|
|
|
assert_equal ["1.1.1.2", "`bundle update --bundler`"], bvf.bundler_version_with_reason
|
|
|
|
|
|
|
|
ENV["BUNDLER_VERSION"] = "1.1.1.3"
|
|
|
|
assert_equal ["1.1.1.3", "`$BUNDLER_VERSION`"], bvf.bundler_version_with_reason
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_compatible
|
|
|
|
assert bvf.compatible?(util_spec("foo"))
|
|
|
|
assert bvf.compatible?(util_spec("bundler", 1.1))
|
|
|
|
|
|
|
|
bvf.stub(:bundler_version, v("1.1.1.1")) do
|
|
|
|
assert bvf.compatible?(util_spec("foo"))
|
|
|
|
assert bvf.compatible?(util_spec("bundler", "1.1.1.1"))
|
|
|
|
assert bvf.compatible?(util_spec("bundler", "1.1.1.a"))
|
|
|
|
assert bvf.compatible?(util_spec("bundler", "1.999"))
|
|
|
|
refute bvf.compatible?(util_spec("bundler", "2.999"))
|
|
|
|
end
|
|
|
|
|
|
|
|
bvf.stub(:bundler_version, v("2.1.1.1")) do
|
|
|
|
assert bvf.compatible?(util_spec("foo"))
|
|
|
|
assert bvf.compatible?(util_spec("bundler", "2.1.1.1"))
|
2018-12-12 00:07:50 -05:00
|
|
|
assert bvf.compatible?(util_spec("bundler", "2.1.1.a"))
|
|
|
|
assert bvf.compatible?(util_spec("bundler", "2.999"))
|
2017-10-07 21:32:18 -04:00
|
|
|
refute bvf.compatible?(util_spec("bundler", "1.999"))
|
2018-12-12 00:07:50 -05:00
|
|
|
refute bvf.compatible?(util_spec("bundler", "3.0.0"))
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_filter
|
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]
|
2017-10-07 21:32:18 -04:00
|
|
|
specs = versions.map { |v| util_spec("bundler", v) }
|
|
|
|
|
2018-12-12 00:07:50 -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_filter_specs(specs).map(&:version).map(&:to_s)
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
bvf.stub(:bundler_version, v("2.1.1.1")) do
|
2018-12-12 00:07:50 -05:00
|
|
|
assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("1.1.1.1")) do
|
|
|
|
assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
|
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("1")) do
|
|
|
|
assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
|
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("2.a")) do
|
2018-12-12 00:07:50 -05:00
|
|
|
assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
bvf.stub(:bundler_version, v("3")) do
|
2018-12-12 00:07:50 -05:00
|
|
|
assert_equal %w[3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
|
2017-10-07 21:32:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def util_filter_specs(specs)
|
|
|
|
specs = specs.dup
|
|
|
|
bvf.filter!(specs)
|
|
|
|
specs
|
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2017-10-07 21:32:22 -04:00
|
|
|
end
|