diff options
author | Hiroshi SHIBATA <[email protected]> | 2024-07-31 00:05:54 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-07-30 09:05:54 -0700 |
commit | f85c7deacc25738bd83ba182370c283ba82b61d4 (patch) | |
tree | f5c83336547b71212f431eac4d44a8e18f330e7f | |
parent | 0922afa95b3e390876cbea7f78d3d93d979f27d4 (diff) |
Update RubyGems 3.5.16 and Bundler 2.5.16 for Ruby 3.3 (#11252)
* Merge RubyGems-3.5.12 and Bundler-2.5.12
* Merge RubyGems-3.5.13 and Bundler-2.5.13
* Merge RubyGems-3.5.14 and Bundler-2.5.14
* Merge RubyGems-3.5.15 and Bundler-2.5.15
* Merge RubyGems-3.5.16 and Bundler-2.5.16
245 files changed, 7592 insertions, 5857 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index cf6ae2994d..3a15aa2e6f 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -42,6 +42,7 @@ module Bundler autoload :Checksum, File.expand_path("bundler/checksum", __dir__) autoload :CLI, File.expand_path("bundler/cli", __dir__) autoload :CIDetector, File.expand_path("bundler/ci_detector", __dir__) + autoload :CompactIndexClient, File.expand_path("bundler/compact_index_client", __dir__) autoload :Definition, File.expand_path("bundler/definition", __dir__) autoload :Dependency, File.expand_path("bundler/dependency", __dir__) autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__) @@ -166,6 +167,10 @@ module Bundler end end + def auto_switch + self_manager.restart_with_locked_bundler_if_needed + end + # Automatically install dependencies if Bundler.settings[:auto_install] exists. # This is set through config cmd `bundle config set --global auto_install 1`. # @@ -356,7 +361,7 @@ module Bundler def settings @settings ||= Settings.new(app_config_path) rescue GemfileNotFound - @settings = Settings.new(Pathname.new(".bundle").expand_path) + @settings = Settings.new end # @return [Hash] Environment present before Bundler was activated diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 40f19c7fed..b4aa36f246 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -65,7 +65,7 @@ module Bundler Bundler.reset_settings_and_root! end - Bundler.self_manager.restart_with_locked_bundler_if_needed + Bundler.auto_switch Bundler.settings.set_command_option_if_given :retry, options[:retry] @@ -550,10 +550,13 @@ module Bundler method_option :rubocop, type: :boolean, desc: "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set --global gem.rubocop true`." method_option :changelog, type: :boolean, desc: "Generate changelog file. Set a default with `bundle config set --global gem.changelog true`." method_option :test, type: :string, lazy_default: Bundler.settings["gem.test"] || "", aliases: "-t", banner: "Use the specified test framework for your library", + enum: %w[rspec minitest test-unit], desc: "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set --global gem.test (rspec|minitest|test-unit)`." method_option :ci, type: :string, lazy_default: Bundler.settings["gem.ci"] || "", + enum: %w[github gitlab circle], desc: "Generate CI configuration, either GitHub Actions, GitLab CI or CircleCI. Set a default with `bundle config set --global gem.ci (github|gitlab|circle)`" method_option :linter, type: :string, lazy_default: Bundler.settings["gem.linter"] || "", + enum: %w[rubocop standard], desc: "Add a linter and code formatter, either RuboCop or Standard. Set a default with `bundle config set --global gem.linter (rubocop|standard)`" method_option :github_username, type: :string, default: Bundler.settings["gem.github_username"], banner: "Set your username on GitHub", desc: "Fill in GitHub username on README so that you don't have to do it manually. Set a default with `bundle config set --global gem.github_username <your_username>`." @@ -767,13 +770,10 @@ module Bundler return unless SharedHelpers.md5_available? - latest = Fetcher::CompactIndex. - new(nil, Source::Rubygems::Remote.new(Gem::URI("https://rubygems.org")), nil, nil). - send(:compact_index_client). - instance_variable_get(:@cache). - dependencies("bundler"). - map {|d| Gem::Version.new(d.first) }. - max + require_relative "vendored_uri" + remote = Source::Rubygems::Remote.new(Gem::URI("https://rubygems.org")) + cache_path = Bundler.user_cache.join("compact_index", remote.cache_slug) + latest = Bundler::CompactIndexClient.new(cache_path).latest_version("bundler") return unless latest current = Gem::Version.new(VERSION) diff --git a/lib/bundler/cli/fund.rb b/lib/bundler/cli/fund.rb index 52db5aef68..ad7f31f3d6 100644 --- a/lib/bundler/cli/fund.rb +++ b/lib/bundler/cli/fund.rb @@ -16,7 +16,7 @@ module Bundler deps = if groups.any? Bundler.definition.dependencies_for(groups) else - Bundler.definition.current_dependencies + Bundler.definition.requested_dependencies end fund_info = deps.each_with_object([]) do |dep, arr| diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index f0bb3aab18..50288a02e7 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -32,7 +32,6 @@ module Bundler validate_ext_name if @extension validate_rust_builder_rubygems_version if @extension == "rust" - travis_removal_info end def run @@ -276,6 +275,7 @@ module Bundler end def ask_and_set_test_framework + return if skip?(:test) test_framework = options[:test] || Bundler.settings["gem.test"] if test_framework.to_s.empty? @@ -301,6 +301,10 @@ module Bundler test_framework end + def skip?(option) + options.key?(option) && options[option].nil? + end + def hint_text(setting) if Bundler.settings["gem.#{setting}"] == false "Your choice will only be applied to this gem." @@ -311,6 +315,7 @@ module Bundler end def ask_and_set_ci + return if skip?(:ci) ci_template = options[:ci] || Bundler.settings["gem.ci"] if ci_template.to_s.empty? @@ -342,6 +347,7 @@ module Bundler end def ask_and_set_linter + return if skip?(:linter) linter_template = options[:linter] || Bundler.settings["gem.linter"] linter_template = deprecated_rubocop_option if linter_template.nil? @@ -448,19 +454,6 @@ module Bundler "1.3" end - # TODO: remove at next minor release - def travis_removal_info - if options[:ci] == "travis" - Bundler.ui.error "Support for Travis CI was removed from gem skeleton generator." - exit 1 - end - - if Bundler.settings["gem.ci"] == "travis" - Bundler.ui.error "Support for Travis CI was removed from gem skeleton generator, but it is present in bundle config. Please configure another provider using `bundle config set gem.ci SERVICE` (where SERVICE is one of github/gitlab/circle) or unset configuration using `bundle config unset gem.ci`." - exit 1 - end - end - def validate_rust_builder_rubygems_version if Gem::Version.new(rust_builder_required_rubygems_version) > Gem.rubygems_version Bundler.ui.error "Your RubyGems version (#{Gem.rubygems_version}) is too old to build Rust extension. Please update your RubyGems using `gem update --system` or any other way and try again." diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb index 68e0d7e0d5..a4f5bb1638 100644 --- a/lib/bundler/compact_index_client.rb +++ b/lib/bundler/compact_index_client.rb @@ -4,6 +4,29 @@ require "pathname" require "set" module Bundler + # The CompactIndexClient is responsible for fetching and parsing the compact index. + # + # The compact index is a set of caching optimized files that are used to fetch gem information. + # The files are: + # - names: a list of all gem names + # - versions: a list of all gem versions + # - info/[gem]: a list of all versions of a gem + # + # The client is instantiated with: + # - `directory`: the root directory where the cache files are stored. + # - `fetcher`: (optional) an object that responds to #call(uri_path, headers) and returns an http response. + # If the `fetcher` is not provided, the client will only read cached files from disk. + # + # The client is organized into: + # - `Updater`: updates the cached files on disk using the fetcher. + # - `Cache`: calls the updater, caches files, read and return them from disk + # - `Parser`: parses the compact index file data + # - `CacheFile`: a concurrency safe file reader/writer that verifies checksums + # + # The client is intended to optimize memory usage and performance. + # It is called 100s or 1000s of times, parsing files with hundreds of thousands of lines. + # It may be called concurrently without global interpreter lock in some Rubies. + # As a result, some methods may look more complex than necessary to save memory or time. class CompactIndexClient # NOTE: MD5 is here not because we expect a server to respond with it, but # because we use it to generate the etag on first request during the upgrade @@ -12,6 +35,13 @@ module Bundler SUPPORTED_DIGESTS = { "sha-256" => :SHA256, "md5" => :MD5 }.freeze DEBUG_MUTEX = Thread::Mutex.new + # info returns an Array of INFO Arrays. Each INFO Array has the following indices: + INFO_NAME = 0 + INFO_VERSION = 1 + INFO_PLATFORM = 2 + INFO_DEPS = 3 + INFO_REQS = 4 + def self.debug return unless ENV["DEBUG_COMPACT_INDEX"] DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") } @@ -21,106 +51,47 @@ module Bundler require_relative "compact_index_client/cache" require_relative "compact_index_client/cache_file" + require_relative "compact_index_client/parser" require_relative "compact_index_client/updater" - attr_reader :directory - - def initialize(directory, fetcher) - @directory = Pathname.new(directory) - @updater = Updater.new(fetcher) - @cache = Cache.new(@directory) - @endpoints = Set.new - @info_checksums_by_name = {} - @parsed_checksums = false - @mutex = Thread::Mutex.new - end - - def execution_mode=(block) - Bundler::CompactIndexClient.debug { "execution_mode=" } - @endpoints = Set.new - - @execution_mode = block - end - - # @return [Lambda] A lambda that takes an array of inputs and a block, and - # maps the inputs with the block in parallel. - # - def execution_mode - @execution_mode || sequentially - end - - def sequential_execution_mode! - self.execution_mode = sequentially - end - - def sequentially - @sequentially ||= lambda do |inputs, &blk| - inputs.map(&blk) - end + def initialize(directory, fetcher = nil) + @cache = Cache.new(directory, fetcher) + @parser = Parser.new(@cache) end def names - Bundler::CompactIndexClient.debug { "/names" } - update("names", @cache.names_path, @cache.names_etag_path) - @cache.names + Bundler::CompactIndexClient.debug { "names" } + @parser.names end def versions - Bundler::CompactIndexClient.debug { "/versions" } - update("versions", @cache.versions_path, @cache.versions_etag_path) - versions, @info_checksums_by_name = @cache.versions - versions + Bundler::CompactIndexClient.debug { "versions" } + @parser.versions end def dependencies(names) Bundler::CompactIndexClient.debug { "dependencies(#{names})" } - execution_mode.call(names) do |name| - update_info(name) - @cache.dependencies(name).map {|d| d.unshift(name) } - end.flatten(1) + names.map {|name| info(name) } end - def update_and_parse_checksums! - Bundler::CompactIndexClient.debug { "update_and_parse_checksums!" } - return @info_checksums_by_name if @parsed_checksums - update("versions", @cache.versions_path, @cache.versions_etag_path) - @info_checksums_by_name = @cache.checksums - @parsed_checksums = true - end - - private - - def update(remote_path, local_path, local_etag_path) - Bundler::CompactIndexClient.debug { "update(#{local_path}, #{remote_path})" } - unless synchronize { @endpoints.add?(remote_path) } - Bundler::CompactIndexClient.debug { "already fetched #{remote_path}" } - return - end - @updater.update(url(remote_path), local_path, local_etag_path) + def info(name) + Bundler::CompactIndexClient.debug { "info(#{name})" } + @parser.info(name) end - def update_info(name) - Bundler::CompactIndexClient.debug { "update_info(#{name})" } - path = @cache.info_path(name) - unless existing = @info_checksums_by_name[name] - Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since it is missing from versions" } - return - end - checksum = SharedHelpers.checksum_for_file(path, :MD5) - if checksum == existing - Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since the versions checksum matches the local checksum" } - return - end - Bundler::CompactIndexClient.debug { "updating info for #{name} since the versions checksum #{existing} != the local checksum #{checksum}" } - update("info/#{name}", path, @cache.info_etag_path(name)) + def latest_version(name) + Bundler::CompactIndexClient.debug { "latest_version(#{name})" } + @parser.info(name).map {|d| Gem::Version.new(d[INFO_VERSION]) }.max end - def url(path) - path + def available? + Bundler::CompactIndexClient.debug { "available?" } + @parser.available? end - def synchronize - @mutex.synchronize { yield } + def reset! + Bundler::CompactIndexClient.debug { "reset!" } + @cache.reset! end end end diff --git a/lib/bundler/compact_index_client/cache.rb b/lib/bundler/compact_index_client/cache.rb index bc6abaebc7..bedd7f8028 100644 --- a/lib/bundler/compact_index_client/cache.rb +++ b/lib/bundler/compact_index_client/cache.rb @@ -7,123 +7,89 @@ module Bundler class Cache attr_reader :directory - def initialize(directory) + def initialize(directory, fetcher = nil) @directory = Pathname.new(directory).expand_path - info_roots.each {|dir| mkdir(dir) } - mkdir(info_etag_root) + @updater = Updater.new(fetcher) if fetcher + @mutex = Thread::Mutex.new + @endpoints = Set.new + + @info_root = mkdir("info") + @special_characters_info_root = mkdir("info-special-characters") + @info_etag_root = mkdir("info-etags") end def names - lines(names_path) + fetch("names", names_path, names_etag_path) end - def names_path - directory.join("names") + def versions + fetch("versions", versions_path, versions_etag_path) end - def names_etag_path - directory.join("names.etag") - end + def info(name, remote_checksum = nil) + path = info_path(name) - def versions - versions_by_name = Hash.new {|hash, key| hash[key] = [] } - info_checksums_by_name = {} - - lines(versions_path).each do |line| - name, versions_string, info_checksum = line.split(" ", 3) - info_checksums_by_name[name] = info_checksum || "" - versions_string.split(",") do |version| - delete = version.delete_prefix!("-") - version = version.split("-", 2).unshift(name) - if delete - versions_by_name[name].delete(version) - else - versions_by_name[name] << version - end - end + if remote_checksum && remote_checksum != SharedHelpers.checksum_for_file(path, :MD5) + fetch("info/#{name}", path, info_etag_path(name)) + else + Bundler::CompactIndexClient.debug { "update skipped info/#{name} (#{remote_checksum ? "versions index checksum is nil" : "versions index checksum matches local"})" } + read(path) end - - [versions_by_name, info_checksums_by_name] - end - - def versions_path - directory.join("versions") end - def versions_etag_path - directory.join("versions.etag") + def reset! + @mutex.synchronize { @endpoints.clear } end - def checksums - lines(versions_path).each_with_object({}) do |line, checksums| - parse_version_checksum(line, checksums) - end - end + private - def dependencies(name) - lines(info_path(name)).map do |line| - parse_gem(line) - end - end + def names_path = directory.join("names") + def names_etag_path = directory.join("names.etag") + def versions_path = directory.join("versions") + def versions_etag_path = directory.join("versions.etag") def info_path(name) name = name.to_s + # TODO: converge this into the info_root by hashing all filenames like info_etag_path if /[^a-z0-9_-]/.match?(name) name += "-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}" - info_roots.last.join(name) + @special_characters_info_root.join(name) else - info_roots.first.join(name) + @info_root.join(name) end end def info_etag_path(name) name = name.to_s - info_etag_root.join("#{name}-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}") + @info_etag_root.join("#{name}-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}") end - private - - def mkdir(dir) - SharedHelpers.filesystem_access(dir) do - FileUtils.mkdir_p(dir) + def mkdir(name) + directory.join(name).tap do |dir| + SharedHelpers.filesystem_access(dir) do + FileUtils.mkdir_p(dir) + end end end - def lines(path) - return [] unless path.file? - lines = SharedHelpers.filesystem_access(path, :read, &:read).split("\n") - header = lines.index("---") - header ? lines[header + 1..-1] : lines - end - - def parse_gem(line) - @dependency_parser ||= GemParser.new - @dependency_parser.parse(line) - end + def fetch(remote_path, path, etag_path) + if already_fetched?(remote_path) + Bundler::CompactIndexClient.debug { "already fetched #{remote_path}" } + else + Bundler::CompactIndexClient.debug { "fetching #{remote_path}" } + @updater&.update(remote_path, path, etag_path) + end - # This is mostly the same as `split(" ", 3)` but it avoids allocating extra objects. - # This method gets called at least once for every gem when parsing versions. - def parse_version_checksum(line, checksums) - line.freeze # allows slicing into the string to not allocate a copy of the line - name_end = line.index(" ") - checksum_start = line.index(" ", name_end + 1) + 1 - checksum_end = line.size - checksum_start - # freeze name since it is used as a hash key - # pre-freezing means a frozen copy isn't created - name = line[0, name_end].freeze - checksum = line[checksum_start, checksum_end] - checksums[name] = checksum + read(path) end - def info_roots - [ - directory.join("info"), - directory.join("info-special-characters"), - ] + def already_fetched?(remote_path) + @mutex.synchronize { [email protected]?(remote_path) } end - def info_etag_root - directory.join("info-etags") + def read(path) + return unless path.file? + SharedHelpers.filesystem_access(path, :read, &:read) end end end diff --git a/lib/bundler/compact_index_client/parser.rb b/lib/bundler/compact_index_client/parser.rb new file mode 100644 index 0000000000..3276abdd68 --- /dev/null +++ b/lib/bundler/compact_index_client/parser.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +module Bundler + class CompactIndexClient + class Parser + # `compact_index` - an object responding to #names, #versions, #info(name, checksum), + # returning the file contents as a string + def initialize(compact_index) + @compact_index = compact_index + @info_checksums = nil + @versions_by_name = nil + @available = nil + @gem_parser = nil + end + + def names + lines(@compact_index.names) + end + + def versions + @versions_by_name ||= Hash.new {|hash, key| hash[key] = [] } + @info_checksums = {} + + lines(@compact_index.versions).each do |line| + name, versions_string, checksum = line.split(" ", 3) + @info_checksums[name] = checksum || "" + versions_string.split(",") do |version| + delete = version.delete_prefix!("-") + version = version.split("-", 2).unshift(name) + if delete + @versions_by_name[name].delete(version) + else + @versions_by_name[name] << version + end + end + end + + @versions_by_name + end + + def info(name) + data = @compact_index.info(name, info_checksums[name]) + lines(data).map {|line| gem_parser.parse(line).unshift(name) } + end + + def available? + return @available unless @available.nil? + @available = !info_checksums.empty? + end + + private + + def info_checksums + @info_checksums ||= lines(@compact_index.versions).each_with_object({}) do |line, checksums| + parse_version_checksum(line, checksums) + end + end + + def lines(data) + return [] if data.nil? || data.empty? + lines = data.split("\n") + header = lines.index("---") + header ? lines[header + 1..-1] : lines + end + + def gem_parser + @gem_parser ||= GemParser.new + end + + # This is mostly the same as `split(" ", 3)` but it avoids allocating extra objects. + # This method gets called at least once for every gem when parsing versions. + def parse_version_checksum(line, checksums) + return unless (name_end = line.index(" ")) # Artifactory bug causes blank lines in artifactor index files + return unless (checksum_start = line.index(" ", name_end + 1) + 1) + checksum_end = line.size - checksum_start + + line.freeze # allows slicing into the string to not allocate a copy of the line + name = line[0, name_end] + checksum = line[checksum_start, checksum_end] + checksums[name.freeze] = checksum # freeze name since it is used as a hash key + end + end + end +end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 6cf1f9a255..d403f2d586 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -81,7 +81,7 @@ module Bundler @resolved_bundler_version = nil @locked_ruby_version = nil - @new_platform = nil + @new_platforms = [] @removed_platform = nil if lockfile_exists? @@ -367,6 +367,10 @@ module Bundler end def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false) + return unless Bundler.frozen_bundle? + + raise ProductionError, "Frozen mode is set, but there's no lockfile" unless lockfile_exists? + added = [] deleted = [] changed = [] @@ -395,7 +399,7 @@ module Bundler changed << "* #{name} from `#{lockfile_source_name}` to `#{gemfile_source_name}`" end - reason = change_reason + reason = nothing_changed? ? "some dependencies were deleted from your gemfile" : change_reason msg = String.new msg << "#{reason.capitalize.strip}, but the lockfile can't be updated because frozen mode is set" msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any? @@ -453,8 +457,10 @@ module Bundler end def add_platform(platform) - @new_platform ||= [email protected]?(platform) - @platforms |= [platform] + return if @platforms.include?(platform) + + @new_platforms << platform + @platforms << platform end def remove_platform(platform) @@ -478,7 +484,7 @@ module Bundler !@source_changes && !@dependency_changes && - !@new_platform && + @new_platforms.empty? && !@path_changes && !@local_changes && !@missing_lockfile_dep && @@ -561,7 +567,7 @@ module Bundler def resolution_packages @resolution_packages ||= begin last_resolve = converge_locked_specs - remove_invalid_platforms!(current_dependencies) + remove_invalid_platforms! packages = Resolver::Base.new(source_requirements, expanded_dependencies, last_resolve, @platforms, locked_specs: @originally_locked_specs, unlock: @gems_to_unlock, prerelease: gem_version_promoter.pre?) packages = additional_base_requirements_to_prevent_downgrades(packages, last_resolve) packages = additional_base_requirements_to_force_updates(packages) @@ -621,12 +627,22 @@ module Bundler end def start_resolution + local_platform_needed_for_resolvability = @most_specific_non_local_locked_ruby_platform && [email protected]?(local_platform) + @platforms << local_platform if local_platform_needed_for_resolvability + result = SpecSet.new(resolver.start) @resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version - @platforms = result.add_extra_platforms!(platforms) if should_add_extra_platforms? - result.complete_platforms!(platforms) + if @most_specific_non_local_locked_ruby_platform + if spec_set_incomplete_for_platform?(result, @most_specific_non_local_locked_ruby_platform) + @platforms.delete(@most_specific_non_local_locked_ruby_platform) + elsif local_platform_needed_for_resolvability + @platforms.delete(local_platform) + end + end + + @platforms = result.add_extra_platforms!(platforms) if should_add_extra_platforms? SpecSet.new(result.for(dependencies, false, @platforms)) end @@ -648,13 +664,6 @@ module Bundler end end - def current_ruby_platform_locked? - return false unless generic_local_platform_is_ruby? - return false if Bundler.settings[:force_ruby_platform] && [email protected]?(Gem::Platform::RUBY) - - current_platform_locked? - end - def current_platform_locked? @platforms.any? do |bundle_platform| MatchPlatform.platforms_match?(bundle_platform, local_platform) @@ -662,11 +671,21 @@ module Bundler end def add_current_platform - return if current_ruby_platform_locked? + @most_specific_non_local_locked_ruby_platform = find_most_specific_non_local_locked_ruby_platform + return if @most_specific_non_local_locked_ruby_platform add_platform(local_platform) end + def find_most_specific_non_local_locked_ruby_platform + return unless generic_local_platform_is_ruby? && current_platform_locked? + + most_specific_locked_ruby_platform = most_specific_locked_platform + return unless most_specific_locked_ruby_platform != local_platform + + most_specific_locked_ruby_platform + end + def change_reason if unlocking? unlock_targets = if @gems_to_unlock.any? @@ -686,7 +705,7 @@ module Bundler [ [@source_changes, "the list of sources changed"], [@dependency_changes, "the dependencies in your gemfile changed"], - [@new_platform, "you added a new platform to your gemfile"], + [@new_platforms.any?, "you added a new platform to your gemfile"], [@path_changes, "the gemspecs for path gems changed"], [@local_changes, "the gemspecs for git local gems changed"], [@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""], @@ -1039,21 +1058,25 @@ module Bundler unlocked_definition end - def remove_invalid_platforms!(dependencies) + def remove_invalid_platforms! return if Bundler.frozen_bundle? platforms.reverse_each do |platform| next if local_platform == platform || - (@new_platform && platforms.last == platform) || + @new_platforms.include?(platform) || @path_changes || @dependency_changes || - !@originally_locked_specs.incomplete_for_platform?(dependencies, platform) + @locked_spec_with_invalid_deps || + !spec_set_incomplete_for_platform?(@originally_locked_specs, platform) remove_platform(platform) - add_current_platform if platform == Gem::Platform::RUBY end end + def spec_set_incomplete_for_platform?(spec_set, platform) + spec_set.incomplete_for_platform?(current_dependencies, platform) + end + def source_map @source_map ||= SourceMap.new(sources, dependencies, @locked_specs) end diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb index 87cb352efa..201818cc33 100644 --- a/lib/bundler/endpoint_specification.rb +++ b/lib/bundler/endpoint_specification.rb @@ -92,6 +92,17 @@ module Bundler end end + # needed for `bundle fund` + def metadata + if @remote_specification + @remote_specification.metadata + elsif _local_specification + _local_specification.metadata + else + super + end + end + def _local_specification return unless @loaded_from && File.exist?(local_specification_path) eval(File.read(local_specification_path), nil, local_specification_path).tap do |spec| diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index f6cb198e38..074bef6edc 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -120,7 +120,7 @@ module Bundler specs = Bundler.rubygems.find_name(name) out << [" #{name}", "(#{specs.map(&:version).join(",")})"] unless specs.empty? end - if (exe = caller.last.split(":").first)&.match? %r{(exe|bin)/bundler?\z} + if (exe = caller_locations.last.absolute_path)&.match? %r{(exe|bin)/bundler?\z} shebang = File.read(exe).lines.first shebang.sub!(/^#!\s*/, "") unless shebang.start_with?(Gem.ruby, "/usr/bin/env ruby") diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index db914839b1..6e5656d26a 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -4,8 +4,6 @@ require_relative "base" require_relative "../worker" module Bundler - autoload :CompactIndexClient, File.expand_path("../compact_index_client", __dir__) - class Fetcher class CompactIndex < Base def self.compact_index_request(method_name) @@ -36,15 +34,8 @@ module Bundler until remaining_gems.empty? log_specs { "Looking up gems #{remaining_gems.inspect}" } - - deps = begin - parallel_compact_index_client.dependencies(remaining_gems) - rescue TooManyRequestsError - @bundle_worker&.stop - @bundle_worker = nil # reset it. Not sure if necessary - serial_compact_index_client.dependencies(remaining_gems) - end - next_gems = deps.flat_map {|d| d[3].flat_map(&:first) }.uniq + deps = fetch_gem_infos(remaining_gems).flatten(1) + next_gems = deps.flat_map {|d| d[CompactIndexClient::INFO_DEPS].flat_map(&:first) }.uniq deps.each {|dep| gem_info << dep } complete_gems.concat(deps.map(&:first)).uniq! remaining_gems = next_gems - complete_gems @@ -61,7 +52,7 @@ module Bundler return nil end # Read info file checksums out of /versions, so we can know if gems are up to date - compact_index_client.update_and_parse_checksums! + compact_index_client.available? rescue CompactIndexClient::Updater::MismatchedChecksumError => e Bundler.ui.debug(e.message) nil @@ -81,20 +72,20 @@ module Bundler end end - def parallel_compact_index_client - compact_index_client.execution_mode = lambda do |inputs, &blk| - func = lambda {|object, _index| blk.call(object) } - worker = bundle_worker(func) - inputs.each {|input| worker.enq(input) } - inputs.map { worker.deq } - end - - compact_index_client + def fetch_gem_infos(names) + in_parallel(names) {|name| compact_index_client.info(name) } + rescue TooManyRequestsError # rubygems.org is rate limiting us, slow down. + @bundle_worker&.stop + @bundle_worker = nil # reset it. Not sure if necessary + compact_index_client.reset! + names.map {|name| compact_index_client.info(name) } end - def serial_compact_index_client - compact_index_client.sequential_execution_mode! - compact_index_client + def in_parallel(inputs, &blk) + func = lambda {|object, _index| blk.call(object) } + worker = bundle_worker(func) + inputs.each {|input| worker.enq(input) } + inputs.map { worker.deq } end def bundle_worker(func = nil) diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index de007523ec..70ccceb491 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -46,19 +46,26 @@ module Bundler end module_function :platform_specificity_match - def select_best_platform_match(specs, platform) - matching = specs.select {|spec| spec.match_platform(platform) } + def select_best_platform_match(specs, platform, force_ruby: false, prefer_locked: false) + matching = if force_ruby + specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! } + else + specs.select {|spec| spec.match_platform(platform) } + end + + if prefer_locked + locked_originally = matching.select {|spec| spec.is_a?(LazySpecification) } + return locked_originally if locked_originally.any? + end sort_best_platform_match(matching, platform) end module_function :select_best_platform_match - def force_ruby_platform(specs) - matching = specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! } - - sort_best_platform_match(matching, Gem::Platform::RUBY) + def select_best_local_platform_match(specs, force_ruby: false) + select_best_platform_match(specs, local_platform, force_ruby: force_ruby).map(&:materialize_for_installation).compact end - module_function :force_ruby_platform + module_function :select_best_local_platform_match def sort_best_platform_match(matching, platform) exact = matching.select {|spec| spec.platform == platform } diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 879b481339..c7e93c9ee0 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -23,10 +23,7 @@ module Bundler # @param [Pathname] lockfile_path The lockfile in which to inject the new dependency. # @return [Array] def inject(gemfile_path, lockfile_path) - if Bundler.frozen_bundle? - # ensure the lock and Gemfile are synced - Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true) - end + Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true) # temporarily unfreeze Bundler.settings.temporary(deployment: false, frozen: false) do diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index ef9a0a4e07..cbacf70566 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -69,9 +69,7 @@ module Bundler Bundler.create_bundle_path ProcessLock.lock do - if Bundler.frozen_bundle? - @definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment]) - end + @definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment]) if @definition.dependencies.empty? Bundler.ui.warn "The Gemfile specifies no dependencies" diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb index d3bbcc90f5..a7770eb7e0 100644 --- a/lib/bundler/installer/gem_installer.rb +++ b/lib/bundler/installer/gem_installer.rb @@ -54,7 +54,6 @@ module Bundler spec.source.install( spec, force: force, - ensure_builtin_gems_cached: standalone, build_args: Array(spec_settings), previous_spec: previous_spec, ) diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 5331df2e95..cf5993448c 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -58,9 +58,6 @@ module Bundler else SharedHelpers.relative_path_to(full_path, from: Bundler.root.join(bundler_path)) end - rescue TypeError - error_message = "#{spec.name} #{spec.version} has an invalid gemspec" - raise Gem::InvalidSpecificationException.new(error_message) end def prevent_gem_activation diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 38aea2a4aa..8669e021c2 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -4,6 +4,7 @@ require_relative "force_platform" module Bundler class LazySpecification + include MatchMetadata include MatchPlatform include ForcePlatform diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1 index 56a3b6f85c..bda8338d76 100644 --- a/lib/bundler/man/bundle-add.1 +++ b/lib/bundler/man/bundle-add.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-ADD" "1" "May 2024" "" +.TH "BUNDLE\-ADD" "1" "June 2024" "" .SH "NAME" \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-binstubs.1 b/lib/bundler/man/bundle-binstubs.1 index 4ec301951f..974f206c8f 100644 --- a/lib/bundler/man/bundle-binstubs.1 +++ b/lib/bundler/man/bundle-binstubs.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-BINSTUBS" "1" "May 2024" "" +.TH "BUNDLE\-BINSTUBS" "1" "June 2024" "" .SH "NAME" \fBbundle\-binstubs\fR \- Install the binstubs of the listed gems .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-cache.1 b/lib/bundler/man/bundle-cache.1 index e2da1269e6..f83f325efe 100644 --- a/lib/bundler/man/bundle-cache.1 +++ b/lib/bundler/man/bundle-cache.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-CACHE" "1" "May 2024" "" +.TH "BUNDLE\-CACHE" "1" "June 2024" "" .SH "NAME" \fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-check.1 b/lib/bundler/man/bundle-check.1 index dee1af1326..68e9114385 100644 --- a/lib/bundler/man/bundle-check.1 +++ b/lib/bundler/man/bundle-check.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-CHECK" "1" "May 2024" "" +.TH "BUNDLE\-CHECK" "1" "June 2024" "" .SH "NAME" \fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-clean.1 b/lib/bundler/man/bundle-clean.1 index 7c7f9b5c77..33a627c8d7 100644 --- a/lib/bundler/man/bundle-clean.1 +++ b/lib/bundler/man/bundle-clean.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-CLEAN" "1" "May 2024" "" +.TH "BUNDLE\-CLEAN" "1" "June 2024" "" .SH "NAME" \fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index a207dbbcaa..daf96d6787 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-CONFIG" "1" "May 2024" "" +.TH "BUNDLE\-CONFIG" "1" "June 2024" "" .SH "NAME" \fBbundle\-config\fR \- Set bundler configuration options .SH "SYNOPSIS" @@ -307,7 +307,7 @@ Any \fB\.\fR characters in a host name are mapped to a double underscore (\fB__\ .P This means that if you have a gem server named \fBmy\.gem\-host\.com\fR, you'll need to use the \fBBUNDLE_MY__GEM___HOST__COM\fR variable to configure credentials for it through ENV\. .SH "CONFIGURE BUNDLER DIRECTORIES" -Bundler's home, config, cache and plugin directories are able to be configured through environment variables\. The default location for Bundler's home directory is \fB~/\.bundle\fR, which all directories inherit from by default\. The following outlines the available environment variables and their default values +Bundler's home, cache and plugin directories and config file can be configured through environment variables\. The default location for Bundler's home directory is \fB~/\.bundle\fR, which all directories inherit from by default\. The following outlines the available environment variables and their default values .IP "" 4 .nf BUNDLE_USER_HOME : $HOME/\.bundle diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn index 7e5f458fb2..1a0ec2a5dc 100644 --- a/lib/bundler/man/bundle-config.1.ronn +++ b/lib/bundler/man/bundle-config.1.ronn @@ -397,7 +397,7 @@ through ENV. ## CONFIGURE BUNDLER DIRECTORIES -Bundler's home, config, cache and plugin directories are able to be configured +Bundler's home, cache and plugin directories and config file can be configured through environment variables. The default location for Bundler's home directory is `~/.bundle`, which all directories inherit from by default. The following outlines the available environment variables and their default values diff --git a/lib/bundler/man/bundle-console.1 b/lib/bundler/man/bundle-console.1 index dca18ec43d..a84f13a417 100644 --- a/lib/bundler/man/bundle-console.1 +++ b/lib/bundler/man/bundle-console.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-CONSOLE" "1" "May 2024" "" +.TH "BUNDLE\-CONSOLE" "1" "June 2024" "" .SH "NAME" \fBbundle\-console\fR \- Deprecated way to open an IRB session with the bundle pre\-loaded .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-doctor.1 b/lib/bundler/man/bundle-doctor.1 index 6489cc07f7..ce5b5ab3cb 100644 --- a/lib/bundler/man/bundle-doctor.1 +++ b/lib/bundler/man/bundle-doctor.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-DOCTOR" "1" "May 2024" "" +.TH "BUNDLE\-DOCTOR" "1" "June 2024" "" .SH "NAME" \fBbundle\-doctor\fR \- Checks the bundle for common problems .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-exec.1 b/lib/bundler/man/bundle-exec.1 index 1548d29670..f54d4469e1 100644 --- a/lib/bundler/man/bundle-exec.1 +++ b/lib/bundler/man/bundle-exec.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-EXEC" "1" "May 2024" "" +.TH "BUNDLE\-EXEC" "1" "June 2024" "" .SH "NAME" \fBbundle\-exec\fR \- Execute a command in the context of the bundle .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1 index 5df7b0ef2f..d4caac51bc 100644 --- a/lib/bundler/man/bundle-gem.1 +++ b/lib/bundler/man/bundle-gem.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-GEM" "1" "May 2024" "" +.TH "BUNDLE\-GEM" "1" "June 2024" "" .SH "NAME" \fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem .SH "SYNOPSIS" @@ -44,6 +44,8 @@ When Bundler is configured to not generate tests, an interactive prompt will be .IP When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 +\fB\-\-no\-test\fR: Do not use a test framework (overrides \fB\-\-test\fR specified in the global config)\. +.IP "\(bu" 4 \fB\-\-ci\fR, \fB\-\-ci=github\fR, \fB\-\-ci=gitlab\fR, \fB\-\-ci=circle\fR: Specify the continuous integration service that Bundler should use when generating the project\. Acceptable values are \fBgithub\fR, \fBgitlab\fR and \fBcircle\fR\. A configuration file will be generated in the project directory\. Given no option is specified: .IP When Bundler is configured to generate CI files, this defaults to Bundler's global config setting \fBgem\.ci\fR\. @@ -52,6 +54,8 @@ When Bundler is configured to not generate CI files, an interactive prompt will .IP When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 +\fB\-\-no\-ci\fR: Do not use a continuous integration service (overrides \fB\-\-ci\fR specified in the global config)\. +.IP "\(bu" 4 \fB\-\-linter\fR, \fB\-\-linter=rubocop\fR, \fB\-\-linter=standard\fR: Specify the linter and code formatter that Bundler should add to the project's development dependencies\. Acceptable values are \fBrubocop\fR and \fBstandard\fR\. A configuration file will be generated in the project directory\. Given no option is specified: .IP When Bundler is configured to add a linter, this defaults to Bundler's global config setting \fBgem\.linter\fR\. @@ -60,6 +64,8 @@ When Bundler is configured not to add a linter, an interactive prompt will be di .IP When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 +\fB\-\-no\-linter\fR: Do not add a linter (overrides \fB\-\-linter\fR specified in the global config)\. +.IP "\(bu" 4 \fB\-e\fR, \fB\-\-edit[=EDITOR]\fR: Open the resulting GEM_NAME\.gemspec in EDITOR, or the default editor if not specified\. The default is \fB$BUNDLER_EDITOR\fR, \fB$VISUAL\fR, or \fB$EDITOR\fR\. .IP "" 0 .SH "SEE ALSO" diff --git a/lib/bundler/man/bundle-gem.1.ronn b/lib/bundler/man/bundle-gem.1.ronn index 46fa2f179f..2d71d8dabe 100644 --- a/lib/bundler/man/bundle-gem.1.ronn +++ b/lib/bundler/man/bundle-gem.1.ronn @@ -76,6 +76,10 @@ configuration file using the following names: the answer will be saved in Bundler's global config for future `bundle gem` use. +* `--no-test`: + Do not use a test framework (overrides `--test` specified in the global + config). + * `--ci`, `--ci=github`, `--ci=gitlab`, `--ci=circle`: Specify the continuous integration service that Bundler should use when generating the project. Acceptable values are `github`, `gitlab` @@ -92,6 +96,10 @@ configuration file using the following names: the answer will be saved in Bundler's global config for future `bundle gem` use. +* `--no-ci`: + Do not use a continuous integration service (overrides `--ci` specified in + the global config). + * `--linter`, `--linter=rubocop`, `--linter=standard`: Specify the linter and code formatter that Bundler should add to the project's development dependencies. Acceptable values are `rubocop` and @@ -108,6 +116,9 @@ configuration file using the following names: the answer will be saved in Bundler's global config for future `bundle gem` use. +* `--no-linter`: + Do not add a linter (overrides `--linter` specified in the global config). + * `-e`, `--edit[=EDITOR]`: Open the resulting GEM_NAME.gemspec in EDITOR, or the default editor if not specified. The default is `$BUNDLER_EDITOR`, `$VISUAL`, or `$EDITOR`. diff --git a/lib/bundler/man/bundle-help.1 b/lib/bundler/man/bundle-help.1 index a3e7c7770d..b37e249543 100644 --- a/lib/bundler/man/bundle-help.1 +++ b/lib/bundler/man/bundle-help.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-HELP" "1" "May 2024" "" +.TH "BUNDLE\-HELP" "1" "June 2024" "" .SH "NAME" \fBbundle\-help\fR \- Displays detailed help for each subcommand .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-info.1 b/lib/bundler/man/bundle-info.1 index a3d7ff0988..a00c367a27 100644 --- a/lib/bundler/man/bundle-info.1 +++ b/lib/bundler/man/bundle-info.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-INFO" "1" "May 2024" "" +.TH "BUNDLE\-INFO" "1" "June 2024" "" .SH "NAME" \fBbundle\-info\fR \- Show information for the given gem in your bundle .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-init.1 b/lib/bundler/man/bundle-init.1 index a0edaaa18f..8ac6827f8b 100644 --- a/lib/bundler/man/bundle-init.1 +++ b/lib/bundler/man/bundle-init.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-INIT" "1" "May 2024" "" +.TH "BUNDLE\-INIT" "1" "June 2024" "" .SH "NAME" \fBbundle\-init\fR \- Generates a Gemfile into the current working directory .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1 index 7a1038206e..9e539cc5b4 100644 --- a/lib/bundler/man/bundle-inject.1 +++ b/lib/bundler/man/bundle-inject.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-INJECT" "1" "May 2024" "" +.TH "BUNDLE\-INJECT" "1" "June 2024" "" .SH "NAME" \fBbundle\-inject\fR \- Add named gem(s) with version requirements to Gemfile .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1 index cc46a03b7f..bfc33f9fb4 100644 --- a/lib/bundler/man/bundle-install.1 +++ b/lib/bundler/man/bundle-install.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-INSTALL" "1" "May 2024" "" +.TH "BUNDLE\-INSTALL" "1" "June 2024" "" .SH "NAME" \fBbundle\-install\fR \- Install the dependencies specified in your Gemfile .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-list.1 b/lib/bundler/man/bundle-list.1 index 21723608cc..20765f7c12 100644 --- a/lib/bundler/man/bundle-list.1 +++ b/lib/bundler/man/bundle-list.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-LIST" "1" "May 2024" "" +.TH "BUNDLE\-LIST" "1" "June 2024" "" .SH "NAME" \fBbundle\-list\fR \- List all the gems in the bundle .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-lock.1 b/lib/bundler/man/bundle-lock.1 index 8b81b7732f..474ad40b23 100644 --- a/lib/bundler/man/bundle-lock.1 +++ b/lib/bundler/man/bundle-lock.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-LOCK" "1" "May 2024" "" +.TH "BUNDLE\-LOCK" "1" "June 2024" "" .SH "NAME" \fBbundle\-lock\fR \- Creates / Updates a lockfile without installing .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-open.1 b/lib/bundler/man/bundle-open.1 index 41a8804a09..e7a68a6a62 100644 --- a/lib/bundler/man/bundle-open.1 +++ b/lib/bundler/man/bundle-open.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-OPEN" "1" "May 2024" "" +.TH "BUNDLE\-OPEN" "1" "June 2024" "" .SH "NAME" \fBbundle\-open\fR \- Opens the source directory for a gem in your bundle .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-outdated.1 b/lib/bundler/man/bundle-outdated.1 index 838fce45cd..9125a3e16e 100644 --- a/lib/bundler/man/bundle-outdated.1 +++ b/lib/bundler/man/bundle-outdated.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-OUTDATED" "1" "May 2024" "" +.TH "BUNDLE\-OUTDATED" "1" "June 2024" "" .SH "NAME" \fBbundle\-outdated\fR \- List installed gems with newer versions available .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-platform.1 b/lib/bundler/man/bundle-platform.1 index 0dbce7a7a4..f6044ac025 100644 --- a/lib/bundler/man/bundle-platform.1 +++ b/lib/bundler/man/bundle-platform.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-PLATFORM" "1" "May 2024" "" +.TH "BUNDLE\-PLATFORM" "1" "June 2024" "" .SH "NAME" \fBbundle\-platform\fR \- Displays platform compatibility information .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-plugin.1 b/lib/bundler/man/bundle-plugin.1 index 1290abb3ba..9b08ed05e0 100644 --- a/lib/bundler/man/bundle-plugin.1 +++ b/lib/bundler/man/bundle-plugin.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-PLUGIN" "1" "May 2024" "" +.TH "BUNDLE\-PLUGIN" "1" "June 2024" "" .SH "NAME" \fBbundle\-plugin\fR \- Manage Bundler plugins .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-pristine.1 b/lib/bundler/man/bundle-pristine.1 index bf4a7cd323..3412ef2b7c 100644 --- a/lib/bundler/man/bundle-pristine.1 +++ b/lib/bundler/man/bundle-pristine.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-PRISTINE" "1" "May 2024" "" +.TH "BUNDLE\-PRISTINE" "1" "June 2024" "" .SH "NAME" \fBbundle\-pristine\fR \- Restores installed gems to their pristine condition .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-remove.1 b/lib/bundler/man/bundle-remove.1 index c3c96b416d..257b09e2f1 100644 --- a/lib/bundler/man/bundle-remove.1 +++ b/lib/bundler/man/bundle-remove.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-REMOVE" "1" "May 2024" "" +.TH "BUNDLE\-REMOVE" "1" "June 2024" "" .SH "NAME" \fBbundle\-remove\fR \- Removes gems from the Gemfile .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-show.1 b/lib/bundler/man/bundle-show.1 index c054875efd..7061a436e9 100644 --- a/lib/bundler/man/bundle-show.1 +++ b/lib/bundler/man/bundle-show.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-SHOW" "1" "May 2024" "" +.TH "BUNDLE\-SHOW" "1" "June 2024" "" .SH "NAME" \fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-update.1 b/lib/bundler/man/bundle-update.1 index acd80ec75c..b433fc474b 100644 --- a/lib/bundler/man/bundle-update.1 +++ b/lib/bundler/man/bundle-update.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-UPDATE" "1" "May 2024" "" +.TH "BUNDLE\-UPDATE" "1" "June 2024" "" .SH "NAME" \fBbundle\-update\fR \- Update your gems to the latest available versions .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-version.1 b/lib/bundler/man/bundle-version.1 index 44eaf92224..1170deeae8 100644 --- a/lib/bundler/man/bundle-version.1 +++ b/lib/bundler/man/bundle-version.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-VERSION" "1" "May 2024" "" +.TH "BUNDLE\-VERSION" "1" "June 2024" "" .SH "NAME" \fBbundle\-version\fR \- Prints Bundler version information .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle-viz.1 b/lib/bundler/man/bundle-viz.1 index 77b902214c..0640f11cbb 100644 --- a/lib/bundler/man/bundle-viz.1 +++ b/lib/bundler/man/bundle-viz.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE\-VIZ" "1" "May 2024" "" +.TH "BUNDLE\-VIZ" "1" "June 2024" "" .SH "NAME" \fBbundle\-viz\fR \- Generates a visual dependency graph for your Gemfile .SH "SYNOPSIS" diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1 index 199d1ce9fd..70f4252461 100644 --- a/lib/bundler/man/bundle.1 +++ b/lib/bundler/man/bundle.1 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "BUNDLE" "1" "May 2024" "" +.TH "BUNDLE" "1" "June 2024" "" .SH "NAME" \fBbundle\fR \- Ruby Dependency Management .SH "SYNOPSIS" diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5 index fa9e31f615..f9eba7df13 100644 --- a/lib/bundler/man/gemfile.5 +++ b/lib/bundler/man/gemfile.5 @@ -1,6 +1,6 @@ .\" generated with nRonn/v0.11.1 .\" https://github.com/n-ronn/nronn/tree/0.11.1 -.TH "GEMFILE" "5" "May 2024" "" +.TH "GEMFILE" "5" "June 2024" "" .SH "NAME" \fBGemfile\fR \- A format for describing gem dependencies for Ruby programs .SH "SYNOPSIS" diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 1a6711ea6f..2be7af94a2 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -79,7 +79,8 @@ module Bundler def solve_versions(root:, logger:) solver = PubGrub::VersionSolver.new(source: self, root: root, logger: logger) result = solver.solve - result.map {|package, version| version.to_specs(package) }.flatten.uniq + resolved_specs = result.map {|package, version| version.to_specs(package) }.flatten + resolved_specs |= @base.specs_compatible_with(SpecSet.new(resolved_specs)) rescue PubGrub::SolveFailure => e incompatibility = e.incompatibility @@ -254,7 +255,7 @@ module Bundler results = filter_matching_specs(results, locked_requirement) if locked_requirement results.group_by(&:version).reduce([]) do |groups, (version, specs)| - platform_specs = package.platforms.map {|platform| select_best_platform_match(specs, platform) } + platform_specs = package.platform_specs(specs) # If package is a top-level dependency, # candidate is only valid if there are matching versions for all resolution platforms. @@ -269,14 +270,22 @@ module Bundler next groups if platform_specs.all?(&:empty?) end - platform_specs.flatten! - ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY) - groups << Resolver::Candidate.new(version, specs: ruby_specs) if ruby_specs.any? + ruby_group = Resolver::SpecGroup.new(ruby_specs) + + unless ruby_group.empty? + platform_specs.each do |specs| + ruby_group.merge(Resolver::SpecGroup.new(specs)) + end + + groups << Resolver::Candidate.new(version, group: ruby_group, priority: -1) + next groups if package.force_ruby_platform? + end - next groups if platform_specs == ruby_specs || package.force_ruby_platform? + platform_group = Resolver::SpecGroup.new(platform_specs.flatten.uniq) + next groups if platform_group == ruby_group - groups << Resolver::Candidate.new(version, specs: platform_specs) + groups << Resolver::Candidate.new(version, group: platform_group, priority: 1) groups end @@ -431,8 +440,8 @@ module Bundler def requirement_to_range(requirement) ranges = requirement.requirements.map do |(op, version)| - ver = Resolver::Candidate.new(version).generic! - platform_ver = Resolver::Candidate.new(version).platform_specific! + ver = Resolver::Candidate.new(version, priority: -1) + platform_ver = Resolver::Candidate.new(version, priority: 1) case op when "~>" diff --git a/lib/bundler/resolver/base.rb b/lib/bundler/resolver/base.rb index ad19eeb3f4..b0c5c58047 100644 --- a/lib/bundler/resolver/base.rb +++ b/lib/bundler/resolver/base.rb @@ -30,6 +30,10 @@ module Bundler end.compact end + def specs_compatible_with(result) + @base.specs_compatible_with(result) + end + def [](name) @base[name] end diff --git a/lib/bundler/resolver/candidate.rb b/lib/bundler/resolver/candidate.rb index 9e8b913335..f593fc5d61 100644 --- a/lib/bundler/resolver/candidate.rb +++ b/lib/bundler/resolver/candidate.rb @@ -24,10 +24,10 @@ module Bundler attr_reader :version - def initialize(version, specs: []) - @spec_group = Resolver::SpecGroup.new(specs) + def initialize(version, group: nil, priority: -1) + @spec_group = group || SpecGroup.new([]) @version = Gem::Version.new(version) - @ruby_only = specs.map(&:platform).uniq == [Gem::Platform::RUBY] + @priority = priority end def dependencies @@ -40,18 +40,6 @@ module Bundler @spec_group.to_specs(package.force_ruby_platform?) end - def generic! - @ruby_only = true - - self - end - - def platform_specific! - @ruby_only = false - - self - end - def prerelease? @version.prerelease? end @@ -61,7 +49,7 @@ module Bundler end def sort_obj - [@version, @ruby_only ? -1 : 1] + [@version, @priority] end def <=>(other) diff --git a/lib/bundler/resolver/package.rb b/lib/bundler/resolver/package.rb index 0461328683..16c43d05af 100644 --- a/lib/bundler/resolver/package.rb +++ b/lib/bundler/resolver/package.rb @@ -25,6 +25,10 @@ module Bundler @prerelease = @dependency.prerelease? || @locked_version&.prerelease? || prerelease ? :consider_first : :ignore end + def platform_specs(specs) + platforms.map {|platform| GemHelpers.select_best_platform_match(specs, platform, prefer_locked: !unlock?) } + end + def to_s @name.delete("\0") end diff --git a/lib/bundler/resolver/spec_group.rb b/lib/bundler/resolver/spec_group.rb index 5cee444e5e..f950df6eda 100644 --- a/lib/bundler/resolver/spec_group.rb +++ b/lib/bundler/resolver/spec_group.rb @@ -3,6 +3,8 @@ module Bundler class Resolver class SpecGroup + attr_reader :specs + def initialize(specs) @specs = specs end @@ -38,17 +40,33 @@ module Bundler def dependencies @dependencies ||= @specs.map do |spec| __dependencies(spec) + metadata_dependencies(spec) - end.flatten.uniq + end.flatten.uniq.sort + end + + def ==(other) + sorted_spec_names == other.sorted_spec_names + end + + def merge(other) + return false unless equivalent?(other) + + @specs |= other.specs + + true end protected def sorted_spec_names - @sorted_spec_names ||= @specs.map(&:full_name).sort + @specs.map(&:full_name).sort end private + def equivalent?(other) + name == other.name && version == other.version && source == other.source && dependencies == other.dependencies + end + def exemplary_spec @specs.first end diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 18180a81a1..2a18ce1c49 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -30,9 +30,42 @@ module Gem end end + # Can be removed once RubyGems 3.5.14 support is dropped + unless Gem.respond_to?(:open_file_with_flock) + def self.open_file_with_flock(path, &block) + flags = File.exist?(path) ? "r+" : "a+" + + File.open(path, flags) do |io| + begin + io.flock(File::LOCK_EX) + rescue Errno::ENOSYS, Errno::ENOTSUP + end + yield io + rescue Errno::ENOLCK # NFS + if Thread.main != Thread.current + raise + else + File.open(path, flags, &block) + end + end + end + end + require "rubygems/specification" + # Can be removed once RubyGems 3.5.14 support is dropped + VALIDATES_FOR_RESOLUTION = Specification.new.respond_to?(:validate_for_resolution).freeze + + # Can be removed once RubyGems 3.3.15 support is dropped + FLATTENS_REQUIRED_PATHS = Specification.new.respond_to?(:flatten_require_paths).freeze + class Specification + # Can be removed once RubyGems 3.5.15 support is dropped + correct_array_attributes = @@default_value.select {|_k,v| v.is_a?(Array) }.keys + unless @@array_attributes == correct_array_attributes + @@array_attributes = correct_array_attributes # rubocop:disable Style/ClassVars + end + require_relative "match_metadata" require_relative "match_platform" @@ -131,6 +164,33 @@ module Gem !default_gem? && !File.directory?(full_gem_path) end + unless VALIDATES_FOR_RESOLUTION + def validate_for_resolution + SpecificationPolicy.new(self).validate_for_resolution + end + end + + unless FLATTENS_REQUIRED_PATHS + def flatten_require_paths + return unless raw_require_paths.first.is_a?(Array) + + warn "#{name} #{version} includes a gemspec with `require_paths` set to an array of arrays. Newer versions of this gem might've already fixed this" + raw_require_paths.flatten! + end + + class << self + module RequirePathFlattener + def from_yaml(input) + spec = super(input) + spec.flatten_require_paths + spec + end + end + + prepend RequirePathFlattener + end + end + private def dependencies_to_gemfile(dependencies, group = nil) @@ -150,6 +210,14 @@ module Gem end end + unless VALIDATES_FOR_RESOLUTION + class SpecificationPolicy + def validate_for_resolution + validate_required! + end + end + end + module BetterPermissionError def data super @@ -241,7 +309,7 @@ module Gem # cpu ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu || - (@cpu == "arm" && other.cpu.start_with?("arm"))) && + (@cpu == "arm" && other.cpu.start_with?("armv"))) && # os @os == other.os && diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index d563868cd2..4d4fd20fea 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -29,7 +29,10 @@ module Bundler write_build_info_file run_post_build_hooks - generate_bin + SharedHelpers.filesystem_access(bin_dir, :write) do + generate_bin + end + generate_plugins write_spec @@ -45,7 +48,17 @@ module Bundler spec end - def pre_install_checks + if Bundler.rubygems.provides?("< 3.5") + def pre_install_checks + super + rescue Gem::FilePermissionError + # Ignore permission checks in RubyGems. Instead, go on, and try to write + # for real. We properly handle permission errors when they happen. + nil + end + end + + def ensure_writable_dir(dir) super rescue Gem::FilePermissionError # Ignore permission checks in RubyGems. Instead, go on, and try to write @@ -68,6 +81,26 @@ module Bundler end end + if Bundler.rubygems.provides?("< 3.5.15") + def generate_bin_script(filename, bindir) + bin_script_path = File.join bindir, formatted_program_filename(filename) + + Gem.open_file_with_flock("#{bin_script_path}.lock") do + require "fileutils" + FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers + + File.open(bin_script_path, "wb", 0o755) do |file| + file.write app_script_text(filename) + file.chmod(options[:prog_mode] || 0o755) + end + end + + verbose bin_script_path + + generate_windows_script filename, bindir + end + end + def build_extensions extension_cache_path = options[:bundler_extension_cache_path] extension_dir = spec.extension_dir diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index da555681f9..ebe55a7e7a 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -48,7 +48,7 @@ module Bundler end def validate(spec) - Bundler.ui.silence { spec.validate(false) } + Bundler.ui.silence { spec.validate_for_resolution } rescue Gem::InvalidSpecificationException => e error_message = "The gemspec at #{spec.loaded_from} is not valid. Please fix this gemspec.\n" \ "The validation error was '#{e.message}'\n" @@ -204,7 +204,7 @@ module Bundler [::Kernel.singleton_class, ::Kernel].each do |kernel_class| redefine_method(kernel_class, :gem) do |dep, *reqs| - if executables&.include?(File.basename(caller.first.split(":").first)) + if executables&.include?(File.basename(caller_locations(1, 1).first.path)) break end @@ -469,11 +469,25 @@ module Bundler end def all_specs + SharedHelpers.major_deprecation 2, "Bundler.rubygems.all_specs has been removed in favor of Bundler.rubygems.installed_specs" + Gem::Specification.stubs.map do |stub| StubSpecification.from_stub(stub) end end + def installed_specs + Gem::Specification.stubs.reject(&:default_gem?).map do |stub| + StubSpecification.from_stub(stub) + end + end + + def default_specs + Gem::Specification.default_stubs.map do |stub| + StubSpecification.from_stub(stub) + end + end + def find_bundler(version) find_name("bundler").find {|s| s.version.to_s == version } end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index ec772cfe7b..fd7757d2c3 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -10,7 +10,7 @@ module Bundler end def setup(*groups) - @definition.ensure_equivalent_gemfile_and_lockfile if Bundler.frozen_bundle? + @definition.ensure_equivalent_gemfile_and_lockfile # Has to happen first clean_load_path diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb index 5accda4bcb..ea7c014f3c 100644 --- a/lib/bundler/self_manager.rb +++ b/lib/bundler/self_manager.rb @@ -70,8 +70,23 @@ module Bundler configured_gem_home = ENV["GEM_HOME"] configured_gem_path = ENV["GEM_PATH"] - cmd = [$PROGRAM_NAME, *ARGV] - cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME) + # Bundler specs need some stuff to be required before Bundler starts + # running, for example, for faking the compact index API. However, these + # flags are lost when we reexec to a different version of Bundler. In the + # future, we may be able to properly reconstruct the original Ruby + # invocation (see https://bugs.ruby-lang.org/issues/6648), but for now + # there's no way to do it, so we need to be explicit about how to re-exec. + # This may be a feature end users request at some point, but maybe by that + # time, we have builtin tools to do. So for now, we use an undocumented + # ENV variable only for our specs. + bundler_spec_original_cmd = ENV["BUNDLER_SPEC_ORIGINAL_CMD"] + if bundler_spec_original_cmd + require "shellwords" + cmd = [*Shellwords.shellsplit(bundler_spec_original_cmd), *ARGV] + else + cmd = [$PROGRAM_NAME, *ARGV] + cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME) + end Bundler.with_original_env do Kernel.exec( @@ -92,6 +107,7 @@ module Bundler def autoswitching_applies? ENV["BUNDLER_VERSION"].nil? && Bundler.rubygems.supports_bundler_trampolining? && + ruby_can_restart_with_same_arguments? && SharedHelpers.in_bundle? && lockfile_version end @@ -151,6 +167,10 @@ module Bundler !version.to_s.end_with?(".dev") end + def ruby_can_restart_with_same_arguments? + $PROGRAM_NAME != "-e" + end + def updating? "update".start_with?(ARGV.first || " ") && ARGV[1..-1].any? {|a| a.start_with?("--bundler") } end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index abbaec9783..878747a53b 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -103,6 +103,7 @@ module Bundler def initialize(root = nil) @root = root @local_config = load_config(local_config_file) + @local_root = root || Pathname.new(".bundle").expand_path @env_config = ENV.to_h @env_config.select! {|key, _value| key.start_with?("BUNDLE_") } @@ -142,7 +143,7 @@ module Bundler end def set_local(key, value) - local_config_file || raise(GemfileNotFound, "Could not locate Gemfile") + local_config_file = @local_root.join("config") set_key(key, value, @local_config, local_config_file) end @@ -491,6 +492,10 @@ module Bundler valid_file = file.exist? && !file.size.zero? return {} unless valid_file serializer_class.load(file.read).inject({}) do |config, (k, v)| + k = k.dup + k << "/" if /https?:/i.match?(k) && !k.end_with?("/", "__#{FALLBACK_TIMEOUT_URI_OPTION.upcase}") + k.gsub!(".", "__") + unless k.start_with?("#") if k.include?("-") Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \ @@ -518,26 +523,25 @@ module Bundler YAMLSerializer end - PER_URI_OPTIONS = %w[ - fallback_timeout - ].freeze + FALLBACK_TIMEOUT_URI_OPTION = "fallback_timeout" NORMALIZE_URI_OPTIONS_PATTERN = / \A (\w+\.)? # optional prefix key (https?.*?) # URI - (\.#{Regexp.union(PER_URI_OPTIONS)})? # optional suffix key + (\.#{FALLBACK_TIMEOUT_URI_OPTION})? # optional suffix key \z /ix def self.key_for(key) - key = normalize_uri(key).to_s if key.is_a?(String) && key.start_with?("http", "mirror.http") - key = key_to_s(key).gsub(".", "__") + key = key_to_s(key) + key = normalize_uri(key) if key.start_with?("http", "mirror.http") + key = key.gsub(".", "__") key.gsub!("-", "___") key.upcase! - key.prepend("BUNDLE_") + key.gsub(/\A([ #]*)/, '\1BUNDLE_') end # TODO: duplicates Rubygems#normalize_uri diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index 6010d66742..5a0fd8e0e3 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -5,6 +5,9 @@ require_relative "shared_helpers" if Bundler::SharedHelpers.in_bundle? require_relative "../bundler" + # autoswitch to locked Bundler version if available + Bundler.auto_switch + # try to auto_install first before we get to the `Bundler.ui.silence`, so user knows what is happening Bundler.auto_install diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 28f0cdff19..e55632b89f 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -4,14 +4,14 @@ require_relative "version" require_relative "rubygems_integration" require_relative "current_ruby" +autoload :Pathname, "pathname" + module Bundler autoload :WINDOWS, File.expand_path("constants", __dir__) autoload :FREEBSD, File.expand_path("constants", __dir__) autoload :NULL, File.expand_path("constants", __dir__) module SharedHelpers - autoload :Pathname, "pathname" - def root gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 198e335bb6..174a24d358 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -32,6 +32,20 @@ module Bundler @local = false end + def remote! + return if @allow_remote + + @local_specs = nil + @allow_remote = true + end + + def cached! + return if @allow_cached + + @local_specs = nil + @allow_cached = true + end + def self.from_lock(options) new(options.merge("uri" => options.delete("remote"))) end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 978b0b2c9f..754eaa39c4 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -18,9 +18,6 @@ module Bundler @options = options.dup @glob = options["glob"] || DEFAULT_GLOB - @allow_cached = false - @allow_remote = false - @root_path = options["root_path"] || root if options["path"] @@ -41,16 +38,6 @@ module Bundler @original_path = @path end - def remote! - @local_specs = nil - @allow_remote = true - end - - def cached! - @local_specs = nil - @allow_cached = true - end - def self.from_lock(options) new(options.merge("path" => options.delete("remote"))) end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 3ac1bd4ff8..1085fdc2d8 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -22,6 +22,8 @@ module Bundler @checksum_store = Checksum::Store.new Array(options["remotes"]).reverse_each {|r| add_remote(r) } + + @lockfile_remotes = @remotes if options["from_lockfile"] end def caches @@ -91,13 +93,13 @@ module Bundler def self.from_lock(options) options["remotes"] = Array(options.delete("remote")).reverse - new(options) + new(options.merge("from_lockfile" => true)) end def to_lock out = String.new("GEM\n") - remotes.reverse_each do |remote| - out << " remote: #{remove_auth remote}\n" + lockfile_remotes.reverse_each do |remote| + out << " remote: #{remote}\n" end out << " specs:\n" end @@ -136,20 +138,17 @@ module Bundler index = @allow_remote ? remote_specs.dup : Index.new index.merge!(cached_specs) if @allow_cached index.merge!(installed_specs) if @allow_local + + # complete with default specs, only if not already available in the + # index through remote, cached, or installed specs + index.use(default_specs) if @allow_local + index end end def install(spec, options = {}) - force = options[:force] - ensure_builtin_gems_cached = options[:ensure_builtin_gems_cached] - - if ensure_builtin_gems_cached && spec.default_gem? && !cached_path(spec) - cached_built_in_gem(spec) unless spec.remote - force = true - end - - if installed?(spec) && !force + if (spec.default_gem? && !cached_built_in_gem(spec)) || (installed?(spec) && !options[:force]) print_using_message "Using #{version_message(spec, options[:previous_spec])}" return nil # no post-install message end @@ -207,6 +206,7 @@ module Bundler spec.full_gem_path = installed_spec.full_gem_path spec.loaded_from = installed_spec.loaded_from + spec.base_dir = installed_spec.base_dir spec.post_install_message end @@ -362,7 +362,7 @@ module Bundler def installed_specs @installed_specs ||= Index.build do |idx| - Bundler.rubygems.all_specs.reverse_each do |spec| + Bundler.rubygems.installed_specs.reverse_each do |spec| spec.source = self if Bundler.rubygems.spec_missing_extensions?(spec, false) Bundler.ui.debug "Source #{self} is ignoring #{spec} because it is missing extensions" @@ -373,6 +373,15 @@ module Bundler end end + def default_specs + @default_specs ||= Index.build do |idx| + Bundler.rubygems.default_specs.each do |spec| + spec.source = self + idx << spec + end + end + end + def cached_specs @cached_specs ||= begin idx = Index.new @@ -457,6 +466,10 @@ module Bundler private + def lockfile_remotes + @lockfile_remotes || credless_remotes + end + # Checks if the requested spec exists in the global cache. If it does, # we copy it to the download path, and if it does not, we download it. # diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 2933d28450..5f513f3f22 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -71,12 +71,6 @@ module Bundler platforms end - def complete_platforms!(platforms) - platforms.each do |platform| - complete_platform(platform) - end - end - def validate_deps(s) s.runtime_dependencies.each do |dep| next if dep.name == "bundler" @@ -158,6 +152,12 @@ module Bundler @specs.detect {|spec| spec.name == name && spec.match_platform(platform) } end + def specs_compatible_with(other) + select do |spec| + other.valid?(spec) + end + end + def delete_by_name(name) @specs.reject! {|spec| spec.name == name } @@ -195,6 +195,10 @@ module Bundler lookup.keys end + def valid?(s) + s.matches_current_metadata? && valid_dependencies?(s) + end + private def reset! @@ -209,7 +213,7 @@ module Bundler spec = specs.first matching_specs = spec.source.specs.search([spec.name, spec.version]) platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find do |s| - s.matches_current_metadata? && valid_dependencies?(s) + valid?(s) end if platform_spec @@ -273,13 +277,11 @@ module Bundler specs_for_name = lookup[dep.name] return [] unless specs_for_name - matching_specs = if dep.force_ruby_platform - GemHelpers.force_ruby_platform(specs_for_name) + if platform + GemHelpers.select_best_platform_match(specs_for_name, platform, force_ruby: dep.force_ruby_platform) else - GemHelpers.select_best_platform_match(specs_for_name, platform || Bundler.local_platform) + GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform) end - matching_specs.map!(&:materialize_for_installation).compact! if platform.nil? - matching_specs end def tsort_each_child(s) diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index da830cf8d4..1cbb506ef9 100644 --- a/lib/bundler/stub_specification.rb +++ b/lib/bundler/stub_specification.rb @@ -77,6 +77,14 @@ module Bundler stub.full_require_paths end + def require_paths + stub.require_paths + end + + def base_dir=(path) + stub.base_dir = path + end + def load_paths full_require_paths end diff --git a/lib/bundler/vendored_net_http.rb b/lib/bundler/vendored_net_http.rb index 0dcabaa7d7..8ff2ccd1fe 100644 --- a/lib/bundler/vendored_net_http.rb +++ b/lib/bundler/vendored_net_http.rb @@ -1,12 +1,23 @@ # frozen_string_literal: true -begin - require "rubygems/vendored_net_http" -rescue LoadError +# This defined? guard can be removed once RubyGems 3.4 support is dropped. +# +# Bundler specs load this code from `spec/support/vendored_net_http.rb` to avoid +# activating the Bundler gem too early. Without this guard, we get redefinition +# warnings once Bundler is actually activated and +# `lib/bundler/vendored_net_http.rb` is required. This is not an issue in +# RubyGems versions including `rubygems/vendored_net_http` since `require` takes +# care of avoiding the double load. +# +unless defined?(Gem::Net) begin - require "rubygems/net/http" + require "rubygems/vendored_net_http" rescue LoadError - require "net/http" - Gem::Net = Net + begin + require "rubygems/net/http" + rescue LoadError + require "net/http" + Gem::Net = Net + end end end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 5a97cd658e..50b90355bb 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.5.11".freeze + VERSION = "2.5.16".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 42e6aaf89d..93d08a05aa 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -60,7 +60,6 @@ module Bundler indent, key, quote, val = match.captures val = strip_comment(val) - convert_to_backward_compatible_key!(key) depth = indent.size / 2 if quote.empty? && val.empty? new_hash = {} @@ -92,14 +91,8 @@ module Bundler end end - # for settings' keys - def convert_to_backward_compatible_key!(key) - key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key) - key.gsub!(".", "__") - end - class << self - private :dump_hash, :convert_to_backward_compatible_key! + private :dump_hash end end end diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 2c8515b255..3c629421cd 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -9,7 +9,7 @@ require "rbconfig" module Gem - VERSION = "3.5.11" + VERSION = "3.5.16" end # Must be first since it unloads the prelude from 1.9.2 @@ -760,6 +760,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} ## # Safely write a file in binary mode on all platforms. + def self.write_binary(path, data) open_file(path, "wb") do |io| io.write data @@ -771,24 +772,29 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end ## - # Open a file with given flags, and on Windows protect access with flock + # Open a file with given flags def self.open_file(path, flags, &block) + File.open(path, flags, &block) + end + + ## + # Open a file with given flags, and protect access with flock + + def self.open_file_with_flock(path, &block) + flags = File.exist?(path) ? "r+" : "a+" + File.open(path, flags) do |io| - if !java_platform? && win_platform? - begin - io.flock(File::LOCK_EX) - rescue Errno::ENOSYS, Errno::ENOTSUP - end + begin + io.flock(File::LOCK_EX) + rescue Errno::ENOSYS, Errno::ENOTSUP end yield io - end - rescue Errno::ENOLCK # NFS - if Thread.main != Thread.current - raise - else - File.open(path, flags) do |io| - yield io + rescue Errno::ENOLCK # NFS + if Thread.main != Thread.current + raise + else + open_file(path, flags, &block) end end end diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 0380fceece..0eee52492f 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -99,6 +99,20 @@ class Gem::BasicSpecification end ## + # Regular gems take precedence over default gems + + def default_gem_priority + default_gem? ? 1 : -1 + end + + ## + # Gems higher up in +gem_path+ take precedence + + def base_dir_priority(gem_path) + gem_path.index(base_dir) || gem_path.size + end + + ## # Returns full path to the directory where gem's extensions are installed. def extension_dir @@ -144,6 +158,19 @@ class Gem::BasicSpecification end ## + # Returns the full name of this Gem (see `Gem::BasicSpecification#full_name`). + # Information about where the gem is installed is also included if not + # installed in the default GEM_HOME. + + def full_name_with_location + if base_dir != Gem.dir + "#{full_name} in #{base_dir}" + else + full_name + end + end + + ## # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is # activated. diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index dd2fd77418..4ebbad1c0c 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -21,7 +21,7 @@ module Gem::BundlerVersionFinder end def self.bundle_update_bundler_version - return unless File.basename($0) == "bundle" + return unless ["bundle", "bundler"].include? File.basename($0) return unless "update".start_with?(ARGV.first || " ") bundler_version = nil update_index = nil diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index b272a15b6c..999c9fef0f 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -148,7 +148,7 @@ extensions will be restored. end unless spec.extensions.empty? || options[:extensions] || options[:only_executables] || options[:only_plugins] - say "Skipped #{spec.full_name}, it needs to compile an extension" + say "Skipped #{spec.full_name_with_location}, it needs to compile an extension" next end @@ -157,7 +157,7 @@ extensions will be restored. unless File.exist?(gem) || options[:only_executables] || options[:only_plugins] require_relative "../remote_fetcher" - say "Cached gem for #{spec.full_name} not found, attempting to fetch..." + say "Cached gem for #{spec.full_name_with_location} not found, attempting to fetch..." dep = Gem::Dependency.new spec.name, spec.version found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep @@ -201,7 +201,7 @@ extensions will be restored. installer.install end - say "Restored #{spec.full_name}" + say "Restored #{spec.full_name_with_location}" end end end diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 3200beb45f..1cd38977da 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -510,12 +510,12 @@ if you believe they were disclosed to a third party. # Return the configuration information for +key+. def [](key) - @hash[key.to_s] + @hash[key] || @hash[key.to_s] end # Set configuration option +key+ to +value+. def []=(key, value) - @hash[key.to_s] = value + @hash[key] = value end def ==(other) # :nodoc: @@ -543,8 +543,13 @@ if you believe they were disclosed to a third party. require_relative "yaml_serializer" content = Gem::YAMLSerializer.load(yaml) + deep_transform_config_keys!(content) + end - content.transform_keys! do |k| + private + + def self.deep_transform_config_keys!(config) + config.transform_keys! do |k| if k.match?(/\A:(.*)\Z/) k[1..-1].to_sym elsif k.include?("__") || k.match?(%r{/\Z}) @@ -558,7 +563,7 @@ if you believe they were disclosed to a third party. end end - content.transform_values! do |v| + config.transform_values! do |v| if v.is_a?(String) if v.match?(/\A:(.*)\Z/) v[1..-1].to_sym @@ -571,18 +576,18 @@ if you believe they were disclosed to a third party. else v end - elsif v.is_a?(Hash) && v.empty? + elsif v.empty? nil + elsif v.is_a?(Hash) + deep_transform_config_keys!(v) else v end end - content + config end - private - def set_config_file_name(args) @config_file_name = ENV["GEMRC"] need_config_file_name = false diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 844f292ba2..ea7dd54fdc 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -500,8 +500,7 @@ class Gem::Installer dir_mode = options[:prog_mode] || (mode | 0o111) unless dir_mode == mode - require "fileutils" - FileUtils.chmod dir_mode, bin_path + File.chmod dir_mode, bin_path end check_executable_overwrite filename @@ -539,12 +538,14 @@ class Gem::Installer def generate_bin_script(filename, bindir) bin_script_path = File.join bindir, formatted_program_filename(filename) - require "fileutils" - FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers + Gem.open_file_with_flock("#{bin_script_path}.lock") do + require "fileutils" + FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers - File.open bin_script_path, "wb", 0o755 do |file| - file.print app_script_text(filename) - file.chmod(options[:prog_mode] || 0o755) + File.open(bin_script_path, "wb", 0o755) do |file| + file.write app_script_text(filename) + file.chmod(options[:prog_mode] || 0o755) + end end verbose bin_script_path diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index d54ad12880..dac3b1269f 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -176,7 +176,7 @@ class Gem::Platform # they have the same version, or either one has no version # # Additionally, the platform will match if the local CPU is 'arm' and the - # other CPU starts with "arm" (for generic ARM family support). + # other CPU starts with "armv" (for generic 32-bit ARM family support). # # Of note, this method is not commutative. Indeed the OS 'linux' has a # special case: the version is the libc name, yet while "no version" stands @@ -197,7 +197,7 @@ class Gem::Platform # cpu ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu || - (@cpu == "arm" && other.cpu.start_with?("arm"))) && + (@cpu == "arm" && other.cpu.start_with?("armv"))) && # os @os == other.os && diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb index 02543cb14a..10d4befc7b 100644 --- a/lib/rubygems/requirement.rb +++ b/lib/rubygems/requirement.rb @@ -13,8 +13,8 @@ class Gem::Requirement OPS = { # :nodoc: "=" => lambda {|v, r| v == r }, "!=" => lambda {|v, r| v != r }, - ">" => lambda {|v, r| v > r }, - "<" => lambda {|v, r| v < r }, + ">" => lambda {|v, r| v > r }, + "<" => lambda {|v, r| v < r }, ">=" => lambda {|v, r| v >= r }, "<=" => lambda {|v, r| v <= r }, "~>" => lambda {|v, r| v >= r && v.release < r.bump }, diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 05ce483db6..d6eac7fd86 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -175,7 +175,7 @@ class Gem::Specification < Gem::BasicSpecification end @@attributes = @@default_value.keys.sort_by(&:to_s) - @@array_attributes = @@default_value.reject {|_k,v| v != [] }.keys + @@array_attributes = @@default_value.select {|_k,v| v.is_a?(Array) }.keys @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition do |k| @@default_value[k].nil? end @@ -546,9 +546,9 @@ class Gem::Specification < Gem::BasicSpecification # # Usage: # - # spec.add_runtime_dependency 'example', '~> 1.1', '>= 1.1.4' + # spec.add_dependency 'example', '~> 1.1', '>= 1.1.4' - def add_runtime_dependency(gem, *requirements) + def add_dependency(gem, *requirements) if requirements.uniq.size != requirements.size warn "WARNING: duplicated #{gem} dependency #{requirements}" end @@ -771,6 +771,11 @@ class Gem::Specification < Gem::BasicSpecification end private_class_method :clear_load_cache + def self.gem_path # :nodoc: + Gem.path + end + private_class_method :gem_path + def self.each_gemspec(dirs) # :nodoc: dirs.each do |dir| Gem::Util.glob_files_in_dir("*.gemspec", dir).each do |path| @@ -830,7 +835,11 @@ class Gem::Specification < Gem::BasicSpecification next names if names.nonzero? versions = b.version <=> a.version next versions if versions.nonzero? - Gem::Platform.sort_priority(b.platform) + platforms = Gem::Platform.sort_priority(b.platform) <=> Gem::Platform.sort_priority(a.platform) + next platforms if platforms.nonzero? + default_gem = a.default_gem_priority <=> b.default_gem_priority + next default_gem if default_gem.nonzero? + a.base_dir_priority(gem_path) <=> b.base_dir_priority(gem_path) end end @@ -865,7 +874,7 @@ class Gem::Specification < Gem::BasicSpecification # You probably want to use one of the Enumerable methods instead. def self.all - warn "NOTE: Specification.all called from #{caller.first}" unless + warn "NOTE: Specification.all called from #{caller(1, 1).first}" unless Gem::Deprecate.skip _all end @@ -906,7 +915,7 @@ class Gem::Specification < Gem::BasicSpecification # Return the directories that Specification uses to find specs. def self.dirs - @@dirs ||= Gem::SpecificationRecord.dirs_from(Gem.path) + @@dirs ||= Gem::SpecificationRecord.dirs_from(gem_path) end ## @@ -1495,7 +1504,7 @@ class Gem::Specification < Gem::BasicSpecification private :add_dependency_with_type - alias_method :add_dependency, :add_runtime_dependency + alias_method :add_runtime_dependency, :add_dependency ## # Adds this spec's require paths to LOAD_PATH, in the proper location. @@ -2576,6 +2585,10 @@ class Gem::Specification < Gem::BasicSpecification @test_files.delete_if {|x| File.directory?(x) && !File.symlink?(x) } end + def validate_for_resolution + Gem::SpecificationPolicy.new(self).validate_for_resolution + end + def validate_metadata Gem::SpecificationPolicy.new(self).validate_metadata end diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index 812b0f889e..d7568ddde9 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -45,6 +45,7 @@ class Gem::SpecificationPolicy def validate(strict = false) validate_required! + validate_required_metadata! validate_optional(strict) if packaging || strict @@ -85,15 +86,17 @@ class Gem::SpecificationPolicy validate_authors_field - validate_metadata - validate_licenses_length - validate_lazy_metadata - validate_duplicate_dependencies end + def validate_required_metadata! + validate_metadata + + validate_lazy_metadata + end + def validate_optional(strict) validate_licenses @@ -121,6 +124,13 @@ class Gem::SpecificationPolicy end ## + # Implementation for Specification#validate_for_resolution + + def validate_for_resolution + validate_required! + end + + ## # Implementation for Specification#validate_metadata def validate_metadata diff --git a/lib/rubygems/specification_record.rb b/lib/rubygems/specification_record.rb index dd6aa7eafa..664d506265 100644 --- a/lib/rubygems/specification_record.rb +++ b/lib/rubygems/specification_record.rb @@ -68,7 +68,6 @@ module Gem installed_stubs = installed_stubs(pattern) installed_stubs.select! {|s| Gem::Platform.match_spec? s } if match_platform stubs = installed_stubs + Gem::Specification.default_stubs(pattern) - stubs = stubs.uniq(&:full_name) Gem::Specification._resort!(stubs) stubs end diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 58748df5d6..ea66fbc3f6 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -210,4 +210,25 @@ class Gem::StubSpecification < Gem::BasicSpecification def stubbed? data.is_a? StubLine end + + def ==(other) # :nodoc: + self.class === other && + name == other.name && + version == other.version && + platform == other.platform + end + + alias_method :eql?, :== # :nodoc: + + def hash # :nodoc: + name.hash ^ version.hash ^ platform.hash + end + + def <=>(other) # :nodoc: + sort_obj <=> other.sort_obj + end + + def sort_obj # :nodoc: + [name, version, Gem::Platform.sort_priority(platform)] + end end diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 4d72f6fd0a..214ba53a88 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -86,11 +86,7 @@ class Gem::Uninstaller list = [] - dirs = - Gem::Specification.dirs + - [Gem.default_specifications_dir] - - Gem::Specification.each_spec dirs do |spec| + specification_record.stubs.each do |spec| next unless dependency.matches_spec? spec list << spec @@ -102,7 +98,7 @@ class Gem::Uninstaller default_specs, list = list.partition(&:default_gem?) warn_cannot_uninstall_default_gems(default_specs - list) - @default_specs_matching_uninstall_params = default_specs + @default_specs_matching_uninstall_params = default_specs.map(&:to_spec) list, other_repo_specs = list.partition do |spec| @gem_home == spec.base_dir || @@ -126,7 +122,7 @@ class Gem::Uninstaller remove_all list elsif list.size > 1 - gem_names = list.map(&:full_name) + gem_names = list.map(&:full_name_with_location) gem_names << "All versions" say @@ -147,7 +143,9 @@ class Gem::Uninstaller ## # Uninstalls gem +spec+ - def uninstall_gem(spec) + def uninstall_gem(stub) + spec = stub.to_spec + @spec = spec unless dependencies_ok? spec @@ -165,6 +163,8 @@ class Gem::Uninstaller remove_plugins @spec remove @spec + specification_record.remove_spec(stub) + regenerate_plugins Gem.post_uninstall_hooks.each do |hook| @@ -178,7 +178,7 @@ class Gem::Uninstaller # Removes installed executables and batch files (windows only) for +spec+. def remove_executables(spec) - return if spec.executables.empty? + return if spec.executables.empty? || default_spec_matches?(spec) executables = spec.executables.clone @@ -275,8 +275,6 @@ class Gem::Uninstaller safe_delete { FileUtils.rm_r gemspec } announce_deletion_of(spec) - - Gem::Specification.reset end ## @@ -292,7 +290,6 @@ class Gem::Uninstaller # Regenerates plugin wrappers after removal. def regenerate_plugins - specification_record = @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record latest = specification_record.latest_spec_for(@spec.name) return if latest.nil? @@ -381,6 +378,10 @@ class Gem::Uninstaller private + def specification_record + @specification_record ||= @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record + end + def announce_deletion_of(spec) name = spec.full_name say "Successfully uninstalled #{name}" diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb index 128becc1ce..af86c63ef7 100644 --- a/lib/rubygems/yaml_serializer.rb +++ b/lib/rubygems/yaml_serializer.rb @@ -60,7 +60,6 @@ module Gem indent, key, quote, val = match.captures val = strip_comment(val) - convert_to_backward_compatible_key!(key) depth = indent.size / 2 if quote.empty? && val.empty? new_hash = {} @@ -92,14 +91,8 @@ module Gem end end - # for settings' keys - def convert_to_backward_compatible_key!(key) - key << "/" if /https?:/i.match?(key) && !%r{/\Z}.match?(key) - key.gsub!(".", "__") - end - class << self - private :dump_hash, :convert_to_backward_compatible_key! + private :dump_hash end end end diff --git a/spec/bundler/bundler/bundler_spec.rb b/spec/bundler/bundler/bundler_spec.rb index 6a2e435e54..2c8453da4d 100644 --- a/spec/bundler/bundler/bundler_spec.rb +++ b/spec/bundler/bundler/bundler_spec.rb @@ -227,14 +227,14 @@ RSpec.describe Bundler do describe "#mkdir_p" do it "creates a folder at the given path" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G allow(Bundler).to receive(:root).and_return(bundled_app) - Bundler.mkdir_p(bundled_app.join("foo", "bar")) - expect(bundled_app.join("foo", "bar")).to exist + Bundler.mkdir_p(bundled_app("foo", "bar")) + expect(bundled_app("foo", "bar")).to exist end end diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index c71fc8e9e7..b2cc1ccfef 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -101,30 +101,30 @@ RSpec.describe "bundle executable" do context "when ENV['BUNDLE_GEMFILE'] is set to an empty string" do it "ignores it" do gemfile bundled_app_gemfile, <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle :install, env: { "BUNDLE_GEMFILE" => "" } - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end context "with --verbose" do it "prints the running command" do - gemfile "source \"#{file_uri_for(gem_repo1)}\"" + gemfile "source 'https://gem.repo1'" bundle "info bundler", verbose: true expect(out).to start_with("Running `bundle info bundler --verbose` with bundler #{Bundler::VERSION}") end it "doesn't print defaults" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"", verbose: true + install_gemfile "source 'https://gem.repo1'", verbose: true expect(out).to start_with("Running `bundle install --verbose` with bundler #{Bundler::VERSION}") end it "doesn't print defaults" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"", verbose: true + install_gemfile "source 'https://gem.repo1'", verbose: true expect(out).to start_with("Running `bundle install --verbose` with bundler #{Bundler::VERSION}") end end @@ -138,8 +138,8 @@ RSpec.describe "bundle executable" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", '0.9.1' + source "https://gem.repo1" + gem "myrack", '0.9.1' G end @@ -149,8 +149,8 @@ RSpec.describe "bundle executable" do it "prints a message when there are outdated gems" do run_command - expect(out).to include("Gem Current Latest Requested Groups") - expect(out).to include("rack 0.9.1 1.0.0 = 0.9.1 default") + expect(out).to include("Gem Current Latest Requested Groups") + expect(out).to include("myrack 0.9.1 1.0.0 = 0.9.1 default") end end @@ -160,7 +160,7 @@ RSpec.describe "bundle executable" do it "prints a message when there are outdated gems" do run_command - expect(out).to include("rack (newest 1.0.0, installed 0.9.1, requested = 0.9.1)") + expect(out).to include("myrack (newest 1.0.0, installed 0.9.1, requested = 0.9.1)") end end @@ -170,7 +170,7 @@ RSpec.describe "bundle executable" do it "prints a simplified message when there are outdated gems" do run_command - expect(out).to include("rack (newest 1.0.0, installed 0.9.1, requested = 0.9.1)") + expect(out).to include("myrack (newest 1.0.0, installed 0.9.1, requested = 0.9.1)") end end end diff --git a/spec/bundler/bundler/compact_index_client/parser_spec.rb b/spec/bundler/bundler/compact_index_client/parser_spec.rb new file mode 100644 index 0000000000..1f6b9e593b --- /dev/null +++ b/spec/bundler/bundler/compact_index_client/parser_spec.rb @@ -0,0 +1,237 @@ +# frozen_string_literal: true + +require "bundler/compact_index_client" +require "bundler/compact_index_client/parser" + +TestCompactIndexClient = Struct.new(:names, :versions, :info_data) do + # Requiring the checksum to match the input data helps ensure + # that we are parsing the correct checksum from the versions file + def info(name, checksum) + info_data.dig(name, checksum) + end + + def set_info_data(name, value) + info_data[name] = value + end +end + +RSpec.describe Bundler::CompactIndexClient::Parser do + subject(:parser) { described_class.new(compact_index) } + + let(:compact_index) { TestCompactIndexClient.new(names, versions, info_data) } + let(:names) { "a\nb\nc\n" } + let(:versions) { <<~VERSIONS.dup } + created_at: 2024-05-01T00:00:04Z + --- + a 1.0.0,1.0.1,1.1.0 aaa111 + b 2.0.0,2.0.0-java bbb222 + c 3.0.0,3.0.3,3.3.3 ccc333 + c -3.0.3 ccc333yanked + VERSIONS + let(:info_data) do + { + "a" => { "aaa111" => a_info }, + "b" => { "bbb222" => b_info }, + "c" => { "ccc333yanked" => c_info }, + } + end + let(:a_info) { <<~INFO.dup } + --- + 1.0.0 |checksum:aaa1,ruby:>= 3.0.0,rubygems:>= 3.2.3 + 1.0.1 |checksum:aaa2,ruby:>= 3.0.0,rubygems:>= 3.2.3 + 1.1.0 |checksum:aaa3,ruby:>= 3.0.0,rubygems:>= 3.2.3 + INFO + let(:b_info) { <<~INFO } + 2.0.0 a:~> 1.0&<= 3.0|checksum:bbb1 + 2.0.0-java a:~> 1.0&<= 3.0|checksum:bbb2 + INFO + let(:c_info) { <<~INFO } + 3.0.0 a:= 1.0.0,b:~> 2.0|checksum:ccc1,ruby:>= 2.7.0,rubygems:>= 3.0.0 + 3.3.3 a:>= 1.1.0,b:~> 2.0|checksum:ccc3,ruby:>= 3.0.0,rubygems:>= 3.2.3 + INFO + + describe "#available?" do + it "returns true versions are available" do + expect(parser).to be_available + end + + it "returns true when versions has only one gem" do + compact_index.versions = +"a 1.0.0 aaa1\n" + expect(parser).to be_available + end + + it "returns true when versions has a gem and a header" do + compact_index.versions = +"---\na 1.0.0 aaa1\n" + expect(parser).to be_available + end + + it "returns true when versions has a gem and a header with header data" do + compact_index.versions = +"created_at: 2024-05-01T00:00:04Z\n---\na 1.0.0 aaa1\n" + expect(parser).to be_available + end + + it "returns false when versions has only the header" do + compact_index.versions = +"---\n" + expect(parser).not_to be_available + end + + it "returns false when versions has only the header with header data" do + compact_index.versions = +"created_at: 2024-05-01T00:00:04Z\n---\n" + expect(parser).not_to be_available + end + + it "returns false when versions index is not available" do + compact_index.versions = nil + expect(parser).not_to be_available + end + + it "returns false when versions is empty" do + compact_index.versions = +"" + expect(parser).not_to be_available + end + end + + describe "#names" do + it "returns the names" do + expect(parser.names).to eq(%w[a b c]) + end + + it "returns an empty array when names is empty" do + compact_index.names = "" + expect(parser.names).to eq([]) + end + + it "returns an empty array when names is not readable" do + compact_index.names = nil + expect(parser.names).to eq([]) + end + end + + describe "#versions" do + it "returns the versions" do + expect(parser.versions).to eq( + "a" => [ + ["a", "1.0.0"], + ["a", "1.0.1"], + ["a", "1.1.0"], + ], + "b" => [ + ["b", "2.0.0"], + ["b", "2.0.0", "java"], + ], + "c" => [ + ["c", "3.0.0"], + ["c", "3.3.3"], + ], + ) + end + + it "returns an empty hash when versions is empty" do + compact_index.versions = "" + expect(parser.versions).to eq({}) + end + + it "returns an empty hash when versions is not readable" do + compact_index.versions = nil + expect(parser.versions).to eq({}) + end + end + + describe "#info" do + let(:a_result) do + [ + [ + "a", + "1.0.0", + nil, + [], + [["checksum", ["aaa1"]], ["ruby", [">= 3.0.0"]], ["rubygems", [">= 3.2.3"]]], + ], + [ + "a", + "1.0.1", + nil, + [], + [["checksum", ["aaa2"]], ["ruby", [">= 3.0.0"]], ["rubygems", [">= 3.2.3"]]], + ], + [ + "a", + "1.1.0", + nil, + [], + [["checksum", ["aaa3"]], ["ruby", [">= 3.0.0"]], ["rubygems", [">= 3.2.3"]]], + ], + ] + end + let(:b_result) do + [ + [ + "b", + "2.0.0", + nil, + [["a", ["~> 1.0", "<= 3.0"]]], + [["checksum", ["bbb1"]]], + ], + [ + "b", + "2.0.0", + "java", + [["a", ["~> 1.0", "<= 3.0"]]], + [["checksum", ["bbb2"]]], + ], + ] + end + let(:c_result) do + [ + [ + "c", + "3.0.0", + nil, + [["a", ["= 1.0.0"]], ["b", ["~> 2.0"]]], + [["checksum", ["ccc1"]], ["ruby", [">= 2.7.0"]], ["rubygems", [">= 3.0.0"]]], + ], + [ + "c", + "3.3.3", + nil, + [["a", [">= 1.1.0"]], ["b", ["~> 2.0"]]], + [["checksum", ["ccc3"]], ["ruby", [">= 3.0.0"]], ["rubygems", [">= 3.2.3"]]], + ], + ] + end + + it "returns the info for example gem 'a' which has no deps" do + expect(parser.info("a")).to eq(a_result) + end + + it "returns the info for example gem 'b' which has platform and compound deps" do + expect(parser.info("b")).to eq(b_result) + end + + it "returns the info for example gem 'c' which has deps and yanked version (requires use of correct info checksum)" do + expect(parser.info("c")).to eq(c_result) + end + + it "returns an empty array when the info is empty" do + compact_index.set_info_data("a", {}) + expect(parser.info("a")).to eq([]) + end + + it "returns an empty array when the info is not readable" do + expect(parser.info("d")).to eq([]) + end + + it "handles empty lines in the versions file (Artifactory bug that they have yet to fix)" do + compact_index.versions = +<<~VERSIONS + created_at: 2024-05-01T00:00:04Z + --- + a 1.0.0,1.0.1,1.1.0 aaa111 + b 2.0.0,2.0.0-java bbb222 + + c 3.0.0,3.0.3,3.3.3 ccc333 + c -3.0.3 ccc333yanked + VERSIONS + expect(parser.info("a")).to eq(a_result) + end + end +end diff --git a/spec/bundler/bundler/definition_spec.rb b/spec/bundler/bundler/definition_spec.rb index 28c04e0860..28d770daa0 100644 --- a/spec/bundler/bundler/definition_spec.rb +++ b/spec/bundler/bundler/definition_spec.rb @@ -45,17 +45,17 @@ RSpec.describe Bundler::Definition do build_lib "foo", "1.0", path: lib_path("foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "1.0" + s.add_dependency "myrack", "1.0" end checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" - c.checksum gem_repo1, "rack", "1.0.0" + c.checksum gem_repo1, "myrack", "1.0.0" end bundle :install, env: { "DEBUG" => "1" } @@ -66,12 +66,12 @@ RSpec.describe Bundler::Definition do remote: #{lib_path("foo")} specs: foo (1.0) - rack (= 1.0) + myrack (= 1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} @@ -91,7 +91,7 @@ RSpec.describe Bundler::Definition do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "ffi" G @@ -104,17 +104,17 @@ RSpec.describe Bundler::Definition do it "for a path gem with deps and no changes" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "1.0" + s.add_dependency "myrack", "1.0" s.add_development_dependency "net-ssh", "1.0" end checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" - c.checksum gem_repo1, "rack", "1.0.0" + c.checksum gem_repo1, "myrack", "1.0.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G @@ -123,12 +123,12 @@ RSpec.describe Bundler::Definition do remote: #{lib_path("foo")} specs: foo (1.0) - rack (= 1.0) + myrack (= 1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} @@ -154,7 +154,7 @@ RSpec.describe Bundler::Definition do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "only_java", platform: :jruby G @@ -164,7 +164,7 @@ RSpec.describe Bundler::Definition do expect(out).to match(/using resolution from the lockfile/) expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: only_java (1.1-java) @@ -185,7 +185,7 @@ RSpec.describe Bundler::Definition do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G @@ -194,7 +194,7 @@ RSpec.describe Bundler::Definition do expect(out).to match(/using resolution from the lockfile/) expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: foo (1.0) @@ -215,13 +215,13 @@ RSpec.describe Bundler::Definition do context "eager unlock" do let(:source_list) do Bundler::SourceList.new.tap do |source_list| - source_list.add_global_rubygems_remote(file_uri_for(gem_repo4)) + source_list.add_global_rubygems_remote("https://gem.repo4") end end before do gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'isolated_owner' gem 'shared_owner_a' @@ -230,7 +230,7 @@ RSpec.describe Bundler::Definition do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: isolated_dep (2.0.1) isolated_owner (1.0.1) diff --git a/spec/bundler/bundler/dsl_spec.rb b/spec/bundler/bundler/dsl_spec.rb index 3c3b6c26c3..7b6d080593 100644 --- a/spec/bundler/bundler/dsl_spec.rb +++ b/spec/bundler/bundler/dsl_spec.rb @@ -175,7 +175,7 @@ RSpec.describe Bundler::Dsl do it "handles syntax errors with a useful message" do expect(Bundler).to receive(:read_file).with(source_root.join("Gemfile").to_s).and_return("}") expect { subject.eval_gemfile("Gemfile") }. - to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./) + to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'|.+?unexpected '}', ignoring it\n). Bundler cannot continue./m) end it "distinguishes syntax errors from evaluation errors" do @@ -322,7 +322,7 @@ RSpec.describe Bundler::Dsl do it "will raise a Bundler::GemfileError" do gemfile "gem 'foo', :path => /unquoted/string/syntax/error" expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }. - to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`:( compile error -)? unknown regexp options - trg.+ Bundler cannot continue./) + to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`:( compile error -)?.+?unknown regexp options - trg.+ Bundler cannot continue./m) end end diff --git a/spec/bundler/bundler/env_spec.rb b/spec/bundler/bundler/env_spec.rb index 7997cb0c40..e0ab0a45e3 100644 --- a/spec/bundler/bundler/env_spec.rb +++ b/spec/bundler/bundler/env_spec.rb @@ -70,16 +70,16 @@ RSpec.describe Bundler::Env do context "when there is a Gemfile and a lockfile and print_gemfile is true" do before do - gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem 'rack', '1.0.0'" + gemfile "source 'https://gem.repo1'; gem 'myrack', '1.0.0'" lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) DEPENDENCIES - rack + myrack BUNDLED WITH 1.10.0 @@ -92,12 +92,12 @@ RSpec.describe Bundler::Env do it "prints the Gemfile" do expect(output).to include("Gemfile") - expect(output).to include("'rack', '1.0.0'") + expect(output).to include("'myrack', '1.0.0'") end it "prints the lockfile" do expect(output).to include("Gemfile.lock") - expect(output).to include("rack (1.0.0)") + expect(output).to include("myrack (1.0.0)") end end @@ -148,9 +148,9 @@ RSpec.describe Bundler::Env do end before do - gemfile("source \"#{file_uri_for(gem_repo1)}\"; gemspec") + gemfile("source 'https://gem.repo1'; gemspec") - File.open(bundled_app.join("foo.gemspec"), "wb") do |f| + File.open(bundled_app("foo.gemspec"), "wb") do |f| f.write(gemspec) end @@ -167,10 +167,10 @@ RSpec.describe Bundler::Env do context "when eval_gemfile is used" do it "prints all gemfiles" do - create_file bundled_app("other/Gemfile-other"), "gem 'rack'" - create_file bundled_app("other/Gemfile"), "eval_gemfile 'Gemfile-other'" - create_file bundled_app("Gemfile-alt"), <<-G - source "#{file_uri_for(gem_repo1)}" + gemfile bundled_app("other/Gemfile-other"), "gem 'myrack'" + gemfile bundled_app("other/Gemfile"), "eval_gemfile 'Gemfile-other'" + gemfile bundled_app("Gemfile-alt"), <<-G + source "https://gem.repo1" eval_gemfile "other/Gemfile" G gemfile "eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}" @@ -190,7 +190,7 @@ RSpec.describe Bundler::Env do ### Gemfile-alt ```ruby - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "other/Gemfile" ``` @@ -203,7 +203,7 @@ RSpec.describe Bundler::Env do ### other/Gemfile-other ```ruby - gem 'rack' + gem 'myrack' ``` ### Gemfile.lock diff --git a/spec/bundler/bundler/fetcher/compact_index_spec.rb b/spec/bundler/bundler/fetcher/compact_index_spec.rb index a988171f34..aa536673d9 100644 --- a/spec/bundler/bundler/fetcher/compact_index_spec.rb +++ b/spec/bundler/bundler/fetcher/compact_index_spec.rb @@ -4,14 +4,18 @@ require "bundler/compact_index_client" RSpec.describe Bundler::Fetcher::CompactIndex do - let(:downloader) { double(:downloader) } + let(:response) { double(:response) } + let(:downloader) { double(:downloader, fetch: response) } let(:display_uri) { Gem::URI("http://sampleuri.com") } let(:remote) { double(:remote, cache_slug: "lsjdf", uri: display_uri) } let(:gem_remote_fetcher) { nil } let(:compact_index) { described_class.new(downloader, remote, display_uri, gem_remote_fetcher) } + let(:compact_index_client) { double(:compact_index_client, available?: true, info: [["lskdjf", "1", nil, [], []]]) } before do + allow(response).to receive(:is_a?).with(Gem::Net::HTTPNotModified).and_return(true) allow(compact_index).to receive(:log_specs) {} + allow(compact_index).to receive(:compact_index_client).and_return(compact_index_client) end describe "#specs_for_names" do @@ -32,11 +36,6 @@ RSpec.describe Bundler::Fetcher::CompactIndex do end describe "#available?" do - before do - allow(compact_index).to receive(:compact_index_client). - and_return(double(:compact_index_client, update_and_parse_checksums!: true)) - end - it "returns true" do expect(compact_index).to be_available end diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb index cda2ef31de..255019f40a 100644 --- a/spec/bundler/bundler/friendly_errors_spec.rb +++ b/spec/bundler/bundler/friendly_errors_spec.rb @@ -18,8 +18,8 @@ RSpec.describe Bundler, "friendly errors" do it "reports a relevant friendly error message" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :install, env: { "DEBUG" => "true" } diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb index 940e5df9de..94f66537d3 100644 --- a/spec/bundler/bundler/gem_helper_spec.rb +++ b/spec/bundler/bundler/gem_helper_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Bundler::GemHelper do before(:each) do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__LINTER" => "false", "BUNDLE_GEM__CI" => "false", "BUNDLE_GEM__CHANGELOG" => "false" - sys_exec("git config --global init.defaultBranch main") + git("config --global init.defaultBranch main") bundle "gem #{app_name}" prepare_gemspec(app_gemspec_path) end @@ -253,11 +253,11 @@ RSpec.describe Bundler::GemHelper do end before do - sys_exec("git init", dir: app_path) - sys_exec("git config user.email \"[email protected]\"", dir: app_path) - sys_exec("git config user.name \"name\"", dir: app_path) - sys_exec("git config commit.gpgsign false", dir: app_path) - sys_exec("git config push.default simple", dir: app_path) + git("init", app_path) + git("config user.email \"[email protected]\"", app_path) + git("config user.name \"name\"", app_path) + git("config commit.gpgsign false", app_path) + git("config push.default simple", app_path) # silence messages allow(Bundler.ui).to receive(:confirm) @@ -271,13 +271,13 @@ RSpec.describe Bundler::GemHelper do end it "when there are uncommitted files" do - sys_exec("git add .", dir: app_path) + git("add .", app_path) expect { Rake.application["release"].invoke }. to raise_error("There are files that need to be committed first.") end it "when there is no git remote" do - sys_exec("git commit -a -m \"initial commit\"", dir: app_path) + git("commit -a -m \"initial commit\"", app_path) expect { Rake.application["release"].invoke }.to raise_error(RuntimeError) end end @@ -286,8 +286,8 @@ RSpec.describe Bundler::GemHelper do let(:repo) { build_git("foo", bare: true) } before do - sys_exec("git remote add origin #{file_uri_for(repo.path)}", dir: app_path) - sys_exec('git commit -a -m "initial commit"', dir: app_path) + git("remote add origin #{repo.path}", app_path) + git('commit -a -m "initial commit"', app_path) end context "on releasing" do @@ -296,7 +296,7 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message "Tagged v#{app_version}." mock_confirm_message "Pushed git commits and release tag." - sys_exec("git push -u origin main", dir: app_path) + git("push -u origin main", app_path) end it "calls rubygem_push with proper arguments" do @@ -314,8 +314,8 @@ RSpec.describe Bundler::GemHelper do it "also works when releasing from an ambiguous reference" do # Create a branch with the same name as the tag - sys_exec("git checkout -b v#{app_version}", dir: app_path) - sys_exec("git push -u origin v#{app_version}", dir: app_path) + git("checkout -b v#{app_version}", app_path) + git("push -u origin v#{app_version}", app_path) expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) @@ -323,7 +323,7 @@ RSpec.describe Bundler::GemHelper do end it "also works with releasing from a branch not yet pushed" do - sys_exec("git checkout -b module_function", dir: app_path) + git("checkout -b module_function", app_path) expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) @@ -337,7 +337,7 @@ RSpec.describe Bundler::GemHelper do mock_build_message app_name, app_version mock_confirm_message "Pushed git commits and release tag." - sys_exec("git push -u origin main", dir: app_path) + git("push -u origin main", app_path) expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) end @@ -353,7 +353,7 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message "Tag v#{app_version} has already been created." expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) - sys_exec("git tag -a -m \"Version #{app_version}\" v#{app_version}", dir: app_path) + git("tag -a -m \"Version #{app_version}\" v#{app_version}", app_path) Rake.application["release"].invoke end @@ -374,10 +374,10 @@ RSpec.describe Bundler::GemHelper do end before do - sys_exec("git init", dir: app_path) - sys_exec("git config user.email \"[email protected]\"", dir: app_path) - sys_exec("git config user.name \"name\"", dir: app_path) - sys_exec("git config push.gpgsign simple", dir: app_path) + git("init", app_path) + git("config user.email \"[email protected]\"", app_path) + git("config user.name \"name\"", app_path) + git("config push.gpgsign simple", app_path) # silence messages allow(Bundler.ui).to receive(:confirm) diff --git a/spec/bundler/bundler/installer/gem_installer_spec.rb b/spec/bundler/bundler/installer/gem_installer_spec.rb index 4b6a07f344..ea506c36c8 100644 --- a/spec/bundler/bundler/installer/gem_installer_spec.rb +++ b/spec/bundler/bundler/installer/gem_installer_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Bundler::GemInstaller do it "invokes install method with empty build_args" do allow(spec_source).to receive(:install).with( spec, - { force: false, ensure_builtin_gems_cached: false, build_args: [], previous_spec: nil } + { force: false, build_args: [], previous_spec: nil } ) subject.install_from_spec end @@ -28,7 +28,7 @@ RSpec.describe Bundler::GemInstaller do allow(Bundler.settings).to receive(:[]).with("build.dummy").and_return("--with-dummy-config=dummy") expect(spec_source).to receive(:install).with( spec, - { force: false, ensure_builtin_gems_cached: false, build_args: ["--with-dummy-config=dummy"], previous_spec: nil } + { force: false, build_args: ["--with-dummy-config=dummy"], previous_spec: nil } ) subject.install_from_spec end @@ -42,7 +42,7 @@ RSpec.describe Bundler::GemInstaller do allow(Bundler.settings).to receive(:[]).with("build.dummy").and_return("--with-dummy-config=dummy --with-another-dummy-config") expect(spec_source).to receive(:install).with( spec, - { force: false, ensure_builtin_gems_cached: false, build_args: ["--with-dummy-config=dummy", "--with-another-dummy-config"], previous_spec: nil } + { force: false, build_args: ["--with-dummy-config=dummy", "--with-another-dummy-config"], previous_spec: nil } ) subject.install_from_spec end diff --git a/spec/bundler/bundler/plugin/index_spec.rb b/spec/bundler/bundler/plugin/index_spec.rb index 5a7047459f..e1f10a0db7 100644 --- a/spec/bundler/bundler/plugin/index_spec.rb +++ b/spec/bundler/bundler/plugin/index_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Bundler::Plugin::Index do before do allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) - gemfile "source \"#{file_uri_for(gem_repo1)}\"" + gemfile "source 'https://gem.repo1'" path = lib_path(plugin_name) index.register_plugin("new-plugin", path.to_s, [path.join("lib").to_s], commands, sources, hooks) end diff --git a/spec/bundler/bundler/plugin/installer_spec.rb b/spec/bundler/bundler/plugin/installer_spec.rb index ed40029f5a..8e1879395a 100644 --- a/spec/bundler/bundler/plugin/installer_spec.rb +++ b/spec/bundler/bundler/plugin/installer_spec.rb @@ -57,7 +57,7 @@ RSpec.describe Bundler::Plugin::Installer do end let(:result) do - installer.install(["ga-plugin"], git: file_uri_for(lib_path("ga-plugin"))) + installer.install(["ga-plugin"], git: lib_path("ga-plugin").to_s) end it "returns the installed spec after installing" do diff --git a/spec/bundler/bundler/plugin_spec.rb b/spec/bundler/bundler/plugin_spec.rb index f41b4eff3a..3ac7b251a3 100644 --- a/spec/bundler/bundler/plugin_spec.rb +++ b/spec/bundler/bundler/plugin_spec.rb @@ -247,7 +247,7 @@ RSpec.describe Bundler::Plugin do end it "returns plugin dir in app .bundle path" do - expect(subject.root).to eq(bundled_app.join(".bundle/plugin")) + expect(subject.root).to eq(bundled_app(".bundle/plugin")) end end @@ -257,7 +257,7 @@ RSpec.describe Bundler::Plugin do end it "returns plugin dir in global bundle path" do - expect(subject.root).to eq(home.join(".bundle/plugin")) + expect(subject.root).to eq(home(".bundle/plugin")) end end end diff --git a/spec/bundler/bundler/resolver/candidate_spec.rb b/spec/bundler/bundler/resolver/candidate_spec.rb index f7b378d32b..aefad3316e 100644 --- a/spec/bundler/bundler/resolver/candidate_spec.rb +++ b/spec/bundler/bundler/resolver/candidate_spec.rb @@ -2,20 +2,19 @@ RSpec.describe Bundler::Resolver::Candidate do it "compares fine" do - version1 = described_class.new("1.12.5", specs: [Gem::Specification.new("foo", "1.12.5") {|s| s.platform = Gem::Platform::RUBY }]) - version2 = described_class.new("1.12.5") # passing no specs creates a platform specific candidate, so sorts higher + version1 = described_class.new("1.12.5", priority: -1) + version2 = described_class.new("1.12.5", priority: 1) - expect(version2 >= version1).to be true + expect(version2 > version1).to be true - expect(version1.generic! == version2.generic!).to be true - expect(version1.platform_specific! == version2.platform_specific!).to be true + version1 = described_class.new("1.12.5") + version2 = described_class.new("1.12.5") - expect(version1.platform_specific! >= version2.generic!).to be true - expect(version2.platform_specific! >= version1.generic!).to be true + expect(version2 == version1).to be true - version1 = described_class.new("1.12.5", specs: [Gem::Specification.new("foo", "1.12.5") {|s| s.platform = Gem::Platform::RUBY }]) - version2 = described_class.new("1.12.5", specs: [Gem::Specification.new("foo", "1.12.5") {|s| s.platform = Gem::Platform::X64_LINUX }]) + version1 = described_class.new("1.12.5", priority: 1) + version2 = described_class.new("1.12.5", priority: -1) - expect(version2 >= version1).to be true + expect(version2 < version1).to be true end end diff --git a/spec/bundler/bundler/rubygems_integration_spec.rb b/spec/bundler/bundler/rubygems_integration_spec.rb index b6bda9f43e..81859d10f2 100644 --- a/spec/bundler/bundler/rubygems_integration_spec.rb +++ b/spec/bundler/bundler/rubygems_integration_spec.rb @@ -11,14 +11,14 @@ RSpec.describe Bundler::RubygemsIntegration do end subject { Bundler.rubygems.validate(spec) } - it "validates with packaging mode disabled" do - expect(spec).to receive(:validate).with(false) + it "validates for resolution" do + expect(spec).to receive(:validate_for_resolution) subject end context "with an invalid spec" do before do - expect(spec).to receive(:validate).with(false). + expect(spec).to receive(:validate_for_resolution). and_raise(Gem::InvalidSpecificationException.new("TODO is not an author")) end diff --git a/spec/bundler/bundler/settings_spec.rb b/spec/bundler/bundler/settings_spec.rb index 634e0faf91..b7db548cf9 100644 --- a/spec/bundler/bundler/settings_spec.rb +++ b/spec/bundler/bundler/settings_spec.rb @@ -6,12 +6,18 @@ RSpec.describe Bundler::Settings do subject(:settings) { described_class.new(bundled_app) } describe "#set_local" do - context "when the local config file is not found" do + context "root is nil" do subject(:settings) { described_class.new(nil) } - it "raises a GemfileNotFound error with explanation" do - expect { subject.set_local("foo", "bar") }. - to raise_error(Bundler::GemfileNotFound, "Could not locate Gemfile") + before do + allow(Pathname).to receive(:new).and_call_original + allow(Pathname).to receive(:new).with(".bundle").and_return home(".bundle") + end + + it "works" do + subject.set_local("foo", "bar") + + expect(subject["foo"]).to eq("bar") end end end @@ -310,8 +316,8 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow let(:settings) { described_class.new(bundled_app(".bundle")) } it "converts older keys without double underscore" do - config("BUNDLE_MY__PERSONAL.RACK" => "~/Work/git/rack") - expect(settings["my.personal.rack"]).to eq("~/Work/git/rack") + config("BUNDLE_MY__PERSONAL.MYRACK" => "~/Work/git/myrack") + expect(settings["my.personal.myrack"]).to eq("~/Work/git/myrack") end it "converts older keys without trailing slashes and double underscore" do diff --git a/spec/bundler/cache/cache_path_spec.rb b/spec/bundler/cache/cache_path_spec.rb index 12385427b1..d5bd14965b 100644 --- a/spec/bundler/cache/cache_path_spec.rb +++ b/spec/bundler/cache/cache_path_spec.rb @@ -3,15 +3,15 @@ RSpec.describe "bundle package" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end context "with --cache-path" do it "caches gems at given path" do bundle :cache, "cache-path" => "vendor/cache-foo" - expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist end end @@ -19,14 +19,14 @@ RSpec.describe "bundle package" do it "caches gems at given path" do bundle "config set cache_path vendor/cache-foo" bundle :cache - expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist end end context "with absolute --cache-path" do it "caches gems at given path" do - bundle :cache, "cache-path" => "/tmp/cache-foo" - expect(bundled_app("/tmp/cache-foo/rack-1.0.0.gem")).to exist + bundle :cache, "cache-path" => bundled_app("vendor/cache-foo") + expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist end end end diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index abbc2c3cf2..6d430308a0 100644 --- a/spec/bundler/cache/gems_spec.rb +++ b/spec/bundler/cache/gems_spec.rb @@ -4,23 +4,23 @@ RSpec.describe "bundle cache" do shared_examples_for "when there are only gemsources" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G - system_gems "rack-1.0.0", path: path + system_gems "myrack-1.0.0", path: path bundle :cache end it "copies the .gem file to vendor/cache" do - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "uses the cache as a source when installing gems" do build_gem "omg", path: bundled_app("vendor/cache") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "omg" G @@ -31,44 +31,44 @@ RSpec.describe "bundle cache" do system_gems [], path: default_bundle_path bundle "install --local" - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") end it "does not reinstall gems from the cache if they exist on the system" do - build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") end it "does not reinstall gems from the cache if they exist in the bundle" do - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end bundle :install, local: true - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") end it "creates a lockfile" do - cache_gems "rack-1.0.0" + cache_gems "myrack-1.0.0" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "cache" @@ -93,82 +93,94 @@ RSpec.describe "bundle cache" do let(:default_json_version) { ruby "gem 'json'; require 'json'; puts JSON::VERSION" } before :each do - build_repo2 do - build_gem "json", default_json_version - end - build_gem "json", default_json_version, to_system: true, default: true end - it "uses builtin gems when installing to system gems" do - bundle "config set path.system true" - install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true - expect(out).to include("Using json #{default_json_version}") - end + context "when a remote gem is available for caching" do + before do + build_repo2 do + build_gem "json", default_json_version + end + end - it "caches remote and builtin gems" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'json', '#{default_json_version}' - gem 'rack', '1.0.0' - G + it "uses remote gems when installing to system gems" do + bundle "config set path.system true" + install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true + expect(out).to include("Installing json #{default_json_version}") + end - bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist - end + it "caches remote and builtin gems" do + install_gemfile <<-G + source "https://gem.repo2" + gem 'json', '#{default_json_version}' + gem 'myrack', '1.0.0' + G - it "caches builtin gems when cache_all_platforms is set" do - gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "json" - G + bundle :cache + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist + end - bundle "config set cache_all_platforms true" + it "caches builtin gems when cache_all_platforms is set" do + gemfile <<-G + source "https://gem.repo2" + gem "json" + G - bundle :cache - expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist - end + bundle "config set cache_all_platforms true" - it "doesn't make remote request after caching the gem" do - build_gem "builtin_gem_2", "1.0.2", path: bundled_app("vendor/cache") do |s| - s.summary = "This builtin_gem is bundled with Ruby" + bundle :cache + expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist end - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'builtin_gem_2', '1.0.2' - G + it "doesn't make remote request after caching the gem" do + build_gem "builtin_gem_2", "1.0.2", path: bundled_app("vendor/cache") do |s| + s.summary = "This builtin_gem is bundled with Ruby" + end - bundle "install --local" - expect(the_bundle).to include_gems("builtin_gem_2 1.0.2") + install_gemfile <<-G + source "https://gem.repo2" + gem 'builtin_gem_2', '1.0.2' + G + + bundle "install --local" + expect(the_bundle).to include_gems("builtin_gem_2 1.0.2") + end end - it "errors if the builtin gem isn't available to cache" do - bundle "config set path.system true" + context "when a remote gem is not available for caching" do + it "uses builtin gems when installing to system gems" do + bundle "config set path.system true" + install_gemfile %(source "https://gem.repo1"; gem 'json', '#{default_json_version}'), verbose: true + expect(out).to include("Using json #{default_json_version}") + end - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'json', '#{default_json_version}' - G + it "errors when explicitly caching" do + bundle "config set path.system true" - bundle :cache, raise_on_error: false - expect(exitstatus).to_not eq(0) - expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached") + install_gemfile <<-G + source "https://gem.repo1" + gem 'json', '#{default_json_version}' + G + + bundle :cache, raise_on_error: false + expect(exitstatus).to_not eq(0) + expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached") + end end end describe "when there are also git sources" do before do build_git "foo" - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem 'foo' end - gem 'rack' + gem 'myrack' G end @@ -178,7 +190,7 @@ RSpec.describe "bundle cache" do system_gems [] bundle "install --local" - expect(the_bundle).to include_gems("rack 1.0.0", "foo 1.0") + expect(the_bundle).to include_gems("myrack 1.0.0", "foo 1.0") end it "should not explode if the lockfile is not present" do @@ -194,38 +206,38 @@ RSpec.describe "bundle cache" do before :each do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" gem "actionpack" G bundle :cache - expect(cached_gem("rack-1.0.0")).to exist + expect(cached_gem("myrack-1.0.0")).to exist expect(cached_gem("actionpack-2.3.2")).to exist expect(cached_gem("activesupport-2.3.2")).to exist end it "re-caches during install" do - cached_gem("rack-1.0.0").rmtree + cached_gem("myrack-1.0.0").rmtree bundle :install expect(out).to include("Updating files in vendor/cache") - expect(cached_gem("rack-1.0.0")).to exist + expect(cached_gem("myrack-1.0.0")).to exist end it "adds and removes when gems are updated" do update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end bundle "update", all: true - expect(cached_gem("rack-1.2")).to exist - expect(cached_gem("rack-1.0.0")).not_to exist + expect(cached_gem("myrack-1.2")).to exist + expect(cached_gem("myrack-1.0.0")).not_to exist end it "adds new gems and dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" G expect(cached_gem("rails-2.3.2")).to exist @@ -234,23 +246,23 @@ RSpec.describe "bundle cache" do it "removes .gems for removed gems and dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G - expect(cached_gem("rack-1.0.0")).to exist + expect(cached_gem("myrack-1.0.0")).to exist expect(cached_gem("actionpack-2.3.2")).not_to exist expect(cached_gem("activesupport-2.3.2")).not_to exist end it "removes .gems when gem changes to git source" do - build_git "rack" + build_git "myrack" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", :git => "#{lib_path("rack-1.0")}" + source "https://gem.repo2" + gem "myrack", :git => "#{lib_path("myrack-1.0")}" gem "actionpack" G - expect(cached_gem("rack-1.0.0")).not_to exist + expect(cached_gem("myrack-1.0.0")).not_to exist expect(cached_gem("actionpack-2.3.2")).to exist expect(cached_gem("activesupport-2.3.2")).to exist end @@ -258,7 +270,7 @@ RSpec.describe "bundle cache" do it "doesn't remove gems that are for another platform" do simulate_platform "java" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G @@ -268,7 +280,7 @@ RSpec.describe "bundle cache" do simulate_new_machine install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G @@ -276,62 +288,78 @@ RSpec.describe "bundle cache" do expect(cached_gem("platform_specific-1.0-java")).to exist end - it "doesn't remove gems with mismatched :rubygems_version or :date" do - cached_gem("rack-1.0.0").rmtree - build_gem "rack", "1.0.0", - path: bundled_app("vendor/cache"), + it "doesn't remove gems cached gems that don't match their remote counterparts, but also refuses to install and prints an error" do + cached_myrack = cached_gem("myrack-1.0.0") + cached_myrack.rmtree + build_gem "myrack", "1.0.0", + path: cached_myrack.parent, rubygems_version: "1.3.2" - # This test is only really valid if the checksum isn't saved. It otherwise can't be the same gem. Tested below. - bundled_app_lock.write remove_checksums_from_lockfile(bundled_app_lock.read, "rack (1.0.0)") + simulate_new_machine - bundle :install - expect(cached_gem("rack-1.0.0")).to exist + bundle :install, raise_on_error: false + + expect(err).to eq <<~E.strip + Bundler found mismatched checksums. This is a potential security risk. + #{checksum_to_lock(gem_repo2, "myrack", "1.0.0")} + from the API at https://gem.repo2/ + #{checksum_from_package(cached_myrack, "myrack", "1.0.0")} + from the gem at #{cached_myrack} + + If you trust the API at https://gem.repo2/, to resolve this issue you can: + 1. remove the gem at #{cached_myrack} + 2. run `bundle install` + + To ignore checksum security warnings, disable checksum validation with + `bundle config set --local disable_checksum_validation true` + E + + expect(cached_gem("myrack-1.0.0")).to exist end - it "raises an error when the gem is altered and produces a different checksum" do - cached_gem("rack-1.0.0").rmtree - build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") + it "raises an error when a cached gem is altered and produces a different checksum than the remote gem" do + cached_gem("myrack-1.0.0").rmtree + build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") checksums = checksums_section do |c| - c.checksum gem_repo1, "rack", "1.0.0" + c.checksum gem_repo1, "myrack", "1.0.0" end simulate_new_machine lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) #{checksums} L bundle :install, raise_on_error: false expect(exitstatus).to eq(37) expect(err).to include("Bundler found mismatched checksums.") - expect(err).to include("1. remove the gem at #{cached_gem("rack-1.0.0")}") + expect(err).to include("1. remove the gem at #{cached_gem("myrack-1.0.0")}") - expect(cached_gem("rack-1.0.0")).to exist - cached_gem("rack-1.0.0").rmtree + expect(cached_gem("myrack-1.0.0")).to exist + cached_gem("myrack-1.0.0").rmtree bundle :install - expect(cached_gem("rack-1.0.0")).to exist + expect(cached_gem("myrack-1.0.0")).to exist end - it "installs a modified gem with a non-matching checksum when checksums is not opted in" do - cached_gem("rack-1.0.0").rmtree - build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") + it "installs a modified gem with a non-matching checksum when the API implementation does not provide checksums" do + cached_gem("myrack-1.0.0").rmtree + build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") simulate_new_machine lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) L - bundle :install - expect(cached_gem("rack-1.0.0")).to exist + bundle :install, artifice: "endpoint", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } + expect(cached_gem("myrack-1.0.0")).to exist end it "handles directories and non .gem files in the cache" do @@ -342,8 +370,8 @@ RSpec.describe "bundle cache" do it "does not say that it is removing gems when it isn't actually doing so" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "cache" bundle "install" @@ -352,8 +380,8 @@ RSpec.describe "bundle cache" do it "does not warn about all if it doesn't have any git/path dependency" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "cache" expect(out).not_to match(/\-\-all/) @@ -364,7 +392,7 @@ RSpec.describe "bundle cache" do path: bundled_app("vendor/cache") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo-bundler" G diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb index 4b3cd4d2eb..81b0fd1d31 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -18,7 +18,7 @@ RSpec.describe "bundle cache with git" do ref = git.ref_for("main", 11) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G @@ -37,7 +37,7 @@ RSpec.describe "bundle cache with git" do ref = git.ref_for("main", 11) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G @@ -57,7 +57,7 @@ RSpec.describe "bundle cache with git" do build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G @@ -75,7 +75,7 @@ RSpec.describe "bundle cache with git" do old_ref = git.ref_for("main", 11) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G @@ -105,7 +105,7 @@ RSpec.describe "bundle cache with git" do old_ref = git.ref_for("main", 11) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G @@ -134,7 +134,7 @@ RSpec.describe "bundle cache with git" do ref = git.ref_for("main", 11) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :main G @@ -164,11 +164,11 @@ RSpec.describe "bundle cache with git" do s.add_dependency "submodule" end - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", dir: lib_path("has_submodule-1.0") - sys_exec "git commit -m \"submodulator\"", dir: lib_path("has_submodule-1.0") + git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0") + git "commit -m \"submodulator\"", lib_path("has_submodule-1.0") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("has_submodule-1.0")}", :submodules => true do gem "has_submodule" end @@ -192,7 +192,7 @@ RSpec.describe "bundle cache with git" do update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") } install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G bundle "config set cache_all true" @@ -207,7 +207,7 @@ RSpec.describe "bundle cache with git" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G bundle "config set cache_all true" @@ -226,7 +226,7 @@ RSpec.describe "bundle cache with git" do ref = git.ref_for("main", 11) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G bundle "config set cache_all true" diff --git a/spec/bundler/cache/path_spec.rb b/spec/bundler/cache/path_spec.rb index 2c8a52617a..966cb6f531 100644 --- a/spec/bundler/cache/path_spec.rb +++ b/spec/bundler/cache/path_spec.rb @@ -5,7 +5,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo", path: bundled_app("lib/foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{bundled_app("lib/foo")}' G @@ -19,7 +19,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -38,7 +38,7 @@ RSpec.describe "bundle cache with path" do build_lib libname, path: libpath install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "#{libname}", :path => '#{libpath}' G @@ -54,7 +54,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -77,7 +77,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -89,7 +89,7 @@ RSpec.describe "bundle cache with path" do build_lib "bar" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :path => '#{lib_path("bar-1.0")}' G @@ -101,7 +101,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -114,7 +114,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -127,7 +127,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -136,7 +136,7 @@ RSpec.describe "bundle cache with path" do build_lib "bar" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' gem "bar", :path => '#{lib_path("bar-1.0")}' G @@ -149,7 +149,7 @@ RSpec.describe "bundle cache with path" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G @@ -158,7 +158,7 @@ RSpec.describe "bundle cache with path" do build_lib "baz" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' gem "baz", :path => '#{lib_path("baz-1.0")}' G diff --git a/spec/bundler/cache/platform_spec.rb b/spec/bundler/cache/platform_spec.rb index 36db954c79..71c0eaee8e 100644 --- a/spec/bundler/cache/platform_spec.rb +++ b/spec/bundler/cache/platform_spec.rb @@ -3,10 +3,10 @@ RSpec.describe "bundle cache with multiple platforms" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platforms :mri, :rbx do - gem "rack", "1.0.0" + gem "myrack", "1.0.0" end platforms :jruby do @@ -16,9 +16,9 @@ RSpec.describe "bundle cache with multiple platforms" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) activesupport (2.3.5) PLATFORMS @@ -26,24 +26,24 @@ RSpec.describe "bundle cache with multiple platforms" do java DEPENDENCIES - rack (1.0.0) + myrack (1.0.0) activesupport (2.3.5) G - cache_gems "rack-1.0.0", "activesupport-2.3.5" + cache_gems "myrack-1.0.0", "activesupport-2.3.5" end it "ensures that a successful bundle install does not delete gems for other platforms" do bundle "install" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/activesupport-2.3.5.gem")).to exist end it "ensures that a successful bundle update does not delete gems for other platforms" do bundle "update", all: true - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/activesupport-2.3.5.gem")).to exist end end diff --git a/spec/bundler/commands/add_spec.rb b/spec/bundler/commands/add_spec.rb index 36e286793b..9eb9c876ca 100644 --- a/spec/bundler/commands/add_spec.rb +++ b/spec/bundler/commands/add_spec.rb @@ -15,7 +15,7 @@ RSpec.describe "bundle add" do build_git "foo", "2.0" gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "weakling", "~> 0.0.1" G end @@ -28,6 +28,15 @@ RSpec.describe "bundle add" do end end + context "when Gemfile is empty, and frozen mode is set" do + it "shows error" do + gemfile 'source "https://gem.repo2"' + bundle "add bar", raise_on_error: false, env: { "BUNDLE_FROZEN" => "true" } + + expect(err).to include("Frozen mode is set, but there's no lockfile") + end + end + describe "without version specified" do it "version requirement becomes ~> major.minor.patch when resolved version is < 1.0" do bundle "add 'bar'" @@ -104,9 +113,9 @@ RSpec.describe "bundle add" do describe "with --source" do it "adds dependency with specified source" do - bundle "add 'foo' --source='#{file_uri_for(gem_repo2)}'" + bundle "add 'foo' --source='https://gem.repo2'" - expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :source => "#{file_uri_for(gem_repo2)}"/) + expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", :source => "https://gem.repo2"}) expect(the_bundle).to include_gems "foo 2.0" end end @@ -152,7 +161,7 @@ RSpec.describe "bundle add" do end describe "with --github" do - it "adds dependency with specified github source", :realworld do + it "adds dependency with specified github source" do bundle "add rake --github=ruby/rake" expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake"}) @@ -160,7 +169,7 @@ RSpec.describe "bundle add" do end describe "with --github and --branch" do - it "adds dependency with specified github source and branch", :realworld do + it "adds dependency with specified github source and branch" do bundle "add rake --github=ruby/rake --branch=master" expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :branch => "master"}) @@ -168,7 +177,7 @@ RSpec.describe "bundle add" do end describe "with --github and --ref" do - it "adds dependency with specified github source and ref", :realworld do + it "adds dependency with specified github source and ref" do bundle "add rake --github=ruby/rake --ref=5c60da8" expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :ref => "5c60da8"}) @@ -207,7 +216,7 @@ RSpec.describe "bundle add" do end describe "with --github and --glob" do - it "adds dependency with specified github source", :realworld do + it "adds dependency with specified github source" do bundle "add rake --github=ruby/rake --glob='./*.gemspec'" expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :glob => "\.\/\*\.gemspec"}) @@ -215,7 +224,7 @@ RSpec.describe "bundle add" do end describe "with --github and --branch --and glob" do - it "adds dependency with specified github source and branch", :realworld do + it "adds dependency with specified github source and branch" do bundle "add rake --github=ruby/rake --branch=master --glob='./*.gemspec'" expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :branch => "master", :glob => "\.\/\*\.gemspec"}) @@ -223,7 +232,7 @@ RSpec.describe "bundle add" do end describe "with --github and --ref and --glob" do - it "adds dependency with specified github source and ref", :realworld do + it "adds dependency with specified github source and ref" do bundle "add rake --github=ruby/rake --ref=5c60da8 --glob='./*.gemspec'" expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :ref => "5c60da8", :glob => "\.\/\*\.gemspec"}) @@ -240,8 +249,8 @@ RSpec.describe "bundle add" do end it "using combination of short form options works like long form" do - bundle "add 'foo' -s='#{file_uri_for(gem_repo2)}' -g='development' -v='~>1.0'" - expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "#{file_uri_for(gem_repo2)}") + bundle "add 'foo' -s='https://gem.repo2' -g='development' -v='~>1.0'" + expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "https://gem.repo2") expect(the_bundle).to include_gems "foo 1.1" end @@ -255,12 +264,12 @@ RSpec.describe "bundle add" do bundle "add 'werk_it'", raise_on_error: false expect(err).to match("Could not find gem 'werk_it' in") - bundle "add 'werk_it' -s='#{file_uri_for(gem_repo2)}'", raise_on_error: false + bundle "add 'werk_it' -s='https://gem.repo2'", raise_on_error: false expect(err).to match("Could not find gem 'werk_it' in rubygems repository") end it "shows error message when source cannot be reached" do - bundle "add 'baz' --source='http://badhostasdf'", raise_on_error: false + bundle "add 'baz' --source='http://badhostasdf'", raise_on_error: false, artifice: "fail" expect(err).to include("Could not reach host badhostasdf. Check your network connection and try again.") bundle "add 'baz' --source='file://does/not/exist'", raise_on_error: false @@ -318,41 +327,41 @@ RSpec.describe "bundle add" do describe "when a gem is added which is already specified in Gemfile with version" do it "shows an error when added with different version requirement" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", "1.0" + source "https://gem.repo2" + gem "myrack", "1.0" G - bundle "add 'rack' --version=1.1", raise_on_error: false + bundle "add 'myrack' --version=1.1", raise_on_error: false expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).to include("If you want to update the gem version, run `bundle update rack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") + expect(err).to include("If you want to update the gem version, run `bundle update myrack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end it "shows error when added without version requirements" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", "1.0" + source "https://gem.repo2" + gem "myrack", "1.0" G - bundle "add 'rack'", raise_on_error: false + bundle "add 'myrack'", raise_on_error: false expect(err).to include("Gem already added.") expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).not_to include("If you want to update the gem version, run `bundle update rack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") + expect(err).not_to include("If you want to update the gem version, run `bundle update myrack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end end describe "when a gem is added which is already specified in Gemfile without version" do it "shows an error when added with different version requirement" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G - bundle "add 'rack' --version=1.1", raise_on_error: false + bundle "add 'myrack' --version=1.1", raise_on_error: false expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).to include("If you want to update the gem version, run `bundle update rack`.") + expect(err).to include("If you want to update the gem version, run `bundle update myrack`.") expect(err).not_to include("You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end end @@ -361,8 +370,8 @@ RSpec.describe "bundle add" do it "caches all new dependencies added for the specified gem" do bundle :cache - bundle "add 'rack' --version=1.0.0" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + bundle "add 'myrack' --version=1.0.0" + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end end end diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index 6c3dc7bb2d..74582226f8 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -4,44 +4,44 @@ RSpec.describe "bundle binstubs <gem>" do context "when the gem exists in the lockfile" do it "sets up the binstub" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack" + bundle "binstubs myrack" - expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/myrackup")).to exist end it "does not install other binstubs" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "rails" G bundle "binstubs rails" - expect(bundled_app("bin/rackup")).not_to exist + expect(bundled_app("bin/myrackup")).not_to exist expect(bundled_app("bin/rails")).to exist end it "does install multiple binstubs" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "rails" G - bundle "binstubs rails rack" + bundle "binstubs rails myrack" - expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/myrackup")).to exist expect(bundled_app("bin/rails")).to exist end it "allows installing all binstubs" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -53,20 +53,20 @@ RSpec.describe "bundle binstubs <gem>" do it "allows installing binstubs for all platforms" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack --all-platforms" + bundle "binstubs myrack --all-platforms" - expect(bundled_app("bin/rackup")).to exist - expect(bundled_app("bin/rackup.cmd")).to exist + expect(bundled_app("bin/myrackup")).to exist + expect(bundled_app("bin/myrackup.cmd")).to exist end it "displays an error when used without any gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "binstubs", raise_on_error: false @@ -76,11 +76,11 @@ RSpec.describe "bundle binstubs <gem>" do it "displays an error when used with --all and gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack", all: true, raise_on_error: false + bundle "binstubs myrack", all: true, raise_on_error: false expect(last_command).to be_failure expect(err).to include("Cannot specify --all with specific gems") end @@ -88,17 +88,17 @@ RSpec.describe "bundle binstubs <gem>" do context "when generating bundle binstub outside bundler" do it "should abort" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack" + bundle "binstubs myrack" File.open(bundled_app("bin/bundle"), "wb") do |file| file.print "OMG" end - sys_exec "bin/rackup", raise_on_error: false + sys_exec "bin/myrackup", raise_on_error: false expect(err).to include("was not generated by Bundler") end @@ -108,8 +108,8 @@ RSpec.describe "bundle binstubs <gem>" do before do pristine_system_gems "bundler-#{system_bundler_version}" build_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "prints_loaded_gems", "1.0" do |s| @@ -120,25 +120,29 @@ RSpec.describe "bundle binstubs <gem>" do puts specs.map(&:full_name).sort.inspect R end + + build_bundler locked_bundler_version end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" gem "prints_loaded_gems" G - bundle "binstubs bundler rack prints_loaded_gems" + bundle "binstubs bundler myrack prints_loaded_gems" end let(:system_bundler_version) { Bundler::VERSION } + let(:locked_bundler_version) { nil } + let(:lockfile_content) { lockfile.gsub(system_bundler_version, locked_bundler_version) } it "runs bundler" do - sys_exec "bin/bundle install", env: { "DEBUG" => "1" } + bundle "install --verbose", bundle_bin: "bin/bundle" expect(out).to include %(Using bundler #{system_bundler_version}\n) end context "when BUNDLER_VERSION is set" do it "runs the correct version of bundler" do - sys_exec "bin/bundle install", env: { "BUNDLER_VERSION" => "999.999.999" }, raise_on_error: false + bundle "install", env: { "BUNDLER_VERSION" => "999.999.999" }, raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (999.999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") @@ -147,19 +151,21 @@ RSpec.describe "bundle binstubs <gem>" do it "runs the correct version of bundler even if a higher version is installed" do system_gems "bundler-999.999.998", "bundler-999.999.999" - sys_exec "bin/bundle install", env: { "BUNDLER_VERSION" => "999.999.998", "DEBUG" => "1" }, raise_on_error: false + bundle "install --verbose", env: { "BUNDLER_VERSION" => "999.999.998" }, raise_on_error: false, bundle_bin: "bin/bundle" expect(out).to include %(Using bundler 999.999.998\n) end end context "when a lockfile exists with a locked bundler version" do + let(:locked_bundler_version) { "999.999" } + context "and the version is newer" do before do - lockfile lockfile.gsub(system_bundler_version, "999.999") + lockfile lockfile_content end it "runs the correct version of bundler" do - sys_exec "bin/bundle install", raise_on_error: false + bundle "install", raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -169,11 +175,11 @@ RSpec.describe "bundle binstubs <gem>" do context "and the version is newer when given `gems.rb` and `gems.locked`" do before do gemfile bundled_app("gems.rb"), gemfile - lockfile bundled_app("gems.locked"), lockfile.gsub(system_bundler_version, "999.999") + lockfile bundled_app("gems.locked"), lockfile_content end it "runs the correct version of bundler" do - sys_exec "bin/bundle install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false + bundle "install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 999.999) failed:"). @@ -183,13 +189,14 @@ RSpec.describe "bundle binstubs <gem>" do context "and the version is older and a different major" do let(:system_bundler_version) { "55" } + let(:locked_bundler_version) { "44" } before do - lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 44.0") + lockfile lockfile_content end it "runs the correct version of bundler" do - sys_exec "bin/bundle install", raise_on_error: false + bundle "install", raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 44.0) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`") @@ -198,14 +205,15 @@ RSpec.describe "bundle binstubs <gem>" do context "and the version is older and a different major when given `gems.rb` and `gems.locked`" do let(:system_bundler_version) { "55" } + let(:locked_bundler_version) { "44" } before do gemfile bundled_app("gems.rb"), gemfile - lockfile bundled_app("gems.locked"), lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 44.0") + lockfile bundled_app("gems.locked"), lockfile_content end it "runs the correct version of bundler" do - sys_exec "bin/bundle install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false + bundle "install", env: { "BUNDLE_GEMFILE" => "gems.rb" }, raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 44.0) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`") @@ -214,13 +222,14 @@ RSpec.describe "bundle binstubs <gem>" do context "and the version is older and the same major" do let(:system_bundler_version) { "2.999.999" } + let(:locked_bundler_version) { "2.3.0" } before do - lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 2.3.0") + lockfile lockfile_content end - it "installs and runs the exact version of bundler", rubygems: ">= 3.3.0.dev", realworld: true do - sys_exec "bin/bundle install --verbose", artifice: "vcr" + it "installs and runs the exact version of bundler", rubygems: ">= 3.3.0.dev" do + bundle "install --verbose", bundle_bin: "bin/bundle" expect(exitstatus).not_to eq(42) expect(out).to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.") expect(out).to include("Using bundler 2.3.0") @@ -228,7 +237,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "runs the available version of bundler", rubygems: "< 3.3.0.dev" do - sys_exec "bin/bundle install --verbose" + bundle "install --verbose", bundle_bin: "bin/bundle" expect(exitstatus).not_to eq(42) expect(out).not_to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.") expect(out).to include("Using bundler 2.999.999") @@ -238,13 +247,14 @@ RSpec.describe "bundle binstubs <gem>" do context "and the version is a pre-releaser" do let(:system_bundler_version) { "55" } + let(:locked_bundler_version) { "2.12.0.a" } before do - lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 2.12.0.a") + lockfile lockfile_content end it "runs the correct version of bundler when the version is a pre-release" do - sys_exec "bin/bundle install", raise_on_error: false + bundle "install", raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 2.12.a) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`") @@ -253,10 +263,8 @@ RSpec.describe "bundle binstubs <gem>" do end context "when update --bundler is called" do - before { lockfile.gsub(system_bundler_version, "1.1.1") } - - it "calls through to the latest bundler version", :realworld do - sys_exec "bin/bundle update --bundler", env: { "DEBUG" => "1" } + it "calls through to the latest bundler version" do + bundle "update --bundler --verbose", bundle_bin: "bin/bundle" using_bundler_line = /Using bundler ([\w\.]+)\n/.match(out) expect(using_bundler_line).to_not be_nil latest_version = using_bundler_line[1] @@ -264,7 +272,7 @@ RSpec.describe "bundle binstubs <gem>" do end it "calls through to the explicit bundler version" do - sys_exec "bin/bundle update --bundler=999.999.999", raise_on_error: false + bundle "update --bundler=999.999.999", raise_on_error: false, bundle_bin: "bin/bundle" expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (999.999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '999.999.999'`") @@ -274,7 +282,7 @@ RSpec.describe "bundle binstubs <gem>" do context "without a lockfile" do it "falls back to the latest installed bundler" do FileUtils.rm bundled_app_lock - sys_exec "bin/bundle install", env: { "DEBUG" => "1" } + bundle "install --verbose", bundle_bin: "bin/bundle" expect(out).to include "Using bundler #{system_bundler_version}\n" end end @@ -282,14 +290,14 @@ RSpec.describe "bundle binstubs <gem>" do context "using another binstub" do it "loads all gems" do sys_exec bundled_app("bin/print_loaded_gems").to_s - expect(out).to eq %(["bundler-#{Bundler::VERSION}", "prints_loaded_gems-1.0", "rack-1.2"]) + expect(out).to eq %(["bundler-#{Bundler::VERSION}", "myrack-1.2", "prints_loaded_gems-1.0"]) end context "when requesting a different bundler version" do before { lockfile lockfile.gsub(Bundler::VERSION, "999.999.999") } it "attempts to load that version" do - sys_exec bundled_app("bin/rackup").to_s, raise_on_error: false + sys_exec bundled_app("bin/myrackup").to_s, raise_on_error: false expect(exitstatus).to eq(42) expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") @@ -305,7 +313,7 @@ RSpec.describe "bundle binstubs <gem>" do s.executables = %w[foo] end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo")}" G @@ -321,7 +329,7 @@ RSpec.describe "bundle binstubs <gem>" do s.executables = %w[foo] end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G @@ -333,12 +341,12 @@ RSpec.describe "bundle binstubs <gem>" do it "sets correct permissions for binstubs" do with_umask(0o002) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack" - binary = bundled_app("bin/rackup") + bundle "binstubs myrack" + binary = bundled_app("bin/myrackup") expect(File.stat(binary).mode.to_s(8)).to eq(Gem.win_platform? ? "100644" : "100775") end end @@ -346,12 +354,12 @@ RSpec.describe "bundle binstubs <gem>" do context "when using --shebang" do it "sets the specified shebang for the binstub" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack --shebang jruby" - expect(File.readlines(bundled_app("bin/rackup")).first).to eq("#!/usr/bin/env jruby\n") + bundle "binstubs myrack --shebang jruby" + expect(File.readlines(bundled_app("bin/myrackup")).first).to eq("#!/usr/bin/env jruby\n") end end end @@ -359,7 +367,7 @@ RSpec.describe "bundle binstubs <gem>" do context "when the gem doesn't exist" do it "displays an error with correct status" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G bundle "binstubs doesnt_exist", raise_on_error: false @@ -372,23 +380,23 @@ RSpec.describe "bundle binstubs <gem>" do context "--path" do it "sets the binstubs dir" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack --path exec" + bundle "binstubs myrack --path exec" - expect(bundled_app("exec/rackup")).to exist + expect(bundled_app("exec/myrackup")).to exist end it "setting is saved for bundle install", bundler: "< 3" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "rails" G - bundle "binstubs rack", path: "exec" + bundle "binstubs myrack", path: "exec" bundle :install expect(bundled_app("exec/rails")).to exist @@ -398,34 +406,34 @@ RSpec.describe "bundle binstubs <gem>" do context "with --standalone option" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "rails" G end it "generates a standalone binstub" do - bundle "binstubs rack --standalone" - expect(bundled_app("bin/rackup")).to exist + bundle "binstubs myrack --standalone" + expect(bundled_app("bin/myrackup")).to exist end it "generates a binstub that does not depend on rubygems or bundler" do - bundle "binstubs rack --standalone" - expect(File.read(bundled_app("bin/rackup"))).to_not include("Gem.bin_path") + bundle "binstubs myrack --standalone" + expect(File.read(bundled_app("bin/myrackup"))).to_not include("Gem.bin_path") end context "when specified --path option" do it "generates a standalone binstub at the given path" do - bundle "binstubs rack --standalone --path foo" - expect(bundled_app("foo/rackup")).to exist + bundle "binstubs myrack --standalone --path foo" + expect(bundled_app("foo/myrackup")).to exist end end context "when specified --all-platforms option" do it "generates standalone binstubs for all platforms" do - bundle "binstubs rack --standalone --all-platforms" - expect(bundled_app("bin/rackup")).to exist - expect(bundled_app("bin/rackup.cmd")).to exist + bundle "binstubs myrack --standalone --all-platforms" + expect(bundled_app("bin/myrackup")).to exist + expect(bundled_app("bin/myrackup.cmd")).to exist end end @@ -441,7 +449,7 @@ RSpec.describe "bundle binstubs <gem>" do context "when specified --all option" do it "generates standalone binstubs for all gems except bundler" do bundle "binstubs --standalone --all" - expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/myrackup")).to exist expect(bundled_app("bin/rails")).to exist expect(bundled_app("bin/bundle")).not_to exist expect(bundled_app("bin/bundler")).not_to exist @@ -453,39 +461,39 @@ RSpec.describe "bundle binstubs <gem>" do context "when the bin already exists" do it "doesn't overwrite and warns" do FileUtils.mkdir_p(bundled_app("bin")) - File.open(bundled_app("bin/rackup"), "wb") do |file| + File.open(bundled_app("bin/myrackup"), "wb") do |file| file.print "OMG" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack" + bundle "binstubs myrack" - expect(bundled_app("bin/rackup")).to exist - expect(File.read(bundled_app("bin/rackup"))).to eq("OMG") - expect(err).to include("Skipped rackup") + expect(bundled_app("bin/myrackup")).to exist + expect(File.read(bundled_app("bin/myrackup"))).to eq("OMG") + expect(err).to include("Skipped myrackup") expect(err).to include("overwrite skipped stubs, use --force") end context "when using --force" do it "overwrites the binstub" do FileUtils.mkdir_p(bundled_app("bin")) - File.open(bundled_app("bin/rackup"), "wb") do |file| + File.open(bundled_app("bin/myrackup"), "wb") do |file| file.print "OMG" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "binstubs rack --force" + bundle "binstubs myrack --force" - expect(bundled_app("bin/rackup")).to exist - expect(File.read(bundled_app("bin/rackup"))).not_to eq("OMG") + expect(bundled_app("bin/myrackup")).to exist + expect(File.read(bundled_app("bin/myrackup"))).not_to eq("OMG") end end end @@ -493,18 +501,18 @@ RSpec.describe "bundle binstubs <gem>" do context "when the gem has no bins" do it "suggests child gems if they have bins" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack-obama" G - bundle "binstubs rack-obama" - expect(err).to include("rack-obama has no executables") - expect(err).to include("rack has: rackup") + bundle "binstubs myrack-obama" + expect(err).to include("myrack-obama has no executables") + expect(err).to include("myrack has: myrackup") end it "works if child gems don't have bins" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "actionpack" G @@ -520,7 +528,7 @@ RSpec.describe "bundle binstubs <gem>" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "with_development_dependency" G @@ -532,25 +540,25 @@ RSpec.describe "bundle binstubs <gem>" do context "when BUNDLE_INSTALL is specified" do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set auto_install 1" - bundle "binstubs rack" - expect(out).to include("Installing rack 1.0.0") - expect(the_bundle).to include_gems "rack 1.0.0" + bundle "binstubs myrack" + expect(out).to include("Installing myrack 1.0.0") + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does nothing when already up to date" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set auto_install 1" - bundle "binstubs rack", env: { "BUNDLE_INSTALL" => "1" } - expect(out).not_to include("Installing rack 1.0.0") + bundle "binstubs myrack", env: { "BUNDLE_INSTALL" => "1" } + expect(out).not_to include("Installing myrack 1.0.0") end end end diff --git a/spec/bundler/commands/cache_spec.rb b/spec/bundler/commands/cache_spec.rb index 37d8b3ac1a..ab8eb06838 100644 --- a/spec/bundler/commands/cache_spec.rb +++ b/spec/bundler/commands/cache_spec.rb @@ -3,8 +3,8 @@ RSpec.describe "bundle cache" do it "doesn't update the cache multiple times, even if it already exists" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :cache @@ -17,14 +17,14 @@ RSpec.describe "bundle cache" do context "with --gemfile" do it "finds the gemfile" do gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle "cache --gemfile=NotGemfile" ENV["BUNDLE_GEMFILE"] = "NotGemfile" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end @@ -32,15 +32,15 @@ RSpec.describe "bundle cache" do context "without a gemspec" do it "caches all dependencies except bundler itself" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gem 'bundler' D bundle "config set cache_all true" bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist end end @@ -63,15 +63,15 @@ RSpec.describe "bundle cache" do it "caches all dependencies except bundler and the gemspec specified gem" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gemspec D bundle "config set cache_all true" bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist @@ -95,15 +95,15 @@ RSpec.describe "bundle cache" do it "caches all dependencies except bundler and the gemspec specified gem" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gemspec D bundle "config set cache_all true" bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist @@ -139,8 +139,8 @@ RSpec.describe "bundle cache" do it "caches all dependencies except bundler and the gemspec specified gems" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gemspec :name => 'mygem' gemspec :name => 'mygem_test' D @@ -148,7 +148,7 @@ RSpec.describe "bundle cache" do bundle "config set cache_all true" bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist @@ -161,13 +161,13 @@ RSpec.describe "bundle cache" do context "with --path", bundler: "< 3" do it "sets root directory for gems" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' D bundle "cache --path #{bundled_app("test")}" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(bundled_app("test/vendor/cache/")).to exist end end @@ -175,60 +175,60 @@ RSpec.describe "bundle cache" do context "with --no-install" do it "puts the gems in vendor/cache but does not install them" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' D bundle "cache --no-install" - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(the_bundle).not_to include_gems "myrack 1.0.0" + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "does not prevent installing gems with bundle install" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' D bundle "cache --no-install" bundle "install" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does not prevent installing gems with bundle update" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" D bundle "cache --no-install" bundle "update --all" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end context "with --all-platforms" do it "puts the gems in vendor/cache even for other rubies", bundler: ">= 2.4.0" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack', :platforms => [:ruby_20, :windows_20] + source "https://gem.repo1" + gem 'myrack', :platforms => [:ruby_20, :windows_20] D bundle "cache --all-platforms" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "puts the gems in vendor/cache even for legacy windows rubies", bundler: ">= 2.4.0" do gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack', :platforms => [:ruby_20, :x64_mingw_20] + source "https://gem.repo1" + gem 'myrack', :platforms => [:ruby_20, :x64_mingw_20] D bundle "cache --all-platforms" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "does not attempt to install gems in without groups" do @@ -241,39 +241,39 @@ RSpec.describe "bundle cache" do end bundle "config set --local without wo" - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + install_gemfile <<-G, artifice: "compact_index_extra_api" + source "https://main.repo" + gem "myrack" group :wo do gem "weakling" - gem "uninstallable", :source => "#{file_uri_for(gem_repo4)}" + gem "uninstallable", :source => "https://main.repo/extra" end G - bundle :cache, "all-platforms" => true + bundle :cache, "all-platforms" => true, artifice: "compact_index_extra_api" expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist expect(bundled_app("vendor/cache/uninstallable-2.0.gem")).to exist - expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).to include_gem "myrack 1.0" expect(the_bundle).not_to include_gems "weakling", "uninstallable" bundle "config set --local without wo" - bundle :install - expect(the_bundle).to include_gem "rack 1.0" - expect(the_bundle).not_to include_gems "weakling", "uninstallable" + bundle :install, artifice: "compact_index_extra_api" + expect(the_bundle).to include_gem "myrack 1.0" + expect(the_bundle).not_to include_gems "weakling" end it "does not fail to cache gems in excluded groups when there's a lockfile but gems not previously installed" do bundle "config set --local without wo" gemfile <<-G - source "https://my.gem.repo.1" - gem "rack" + source "https://gem.repo1" + gem "myrack" group :wo do gem "weakling" end G - bundle :lock, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } - bundle :cache, "all-platforms" => true, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } + bundle :lock + bundle :cache, "all-platforms" => true expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist end end @@ -281,8 +281,8 @@ RSpec.describe "bundle cache" do context "with frozen configured" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "install" end @@ -295,15 +295,15 @@ RSpec.describe "bundle cache" do it "tries to install with frozen" do bundle "config set deployment true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G subject expect(exitstatus).to eq(16) expect(err).to include("frozen mode") expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") + expect(err).to include("* myrack-obama") bundle "env" expect(out).to include("frozen").or include("deployment") end @@ -315,12 +315,12 @@ RSpec.describe "bundle cache" do build_gem "racc", "2.0" do |s| s.add_dependency "rake" s.extensions << "Rakefile" - s.write "Rakefile", "task(:default) { puts 'INSTALLING rack' }" + s.write "Rakefile", "task(:default) { puts 'INSTALLING myrack' }" end end gemfile <<~G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "racc" G @@ -339,8 +339,8 @@ RSpec.describe "bundle install with gem sources" do it "does not hit the remote at all" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G bundle :cache @@ -348,14 +348,14 @@ RSpec.describe "bundle install with gem sources" do FileUtils.rm_rf gem_repo2 bundle "install --local" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does not hit the remote at all in frozen mode" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G bundle :cache @@ -365,14 +365,14 @@ RSpec.describe "bundle install with gem sources" do bundle "config set --local deployment true" bundle "config set --local path vendor/bundle" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does not hit the remote at all when cache_all_platforms configured" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G bundle :cache @@ -383,7 +383,7 @@ RSpec.describe "bundle install with gem sources" do bundle "config set --local path vendor/bundle" bundle "install --local" expect(out).not_to include("Fetching gem metadata") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "uses cached gems for secondary sources when cache_all_platforms configured" do @@ -398,20 +398,20 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "https://gems.repo2" + source "https://gem.repo2" - source "https://gems.repo4" do + source "https://gem.repo4" do gem "foo" end G lockfile <<~L GEM - remote: https://gems.repo2/ + remote: https://gem.repo2/ specs: GEM - remote: https://gems.repo4/ + remote: https://gem.repo4/ specs: foo (1.0.0-x86_64-linux) foo (1.0.0-arm64-darwin) @@ -448,24 +448,24 @@ RSpec.describe "bundle install with gem sources" do it "does not reinstall already-installed gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :cache - build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") do |s| - s.write "lib/rack.rb", "raise 'omg'" + build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") do |s| + s.write "lib/myrack.rb", "raise 'omg'" end bundle :install expect(err).to be_empty - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "ignores cached gems for the wrong platform" do simulate_platform "java" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G bundle :cache @@ -476,17 +476,16 @@ RSpec.describe "bundle install with gem sources" do bundle "config set --local force_ruby_platform true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 RUBY") + expect(the_bundle).to include_gems("platform_specific 1.0 ruby") end it "does not update the cache if --no-cache is passed" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundled_app("vendor/cache").mkpath expect(bundled_app("vendor/cache").children).to be_empty diff --git a/spec/bundler/commands/check_spec.rb b/spec/bundler/commands/check_spec.rb index 02f9bb5b7a..7da9635d9f 100644 --- a/spec/bundler/commands/check_spec.rb +++ b/spec/bundler/commands/check_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "bundle check" do it "returns success when the Gemfile is satisfied" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -13,7 +13,7 @@ RSpec.describe "bundle check" do it "works with the --gemfile flag when not in the directory" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -23,7 +23,7 @@ RSpec.describe "bundle check" do it "creates a Gemfile.lock by default if one does not exist" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -36,7 +36,7 @@ RSpec.describe "bundle check" do it "does not create a Gemfile.lock if --dry-run was passed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -51,7 +51,7 @@ RSpec.describe "bundle check" do system_gems ["rails-2.3.2"] gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -61,7 +61,7 @@ RSpec.describe "bundle check" do it "prints a generic error if a Gemfile.lock does not exist and a toplevel dependency does not exist" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -78,12 +78,12 @@ RSpec.describe "bundle check" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'rails' G gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" gem "rails_pinned_to_old_activesupport" G @@ -94,9 +94,9 @@ RSpec.describe "bundle check" do it "remembers --without option from install", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :foo do - gem "rack" + gem "myrack" end G @@ -108,9 +108,9 @@ RSpec.describe "bundle check" do it "uses the without setting" do bundle "config set without foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :foo do - gem "rack" + gem "myrack" end G @@ -120,63 +120,63 @@ RSpec.describe "bundle check" do it "ensures that gems are actually installed and not just cached" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :group => :foo + source "https://gem.repo1" + gem "myrack", :group => :foo G bundle "config set --local without foo" bundle :install gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "check", raise_on_error: false - expect(err).to include("* rack (1.0.0)") + expect(err).to include("* myrack (1.0.0)") expect(exitstatus).to eq(1) end it "ensures that gems are actually installed and not just cached in applications' cache" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set --local path vendor/bundle" bundle :cache - gem_command "uninstall rack", env: { "GEM_HOME" => vendored_gems.to_s } + gem_command "uninstall myrack", env: { "GEM_HOME" => vendored_gems.to_s } bundle "check", raise_on_error: false - expect(err).to include("* rack (1.0.0)") + expect(err).to include("* myrack (1.0.0)") expect(exitstatus).to eq(1) end it "ignores missing gems restricted to other platforms" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" platforms :#{not_local_tag} do gem "activesupport" end G - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: activesupport (2.3.5) - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{generic_local_platform} #{not_local} DEPENDENCIES - rack + myrack activesupport G @@ -186,28 +186,28 @@ RSpec.describe "bundle check" do it "works with env conditionals" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" env :NOT_GOING_TO_BE_SET do gem "activesupport" end G - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: activesupport (2.3.5) - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{generic_local_platform} #{not_local} DEPENDENCIES - rack + myrack activesupport G @@ -229,7 +229,7 @@ RSpec.describe "bundle check" do it "fails when there's no lock file and frozen is set" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G @@ -245,7 +245,7 @@ RSpec.describe "bundle check" do context "after installing gems in the proper directory" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G bundle "install --path vendor/bundle" @@ -267,7 +267,7 @@ RSpec.describe "bundle check" do context "after installing gems on a different directory" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -283,10 +283,10 @@ RSpec.describe "bundle check" do describe "when locked" do before :each do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0" + source "https://gem.repo1" + gem "myrack", "1.0" G end @@ -300,26 +300,26 @@ RSpec.describe "bundle check" do simulate_new_machine bundle :check, raise_on_error: false expect(err).to match(/The following gems are missing/) - expect(err).to include("* rack (1.0") + expect(err).to include("* myrack (1.0") end end describe "when locked with multiple dependents with different requirements" do before :each do build_repo4 do - build_gem "depends_on_rack" do |s| - s.add_dependency "rack", ">= 1.0" + build_gem "depends_on_myrack" do |s| + s.add_dependency "myrack", ">= 1.0" end - build_gem "also_depends_on_rack" do |s| - s.add_dependency "rack", "~> 1.0" + build_gem "also_depends_on_myrack" do |s| + s.add_dependency "myrack", "~> 1.0" end - build_gem "rack" + build_gem "myrack" end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "depends_on_rack" - gem "also_depends_on_rack" + source "https://gem.repo4" + gem "depends_on_myrack" + gem "also_depends_on_myrack" G bundle "lock" @@ -328,33 +328,33 @@ RSpec.describe "bundle check" do it "shows what is missing with the current Gemfile without duplications" do bundle :check, raise_on_error: false expect(err).to match(/The following gems are missing/) - expect(err).to include("* rack (1.0").once + expect(err).to include("* myrack (1.0").once end end describe "when locked under multiple platforms" do before :each do build_repo4 do - build_gem "rack" + build_gem "myrack" end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS ruby #{local_platform} DEPENDENCIES - rack + myrack BUNDLED WITH #{Bundler::VERSION} @@ -364,22 +364,22 @@ RSpec.describe "bundle check" do it "shows what is missing with the current Gemfile without duplications" do bundle :check, raise_on_error: false expect(err).to match(/The following gems are missing/) - expect(err).to include("* rack (1.0").once + expect(err).to include("* myrack (1.0").once end end describe "when using only scoped rubygems sources" do before do gemfile <<~G - source "#{file_uri_for(gem_repo2)}" - source "#{file_uri_for(gem_repo1)}" do - gem "rack" + source "https://gem.repo2" + source "https://gem.repo1" do + gem "myrack" end G end it "returns success when the Gemfile is satisfied" do - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path bundle :check expect(out).to include("The Gemfile's dependencies are satisfied") end @@ -388,48 +388,48 @@ RSpec.describe "bundle check" do describe "when using only scoped rubygems sources with indirect dependencies" do before do build_repo4 do - build_gem "depends_on_rack" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack" do |s| + s.add_dependency "myrack" end - build_gem "rack" + build_gem "myrack" end gemfile <<~G - source "#{file_uri_for(gem_repo1)}" - source "#{file_uri_for(gem_repo4)}" do - gem "depends_on_rack" + source "https://gem.repo1" + source "https://gem.repo4" do + gem "depends_on_myrack" end G end it "returns success when the Gemfile is satisfied and generates a correct lockfile" do - system_gems "depends_on_rack-1.0", "rack-1.0", gem_repo: gem_repo4, path: default_bundle_path + system_gems "depends_on_myrack-1.0", "myrack-1.0", gem_repo: gem_repo4, path: default_bundle_path bundle :check checksums = checksums_section_when_existing do |c| - c.no_checksum "depends_on_rack", "1.0" - c.no_checksum "rack", "1.0" + c.no_checksum "depends_on_myrack", "1.0" + c.no_checksum "myrack", "1.0" end expect(out).to include("The Gemfile's dependencies are satisfied") expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - depends_on_rack (1.0) - rack - rack (1.0) + depends_on_myrack (1.0) + myrack + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - depends_on_rack! + depends_on_myrack! #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -447,7 +447,7 @@ RSpec.describe "bundle check" do build_gem "dex-dispatch-engine" end - build_lib("bundle-check-issue", path: tmp.join("bundle-check-issue")) do |s| + build_lib("bundle-check-issue", path: tmp("bundle-check-issue")) do |s| s.write "Gemfile", <<-G source "https://localgemserver.test" @@ -461,14 +461,14 @@ RSpec.describe "bundle check" do s.add_dependency "awesome_print" end - bundle "install", artifice: "compact_index_extra", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }, dir: tmp.join("bundle-check-issue") + bundle "install", artifice: "compact_index_extra", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }, dir: tmp("bundle-check-issue") end it "does not corrupt lockfile when changing version" do - version_file = tmp.join("bundle-check-issue/bundle-check-issue.gemspec") + version_file = tmp("bundle-check-issue/bundle-check-issue.gemspec") File.write(version_file, File.read(version_file).gsub(/s\.version = .+/, "s.version = '9999'")) - bundle "check --verbose", dir: tmp.join("bundle-check-issue") + bundle "check --verbose", dir: tmp("bundle-check-issue") checksums = checksums_section_when_existing do |c| c.checksum gem_repo4, "awesome_print", "1.0" @@ -476,7 +476,7 @@ RSpec.describe "bundle check" do c.checksum gem_repo2, "dex-dispatch-engine", "1.0" end - expect(File.read(tmp.join("bundle-check-issue/Gemfile.lock"))).to eq <<~L + expect(File.read(tmp("bundle-check-issue/Gemfile.lock"))).to eq <<~L PATH remote: . specs: @@ -510,15 +510,15 @@ RSpec.describe "bundle check" do def lock_with(bundler_version = nil) lock = <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack L if bundler_version @@ -532,8 +532,8 @@ RSpec.describe "bundle check" do bundle "config set --local path vendor/bundle" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end diff --git a/spec/bundler/commands/clean_spec.rb b/spec/bundler/commands/clean_spec.rb index 0b559a87c8..c27766835e 100644 --- a/spec/bundler/commands/clean_spec.rb +++ b/spec/bundler/commands/clean_spec.rb @@ -19,7 +19,7 @@ RSpec.describe "bundle clean" do it "removes unused gems that are different" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "foo" @@ -30,7 +30,7 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" G @@ -40,17 +40,17 @@ RSpec.describe "bundle clean" do expect(out).to include("Removing foo (1.0)") - should_have_gems "thin-1.0", "rack-1.0.0" + should_have_gems "thin-1.0", "myrack-1.0.0" should_not_have_gems "foo-1.0" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "removes old version of gem if unused" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "0.9.1" + gem "myrack", "0.9.1" gem "foo" G @@ -59,28 +59,28 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" gem "foo" G bundle "install" bundle :clean - expect(out).to include("Removing rack (0.9.1)") + expect(out).to include("Removing myrack (0.9.1)") - should_have_gems "foo-1.0", "rack-1.0.0" - should_not_have_gems "rack-0.9.1" + should_have_gems "foo-1.0", "myrack-1.0.0" + should_not_have_gems "myrack-0.9.1" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "removes new version of gem if unused" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" gem "foo" G @@ -89,31 +89,31 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "0.9.1" + gem "myrack", "0.9.1" gem "foo" G - bundle "update rack" + bundle "update myrack" bundle :clean - expect(out).to include("Removing rack (1.0.0)") + expect(out).to include("Removing myrack (1.0.0)") - should_have_gems "foo-1.0", "rack-0.9.1" - should_not_have_gems "rack-1.0.0" + should_have_gems "foo-1.0", "myrack-0.9.1" + should_not_have_gems "myrack-1.0.0" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "removes gems in bundle without groups" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" group :test_group do - gem "rack", "1.0.0" + gem "myrack", "1.0.0" end G @@ -123,12 +123,12 @@ RSpec.describe "bundle clean" do bundle "install" bundle :clean - expect(out).to include("Removing rack (1.0.0)") + expect(out).to include("Removing myrack (1.0.0)") should_have_gems "foo-1.0" - should_not_have_gems "rack-1.0.0" + should_not_have_gems "myrack-1.0.0" - expect(vendored_gems("bin/rackup")).to_not exist + expect(vendored_gems("bin/myrackup")).to_not exist end it "does not remove cached git dir if it's being used" do @@ -137,9 +137,9 @@ RSpec.describe "bundle clean" do git_path = lib_path("foo-1.0") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" git "#{git_path}", :ref => "#{revision}" do gem "foo" end @@ -161,9 +161,9 @@ RSpec.describe "bundle clean" do revision = revision_for(git_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" git "#{git_path}", :ref => "#{revision}" do gem "foo" end @@ -173,9 +173,9 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G bundle "install" @@ -183,14 +183,14 @@ RSpec.describe "bundle clean" do expect(out).to include("Removing foo (#{revision[0..11]})") - expect(vendored_gems("gems/rack-1.0.0")).to exist + expect(vendored_gems("gems/myrack-1.0.0")).to exist expect(vendored_gems("bundler/gems/foo-#{revision[0..11]}")).not_to exist digest = Digest(:SHA1).hexdigest(git_path.to_s) expect(vendored_gems("cache/bundler/git/foo-#{digest}")).not_to exist - expect(vendored_gems("specifications/rack-1.0.0.gemspec")).to exist + expect(vendored_gems("specifications/myrack-1.0.0.gemspec")).to exist - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "keeps used git gems even if installed to a symlinked location" do @@ -199,9 +199,9 @@ RSpec.describe "bundle clean" do revision = revision_for(git_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" git "#{git_path}", :ref => "#{revision}" do gem "foo" end @@ -225,9 +225,9 @@ RSpec.describe "bundle clean" do revision = revision_for(lib_path("foo-bar")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" git "#{lib_path("foo-bar")}" do gem "foo-bar" end @@ -244,13 +244,13 @@ RSpec.describe "bundle clean" do expect(out).to include("Removing foo-bar (#{revision[0..11]})") - expect(vendored_gems("gems/rack-1.0.0")).to exist + expect(vendored_gems("gems/myrack-1.0.0")).to exist expect(vendored_gems("bundler/gems/foo-bar-#{revision[0..11]}")).not_to exist expect(vendored_gems("bundler/gems/foo-bar-#{revision2[0..11]}")).to exist - expect(vendored_gems("specifications/rack-1.0.0.gemspec")).to exist + expect(vendored_gems("specifications/myrack-1.0.0.gemspec")).to exist - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "does not remove nested gems in a git repo" do @@ -261,7 +261,7 @@ RSpec.describe "bundle clean" do revision = revision_for(lib_path("rails")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", :git => "#{lib_path("rails")}", :ref => '#{revision}' G @@ -279,9 +279,9 @@ RSpec.describe "bundle clean" do revision = revision_for(git_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" group :test do git "#{git_path}", :ref => "#{revision}" do gem "foo" @@ -302,9 +302,9 @@ RSpec.describe "bundle clean" do it "does not blow up when using without groups" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" group :development do gem "foo" @@ -321,9 +321,9 @@ RSpec.describe "bundle clean" do it "displays an error when used without --path" do bundle "config set path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G bundle :clean, raise_on_error: false @@ -335,7 +335,7 @@ RSpec.describe "bundle clean" do # handling bundle clean upgrade path from the pre's it "removes .gem/.gemspec file even if there's no corresponding gem dir" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "foo" @@ -345,63 +345,63 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G bundle "install" - FileUtils.rm(vendored_gems("bin/rackup")) + FileUtils.rm(vendored_gems("bin/myrackup")) FileUtils.rm_rf(vendored_gems("gems/thin-1.0")) - FileUtils.rm_rf(vendored_gems("gems/rack-1.0.0")) + FileUtils.rm_rf(vendored_gems("gems/myrack-1.0.0")) bundle :clean - should_not_have_gems "thin-1.0", "rack-1.0" + should_not_have_gems "thin-1.0", "myrack-1.0" should_have_gems "foo-1.0" - expect(vendored_gems("bin/rackup")).not_to exist + expect(vendored_gems("bin/myrackup")).not_to exist end it "does not call clean automatically when using system gems" do bundle "config set path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" - gem "rack" + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G gem_command :list - expect(out).to include("rack (1.0.0)").and include("thin (1.0)") + expect(out).to include("myrack (1.0.0)").and include("thin (1.0)") end it "--clean should override the bundle setting on install", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" - gem "rack" + gem "myrack" G bundle "config set path vendor/bundle" bundle "config set clean false" bundle "install --clean true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G bundle "install" - should_have_gems "rack-1.0.0" + should_have_gems "myrack-1.0.0" should_not_have_gems "thin-1.0" end @@ -409,7 +409,7 @@ RSpec.describe "bundle clean" do build_repo2 gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "foo" G @@ -431,7 +431,7 @@ RSpec.describe "bundle clean" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "foo" G @@ -453,29 +453,29 @@ RSpec.describe "bundle clean" do it "does not clean automatically on --path" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" - gem "rack" + gem "myrack" G bundle "config set path vendor/bundle" bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G bundle "install" - should_have_gems "rack-1.0.0", "thin-1.0" + should_have_gems "myrack-1.0.0", "thin-1.0" end it "does not clean on bundle update with --path" do build_repo2 gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "foo" G @@ -496,7 +496,7 @@ RSpec.describe "bundle clean" do build_repo2 gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "foo" G @@ -515,17 +515,17 @@ RSpec.describe "bundle clean" do bundle "config set path.system true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" - gem "rack" + gem "myrack" G bundle :install gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G bundle :install bundle "clean --force" @@ -533,7 +533,7 @@ RSpec.describe "bundle clean" do expect(out).to include("Removing foo (1.0)") gem_command :list expect(out).not_to include("foo (1.0)") - expect(out).to include("rack (1.0.0)") + expect(out).to include("myrack (1.0.0)") end describe "when missing permissions", :permissions do @@ -544,17 +544,17 @@ RSpec.describe "bundle clean" do end it "returns a helpful error message" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" - gem "rack" + gem "myrack" G bundle :install gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G bundle :install @@ -567,7 +567,7 @@ RSpec.describe "bundle clean" do gem_command :list expect(out).to include("foo (1.0)") - expect(out).to include("rack (1.0.0)") + expect(out).to include("myrack (1.0.0)") end end @@ -576,7 +576,7 @@ RSpec.describe "bundle clean" do revision = revision_for(lib_path("foo-1.0")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -612,7 +612,7 @@ RSpec.describe "bundle clean" do end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "bindir" G @@ -637,7 +637,7 @@ RSpec.describe "bundle clean" do realworld_system_gems "tsort --version 0.1.0", "pathname --version 0.1.0", "set --version 1.0.1" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" G bundle "clean --force", env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } @@ -654,7 +654,7 @@ RSpec.describe "bundle clean" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" gem "bar", "1.0", :path => "#{relative_path}" @@ -667,7 +667,7 @@ RSpec.describe "bundle clean" do it "doesn't remove gems in dry-run mode with path set" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "foo" @@ -678,7 +678,7 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" G @@ -690,14 +690,14 @@ RSpec.describe "bundle clean" do expect(out).not_to include("Removing foo (1.0)") expect(out).to include("Would have removed foo (1.0)") - should_have_gems "thin-1.0", "rack-1.0.0", "foo-1.0" + should_have_gems "thin-1.0", "myrack-1.0.0", "foo-1.0" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "doesn't remove gems in dry-run mode with no path set" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "foo" @@ -708,7 +708,7 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" G @@ -720,14 +720,14 @@ RSpec.describe "bundle clean" do expect(out).not_to include("Removing foo (1.0)") expect(out).to include("Would have removed foo (1.0)") - should_have_gems "thin-1.0", "rack-1.0.0", "foo-1.0" + should_have_gems "thin-1.0", "myrack-1.0.0", "foo-1.0" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "doesn't store dry run as a config setting" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "foo" @@ -739,7 +739,7 @@ RSpec.describe "bundle clean" do bundle "config set dry_run false" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" G @@ -751,15 +751,15 @@ RSpec.describe "bundle clean" do expect(out).to include("Removing foo (1.0)") expect(out).not_to include("Would have removed foo (1.0)") - should_have_gems "thin-1.0", "rack-1.0.0" + should_have_gems "thin-1.0", "myrack-1.0.0" should_not_have_gems "foo-1.0" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "foo" @@ -770,7 +770,7 @@ RSpec.describe "bundle clean" do bundle "install" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "weakling" @@ -779,7 +779,7 @@ RSpec.describe "bundle clean" do bundle "config set auto_install 1" bundle :clean expect(out).to include("Installing weakling 0.0.3") - should_have_gems "thin-1.0", "rack-1.0.0", "weakling-0.0.3" + should_have_gems "thin-1.0", "myrack-1.0.0", "weakling-0.0.3" should_not_have_gems "foo-1.0" end @@ -789,7 +789,7 @@ RSpec.describe "bundle clean" do revision = revision_for(lib_path("very_simple_git_binary-1.0")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" G @@ -808,7 +808,7 @@ RSpec.describe "bundle clean" do it "removes extension directories" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "very_simple_binary" @@ -828,7 +828,7 @@ RSpec.describe "bundle clean" do expect(simple_binary_extensions_dir).to exist gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "simple_binary" @@ -849,7 +849,7 @@ RSpec.describe "bundle clean" do short_revision = revision[0..11] gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" @@ -864,7 +864,7 @@ RSpec.describe "bundle clean" do expect(very_simple_binary_extensions_dir).to exist gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" G @@ -874,7 +874,7 @@ RSpec.describe "bundle clean" do expect(very_simple_binary_extensions_dir).to exist gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G bundle "install" @@ -891,7 +891,7 @@ RSpec.describe "bundle clean" do short_revision = revision[0..11] gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :development do gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb index 547fd2d869..1392b17315 100644 --- a/spec/bundler/commands/config_spec.rb +++ b/spec/bundler/commands/config_spec.rb @@ -38,8 +38,8 @@ RSpec.describe ".bundle/config" do describe "location with a gemfile" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G end @@ -56,7 +56,7 @@ RSpec.describe ".bundle/config" do expect(bundled_app(".bundle")).not_to exist expect(tmp("foo/bar/config")).to exist - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "can provide a relative path with the environment variable" do @@ -68,7 +68,7 @@ RSpec.describe ".bundle/config" do expect(bundled_app(".bundle")).not_to exist expect(bundled_app("../foo/config")).to exist - expect(the_bundle).to include_gems "rack 1.0.0", dir: bundled_app("omg") + expect(the_bundle).to include_gems "myrack 1.0.0", dir: bundled_app("omg") end end @@ -79,6 +79,14 @@ RSpec.describe ".bundle/config" do expect(home(".bundle/config")).to exist end + it "does not list global settings as local" do + bundle "config set --global foo bar" + bundle "config list", dir: home + + expect(out).to include("for the current user") + expect(out).not_to include("for your local app") + end + it "works with an absolute path" do ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s bundle "config set --local path vendor/bundle" @@ -115,8 +123,8 @@ RSpec.describe ".bundle/config" do describe "global" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G end @@ -207,8 +215,8 @@ RSpec.describe ".bundle/config" do describe "local" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G end @@ -263,8 +271,8 @@ RSpec.describe ".bundle/config" do describe "env" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G end @@ -336,8 +344,8 @@ RSpec.describe ".bundle/config" do describe "gem mirrors" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G end @@ -350,10 +358,16 @@ end E expect(out).to eq("http://gems.example.org/ => http://gem-mirror.example.org/") end + + it "allows configuring fallback timeout for each mirror, and does not duplicate configs", rubygems: ">= 3.5.12" do + bundle "config set --global mirror.https://rubygems.org.fallback_timeout 1" + bundle "config set --global mirror.https://rubygems.org.fallback_timeout 2" + expect(File.read(home(".bundle/config"))).to include("BUNDLE_MIRROR").once + end end describe "quoting" do - before(:each) { gemfile "source \"#{file_uri_for(gem_repo1)}\"" } + before(:each) { gemfile "source 'https://gem.repo1'" } let(:long_string) do "--with-xml2-include=/usr/pkg/include/libxml2 --with-xml2-lib=/usr/pkg/lib " \ "--with-xslt-dir=/usr/pkg" @@ -403,8 +417,8 @@ E describe "very long lines" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G end @@ -439,7 +453,7 @@ E it "does not make bundler crash and ignores the configuration" do bundle "config list --parseable" - expect(out).to eq("#mirror.https://rails-assets.org/=http://localhost:9292") + expect(out).to be_empty expect(err).to be_empty ruby(<<~RUBY) @@ -566,8 +580,8 @@ RSpec.describe "setting gemfile via config" do context "when only the non-default Gemfile exists" do it "persists the gemfile location to .bundle/config" do gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle "config set --local gemfile #{bundled_app("NotGemfile")}" diff --git a/spec/bundler/commands/console_spec.rb b/spec/bundler/commands/console_spec.rb index a41432b88a..8b02e7aa1b 100644 --- a/spec/bundler/commands/console_spec.rb +++ b/spec/bundler/commands/console_spec.rb @@ -38,16 +38,16 @@ RSpec.describe "bundle console", bundler: "< 3", readline: true do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development G end it "starts IRB with the default group loaded" do bundle "console" do |input, _, _| - input.puts("puts RACK") + input.puts("puts MYRACK") input.puts("exit") end expect(out).to include("0.9.1") @@ -63,7 +63,7 @@ RSpec.describe "bundle console", bundler: "< 3", readline: true do it "starts another REPL if configured as such" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "pry" G bundle "config set console pry" @@ -105,7 +105,7 @@ RSpec.describe "bundle console", bundler: "< 3", readline: true do it "loads the default group" do bundle "console test" do |input, _, _| - input.puts("puts RACK") + input.puts("puts MYRACK") input.puts("exit") end expect(out).to include("0.9.1") @@ -113,7 +113,7 @@ RSpec.describe "bundle console", bundler: "< 3", readline: true do it "doesn't load other groups" do bundle "console test" do |input, _, _| - input.puts("puts RACK_MIDDLEWARE") + input.puts("puts MYRACK_MIDDLEWARE") input.puts("exit") end expect(out).to include("NameError") @@ -122,10 +122,10 @@ RSpec.describe "bundle console", bundler: "< 3", readline: true do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development gem "foo" G diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb index 666b23a141..744510cd40 100644 --- a/spec/bundler/commands/doctor_spec.rb +++ b/spec/bundler/commands/doctor_spec.rb @@ -8,8 +8,8 @@ require "bundler/cli/doctor" RSpec.describe "bundle doctor" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G @stdout = StringIO.new @@ -52,7 +52,7 @@ RSpec.describe "bundle doctor" do it "exits with no message if the installed gem's C extension dylib breakage is fine" do doctor = Bundler::CLI::Doctor.new({}) - expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/rack/rack.bundle"] + expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"] allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true) expect { doctor.run }.not_to raise_error @@ -61,13 +61,13 @@ RSpec.describe "bundle doctor" do it "exits with a message if one of the linked libraries is missing" do doctor = Bundler::CLI::Doctor.new({}) - expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/rack/rack.bundle"] + expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"] allow(Fiddle).to receive(:dlopen).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_raise(Fiddle::DLError) expect { doctor.run }.to raise_error(Bundler::ProductionError, <<~E.strip), @stdout.string The following gems are missing OS dependencies: * bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib - * rack: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib + * myrack: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib E end end diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index 9f5f12739a..832a28e361 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true RSpec.describe "bundle exec" do - let(:system_gems_to_install) { %w[rack-1.0.0 rack-0.9.1] } + let(:system_gems_to_install) { %w[myrack-1.0.0 myrack-0.9.1] } it "works with --gemfile flag" do system_gems(system_gems_to_install, path: default_bundle_path) - create_file "CustomGemfile", <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + gemfile "CustomGemfile", <<-G + source "https://gem.repo1" + gem "myrack", "1.0.0" G - bundle "exec --gemfile CustomGemfile rackup" + bundle "exec --gemfile CustomGemfile myrackup" expect(out).to eq("1.0.0") end @@ -19,11 +19,11 @@ RSpec.describe "bundle exec" do system_gems(system_gems_to_install, path: default_bundle_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G - bundle "exec rackup" + bundle "exec myrackup" expect(out).to eq("0.9.1") end @@ -31,86 +31,69 @@ RSpec.describe "bundle exec" do system_gems(system_gems_to_install, path: default_bundle_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G - bundle "exec rackup", env: { "HOME" => "/" } + bundle "exec myrackup", env: { "HOME" => "/" } expect(out).to eq("0.9.1") expect(err).to be_empty end it "works when the bins are in ~/.bundle" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "exec rackup" + bundle "exec myrackup" expect(out).to eq("1.0.0") end it "works when running from a random directory" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && myrackup'" expect(out).to eq("1.0.0") end it "works when exec'ing something else" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" bundle "exec echo exec" expect(out).to eq("exec") end it "works when exec'ing to ruby" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" bundle "exec ruby -e 'puts %{hi}'" expect(out).to eq("hi") end it "works when exec'ing to rubygems" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" bundle "exec #{gem_cmd} --version" expect(out).to eq(Gem::VERSION) end it "works when exec'ing to rubygems through sh -c" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" bundle "exec sh -c '#{gem_cmd} --version'" expect(out).to eq(Gem::VERSION) end - it "works when exec'ing back to bundler with a lockfile that doesn't include the current platform" do + it "works when exec'ing back to bundler to run a remote resolve" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G - # simulate lockfile generated with old version not including specific platform - lockfile <<-L - GEM - remote: #{file_uri_for(gem_repo1)}/ - specs: - rack (0.9.1) + bundle "exec bundle lock", env: { "BUNDLER_VERSION" => Bundler::VERSION } - PLATFORMS - RUBY - - DEPENDENCIES - rack (= 0.9.1) - - BUNDLED WITH - 2.1.4 - L - - bundle "exec bundle cache", env: { "BUNDLER_VERSION" => Bundler::VERSION } - - expect(out).to include("Updating files in vendor/cache") + expect(out).to include("Writing lockfile") end it "respects custom process title when loading through ruby" do @@ -120,20 +103,20 @@ RSpec.describe "bundle exec" do Process.setproctitle("1-2-3-4-5-6-7") puts `ps -ocommand= -p#{$$}` RUBY - create_file "Gemfile", "source \"#{file_uri_for(gem_repo1)}\"" + gemfile "Gemfile", "source \"https://gem.repo1\"" create_file "a.rb", script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility bundle "exec ruby a.rb" expect(out).to eq("1-2-3-4-5-6-7") end it "accepts --verbose" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" bundle "exec --verbose echo foobar" expect(out).to eq("foobar") end it "passes --verbose to command if it is given after the command" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" bundle "exec echo --verbose" expect(out).to eq("--verbose") end @@ -157,7 +140,7 @@ RSpec.describe "bundle exec" do end G - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source \"https://gem.repo1\"" sys_exec "#{Gem.ruby} #{command.path}" expect(out).to be_empty @@ -165,7 +148,7 @@ RSpec.describe "bundle exec" do end it "accepts --keep-file-descriptors" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source \"https://gem.repo1\"" bundle "exec --keep-file-descriptors echo foobar" expect(err).to be_empty @@ -174,7 +157,7 @@ RSpec.describe "bundle exec" do it "can run a command named --verbose" do skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"; gem \"rack\"" + install_gemfile "source \"https://gem.repo1\"; gem \"myrack\"" File.open(bundled_app("--verbose"), "w") do |f| f.puts "#!/bin/sh" f.puts "echo foobar" @@ -188,26 +171,26 @@ RSpec.describe "bundle exec" do it "handles different versions in different bundles" do build_repo2 do - build_gem "rack_two", "1.0.0" do |s| - s.executables = "rackup" + build_gem "myrack_two", "1.0.0" do |s| + s.executables = "myrackup" end end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G install_gemfile bundled_app2("Gemfile"), <<-G, dir: bundled_app2 - source "#{file_uri_for(gem_repo2)}" - gem "rack_two", "1.0.0" + source "https://gem.repo2" + gem "myrack_two", "1.0.0" G - bundle "exec rackup" + bundle "exec myrackup" expect(out).to eq("0.9.1") - bundle "exec rackup", dir: bundled_app2 + bundle "exec myrackup", dir: bundled_app2 expect(out).to eq("1.0.0") end @@ -218,7 +201,7 @@ RSpec.describe "bundle exec" do before do skip "irb isn't a default gem" if default_irb_version.empty? - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source \"https://gem.repo1\"" end it "uses version provided by ruby" do @@ -241,7 +224,7 @@ RSpec.describe "bundle exec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "irb", "#{specified_irb_version}" G end @@ -271,7 +254,7 @@ RSpec.describe "bundle exec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "gem_depending_on_old_irb" G @@ -287,54 +270,54 @@ RSpec.describe "bundle exec" do it "warns about executable conflicts" do build_repo2 do - build_gem "rack_two", "1.0.0" do |s| - s.executables = "rackup" + build_gem "myrack_two", "1.0.0" do |s| + s.executables = "myrackup" end end bundle "config set --global path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G install_gemfile bundled_app2("Gemfile"), <<-G, dir: bundled_app2 - source "#{file_uri_for(gem_repo2)}" - gem "rack_two", "1.0.0" + source "https://gem.repo2" + gem "myrack_two", "1.0.0" G - bundle "exec rackup" + bundle "exec myrackup" expect(last_command.stderr).to eq( - "Bundler is using a binstub that was created for a different gem (rack).\n" \ - "You should run `bundle binstub rack_two` to work around a system/bundle conflict." + "Bundler is using a binstub that was created for a different gem (myrack).\n" \ + "You should run `bundle binstub myrack_two` to work around a system/bundle conflict." ) end it "handles gems installed with --without" do bundle "config set --local without middleware" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" # rack 0.9.1 and 1.0 exist + source "https://gem.repo1" + gem "myrack" # myrack 0.9.1 and 1.0 exist group :middleware do - gem "rack_middleware" # rack_middleware depends on rack 0.9.1 + gem "myrack_middleware" # myrack_middleware depends on myrack 0.9.1 end G - bundle "exec rackup" + bundle "exec myrackup" expect(out).to eq("0.9.1") - expect(the_bundle).not_to include_gems "rack_middleware 1.0" + expect(the_bundle).not_to include_gems "myrack_middleware 1.0" end it "does not duplicate already exec'ed RUBYOPT" do skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundler_setup_opt = "-r#{lib_dir}/bundler/setup" @@ -352,8 +335,8 @@ RSpec.describe "bundle exec" do skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G rubylib = ENV["RUBYLIB"] @@ -369,8 +352,8 @@ RSpec.describe "bundle exec" do it "errors nicely when the argument doesn't exist" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "exec foobarbaz", raise_on_error: false @@ -381,8 +364,8 @@ RSpec.describe "bundle exec" do it "errors nicely when the argument is not executable" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "exec touch foo" @@ -393,8 +376,8 @@ RSpec.describe "bundle exec" do it "errors nicely when no arguments are passed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "exec", raise_on_error: false @@ -405,15 +388,15 @@ RSpec.describe "bundle exec" do it "raises a helpful error when exec'ing to something outside of the bundle" do system_gems(system_gems_to_install, path: default_bundle_path) - bundle "config set clean false" # want to keep the rackup binstub + bundle "config set clean false" # want to keep the myrackup binstub install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G [true, false].each do |l| bundle "config set disable_exec_load #{l}" - bundle "exec rackup", raise_on_error: false - expect(err).to include "can't find executable rackup for gem rack. rack is not currently included in the bundle, perhaps you meant to add it to your Gemfile?" + bundle "exec myrackup", raise_on_error: false + expect(err).to include "can't find executable myrackup for gem myrack. myrack is not currently included in the bundle, perhaps you meant to add it to your Gemfile?" end end @@ -427,8 +410,8 @@ RSpec.describe "bundle exec" do skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G create_file("print_args", <<-'RUBY') @@ -512,19 +495,19 @@ RSpec.describe "bundle exec" do describe "run from a random directory" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end it "works when unlocked" do - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && myrackup'" expect(out).to eq("1.0.0") end it "works when locked" do expect(the_bundle).to be_locked - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && myrackup'" expect(out).to eq("1.0.0") end end @@ -536,7 +519,7 @@ RSpec.describe "bundle exec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "fizz", :path => "#{File.expand_path(home("fizz"))}" G end @@ -561,7 +544,7 @@ RSpec.describe "bundle exec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "fizz_git", :git => "#{lib_path("fizz_git-1.0")}" G end @@ -585,7 +568,7 @@ RSpec.describe "bundle exec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "fizz_no_gemspec", "1.0", :git => "#{lib_path("fizz_no_gemspec-1.0")}" G end @@ -605,13 +588,13 @@ RSpec.describe "bundle exec" do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" gem "foo" G bundle "config set auto_install 1" - bundle "exec rackup" + bundle "exec myrackup" expect(out).to include("Installing foo 1.0") end @@ -620,14 +603,14 @@ RSpec.describe "bundle exec" do s.executables = "foo" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" gem "foo", :git => "#{lib_path("foo-1.0")}" G bundle "config set auto_install 1" bundle "exec foo" - expect(out).to include("Fetching rack 0.9.1") + expect(out).to include("Fetching myrack 0.9.1") expect(out).to include("Fetching #{lib_path("foo-1.0")}") expect(out.lines).to end_with("1.0") end @@ -653,7 +636,7 @@ RSpec.describe "bundle exec" do bundle "config set --local path vendor/bundle" gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "fastlane" G @@ -674,19 +657,20 @@ RSpec.describe "bundle exec" do s.version = '1.0' s.summary = 'TODO: Add summary' s.authors = 'Me' + s.rubygems_version = nil end G end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" G bundle "exec irb", raise_on_error: false expect(err).to match("The gemspec at #{lib_path("foo-1.0").join("foo.gemspec")} is not valid") - expect(err).to match('"TODO" is not a summary') + expect(err).to match(/missing value for attribute rubygems_version|rubygems_version must not be nil/) end end @@ -695,7 +679,7 @@ RSpec.describe "bundle exec" do skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" module Monkey def bin_path(a,b,c) @@ -717,10 +701,10 @@ RSpec.describe "bundle exec" do let(:executable) { <<~RUBY.strip } #{shebang} - require "rack" + require "myrack" puts "EXEC: \#{caller.grep(/load/).empty? ? 'exec' : 'load'}" puts "ARGS: \#{$0} \#{ARGV.join(' ')}" - puts "RACK: \#{RACK}" + puts "MYRACK: \#{MYRACK}" process_title = `ps -o args -p \#{Process.pid}`.split("\n", 2).last.strip puts "PROCESS: \#{process_title}" RUBY @@ -732,21 +716,21 @@ RSpec.describe "bundle exec" do bundled_app(path).chmod(0o755) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end let(:exec) { "EXEC: load" } let(:args) { "ARGS: #{path} arg1 arg2" } - let(:rack) { "RACK: 1.0.0" } + let(:myrack) { "MYRACK: 1.0.0" } let(:process) do title = "PROCESS: #{path}" title += " arg1 arg2" title end let(:exit_code) { 0 } - let(:expected) { [exec, args, rack, process].join("\n") } + let(:expected) { [exec, args, myrack, process].join("\n") } let(:expected_err) { "" } subject { bundle "exec #{path} arg1 arg2", raise_on_error: false } @@ -876,8 +860,8 @@ RSpec.describe "bundle exec" do context "when Bundler.setup fails", bundler: "< 3" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', '2' + source "https://gem.repo1" + gem 'myrack', '2' G ENV["BUNDLER_FORCE_TTY"] = "true" end @@ -885,11 +869,11 @@ RSpec.describe "bundle exec" do let(:exit_code) { Bundler::GemNotFound.new.status_code } let(:expected) { "" } let(:expected_err) { <<-EOS.strip } -Could not find gem 'rack (= 2)' in locally installed gems. +Could not find gem 'myrack (= 2)' in locally installed gems. -The source contains the following gems matching 'rack': - * rack-0.9.1 - * rack-1.0.0 +The source contains the following gems matching 'myrack': + * myrack-0.9.1 + * myrack-1.0.0 Run `bundle install` to install missing gems. EOS @@ -906,8 +890,8 @@ Run `bundle install` to install missing gems. context "when Bundler.setup fails", bundler: "3" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', '2' + source "https://gem.repo1" + gem 'myrack', '2' G ENV["BUNDLER_FORCE_TTY"] = "true" end @@ -915,10 +899,10 @@ Run `bundle install` to install missing gems. let(:exit_code) { Bundler::GemNotFound.new.status_code } let(:expected) { "" } let(:expected_err) { <<-EOS.strip } -Could not find gem 'rack (= 2)' in locally installed gems. +Could not find gem 'myrack (= 2)' in locally installed gems. -The source contains the following gems matching 'rack': - * rack-1.0.0 +The source contains the following gems matching 'myrack': + * myrack-1.0.0 Run `bundle install` to install missing gems. EOS @@ -934,9 +918,9 @@ Run `bundle install` to install missing gems. context "when Bundler.setup fails and Gemfile is not the default" do before do - create_file "CustomGemfile", <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', '2' + gemfile "CustomGemfile", <<-G + source "https://gem.repo1" + gem 'myrack', '2' G ENV["BUNDLER_FORCE_TTY"] = "true" ENV["BUNDLE_GEMFILE"] = "CustomGemfile" @@ -1098,8 +1082,8 @@ __FILE__: #{path.to_s.inspect} skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set path vendor/bundler" bundle :install @@ -1121,7 +1105,7 @@ __FILE__: #{path.to_s.inspect} before do skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source \"https://gem.repo1\"" end it "does not undo the monkeypatches" do @@ -1171,18 +1155,18 @@ __FILE__: #{path.to_s.inspect} end bundle "config set path vendor/bundle" - bundle "config set gemfile gemfiles/rack_6_1.gemfile" + bundle "config set gemfile gemfiles/myrack_6_1.gemfile" - create_file(bundled_app("gemfiles/rack_6_1.gemfile"), <<~RUBY) - source "#{file_uri_for(gem_repo2)}" + gemfile(bundled_app("gemfiles/myrack_6_1.gemfile"), <<~RUBY) + source "https://gem.repo2" gem "rails", "6.1.0" RUBY # A Gemfile needs to be in the root to trick bundler's root resolution - create_file(bundled_app("Gemfile"), "source \"#{file_uri_for(gem_repo1)}\"") + gemfile "source 'https://gem.repo1'" - bundle "install" + bundle "install", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } end it "can still find gems after a nested subprocess" do @@ -1211,7 +1195,7 @@ __FILE__: #{path.to_s.inspect} skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform? skip "openssl isn't a default gem" if expected.empty? - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" # must happen before installing the broken system gem + install_gemfile "source \"https://gem.repo1\"" # must happen before installing the broken system gem build_repo4 do build_gem "openssl", openssl_version do |s| @@ -1252,7 +1236,7 @@ __FILE__: #{path.to_s.inspect} build_git "simple_git_binary", &:add_c_extension bundle "config set --local path .bundle" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "simple_git_binary", :git => '#{lib_path("simple_git_binary-1.0")}' G end diff --git a/spec/bundler/commands/fund_spec.rb b/spec/bundler/commands/fund_spec.rb index 5415b88eeb..6f4e61da30 100644 --- a/spec/bundler/commands/fund_spec.rb +++ b/spec/bundler/commands/fund_spec.rb @@ -30,22 +30,22 @@ RSpec.describe "bundle fund" do it "prints fund information for all gems in the bundle" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding_and_other_metadata' gem 'has_funding' - gem 'rack-obama' + gem 'myrack-obama' G bundle "fund" expect(out).to include("* has_funding_and_other_metadata (1.0)\n Funding: https://example.com/has_funding_and_other_metadata/funding") expect(out).to include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") - expect(out).to_not include("rack-obama") + expect(out).to_not include("myrack-obama") end it "does not consider fund information for gem dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'gem_with_dependent_funding' G @@ -55,10 +55,46 @@ RSpec.describe "bundle fund" do expect(out).to_not include("gem_with_dependent_funding") end + it "does not consider fund information for uninstalled optional dependencies" do + install_gemfile <<-G + source "https://gem.repo2" + group :whatever, optional: true do + gem 'has_funding_and_other_metadata' + end + gem 'has_funding' + gem 'myrack-obama' + G + + bundle "fund" + + expect(out).to include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") + expect(out).to_not include("has_funding_and_other_metadata") + expect(out).to_not include("myrack-obama") + end + + it "considers fund information for installed optional dependencies" do + bundle "config set with whatever" + + install_gemfile <<-G + source "https://gem.repo2" + group :whatever, optional: true do + gem 'has_funding_and_other_metadata' + end + gem 'has_funding' + gem 'myrack-obama' + G + + bundle "fund" + + expect(out).to include("* has_funding_and_other_metadata (1.0)\n Funding: https://example.com/has_funding_and_other_metadata/funding") + expect(out).to include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") + expect(out).to_not include("myrack-obama") + end + it "prints message if none of the gems have fund information" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack-obama' + source "https://gem.repo2" + gem 'myrack-obama' G bundle "fund" @@ -69,7 +105,7 @@ RSpec.describe "bundle fund" do describe "with --group option" do it "prints fund message for only specified group gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding_and_other_metadata', :group => :development gem 'has_funding' G diff --git a/spec/bundler/commands/info_spec.rb b/spec/bundler/commands/info_spec.rb index a5a09bc147..42f288a1d8 100644 --- a/spec/bundler/commands/info_spec.rb +++ b/spec/bundler/commands/info_spec.rb @@ -18,7 +18,7 @@ RSpec.describe "bundle info" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" gem "has_metadata" gem "thin" @@ -127,9 +127,9 @@ RSpec.describe "bundle info" do context "when gem has a reverse dependency on any version" do it "prints the details" do - bundle "info rack" + bundle "info myrack" - expect(out).to include("Reverse Dependencies: \n\t\tthin (1.0) depends on rack (>= 0)") + expect(out).to include("Reverse Dependencies: \n\t\tthin (1.0) depends on myrack (>= 0)") end end @@ -157,7 +157,7 @@ RSpec.describe "bundle info" do it "prints out git info" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G expect(the_bundle).to include_gems "foo 1.0" @@ -173,7 +173,7 @@ RSpec.describe "bundle info" do @revision = revision_for(lib_path("foo-1.0"))[0...6] install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "omg" G expect(the_bundle).to include_gems "foo 1.0.omg" @@ -185,7 +185,7 @@ RSpec.describe "bundle info" do it "doesn't print the branch when tied to a ref" do sha = revision_for(lib_path("foo-1.0")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{sha}" G @@ -196,7 +196,7 @@ RSpec.describe "bundle info" do it "handles when a version is a '-' prerelease" do @git = build_git("foo", "1.0.0-beta.1", path: lib_path("foo")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.0.0-beta.1", :git => "#{lib_path("foo")}" G expect(the_bundle).to include_gems "foo 1.0.0.pre.beta.1" @@ -209,20 +209,20 @@ RSpec.describe "bundle info" do context "with a valid regexp for gem name" do it "presents alternatives", :readline do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G bundle "info rac" - expect(out).to match(/\A1 : rack\n2 : rack-obama\n0 : - exit -(\n>.*)?\z/) + expect(out).to match(/\A1 : myrack\n2 : myrack-obama\n0 : - exit -(\n>|\z)/) end end context "with an invalid regexp for gem name" do it "does not find the gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -238,7 +238,7 @@ RSpec.describe "bundle info" do bundle "config without test" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails", group: :test G diff --git a/spec/bundler/commands/init_spec.rb b/spec/bundler/commands/init_spec.rb index 0a1336572a..538e61fd47 100644 --- a/spec/bundler/commands/init_spec.rb +++ b/spec/bundler/commands/init_spec.rb @@ -32,7 +32,7 @@ RSpec.describe "bundle init" do context "when a Gemfile already exists" do before do - create_file "Gemfile", <<-G + gemfile <<-G gem "rails" G end @@ -79,14 +79,14 @@ RSpec.describe "bundle init" do end context "given --gemspec option" do - let(:spec_file) { tmp.join("test.gemspec") } + let(:spec_file) { tmp("test.gemspec") } it "should generate from an existing gemspec" do File.open(spec_file, "w") do |file| file << <<-S Gem::Specification.new do |s| s.name = 'test' - s.add_dependency 'rack', '= 1.0.1' + s.add_dependency 'myrack', '= 1.0.1' s.add_development_dependency 'rspec', '1.2' end S @@ -96,7 +96,7 @@ RSpec.describe "bundle init" do gemfile = bundled_app_gemfile.read expect(gemfile).to match(%r{source 'https://rubygems.org'}) - expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) + expect(gemfile.scan(/gem "myrack", "= 1.0.1"/).size).to eq(1) expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) expect(gemfile.scan(/group :development/).size).to eq(1) end @@ -129,7 +129,7 @@ RSpec.describe "bundle init" do context "when gems.rb already exists" do before do - create_file("gems.rb", <<-G) + gemfile("gems.rb", <<-G) gem "rails" G end @@ -160,14 +160,14 @@ RSpec.describe "bundle init" do end context "given --gemspec option" do - let(:spec_file) { tmp.join("test.gemspec") } + let(:spec_file) { tmp("test.gemspec") } before do File.open(spec_file, "w") do |file| file << <<-S Gem::Specification.new do |s| s.name = 'test' - s.add_dependency 'rack', '= 1.0.1' + s.add_dependency 'myrack', '= 1.0.1' s.add_development_dependency 'rspec', '1.2' end S @@ -179,7 +179,7 @@ RSpec.describe "bundle init" do gemfile = bundled_app("gems.rb").read expect(gemfile).to match(%r{source 'https://rubygems.org'}) - expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) + expect(gemfile.scan(/gem "myrack", "= 1.0.1"/).size).to eq(1) expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) expect(gemfile.scan(/group :development/).size).to eq(1) end diff --git a/spec/bundler/commands/inject_spec.rb b/spec/bundler/commands/inject_spec.rb index 255a03c135..193806a02a 100644 --- a/spec/bundler/commands/inject_spec.rb +++ b/spec/bundler/commands/inject_spec.rb @@ -3,16 +3,16 @@ RSpec.describe "bundle inject", bundler: "< 3" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end context "without a lockfile" do it "locks with the injected gems" do expect(bundled_app_lock).not_to exist - bundle "inject 'rack-obama' '> 0'" - expect(bundled_app_lock.read).to match(/rack-obama/) + bundle "inject 'myrack-obama' '> 0'" + expect(bundled_app_lock.read).to match(/myrack-obama/) end end @@ -22,21 +22,21 @@ RSpec.describe "bundle inject", bundler: "< 3" do end it "adds the injected gems to the Gemfile" do - expect(bundled_app_gemfile.read).not_to match(/rack-obama/) - bundle "inject 'rack-obama' '> 0'" - expect(bundled_app_gemfile.read).to match(/rack-obama/) + expect(bundled_app_gemfile.read).not_to match(/myrack-obama/) + bundle "inject 'myrack-obama' '> 0'" + expect(bundled_app_gemfile.read).to match(/myrack-obama/) end it "locks with the injected gems" do - expect(bundled_app_lock.read).not_to match(/rack-obama/) - bundle "inject 'rack-obama' '> 0'" - expect(bundled_app_lock.read).to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/myrack-obama/) + bundle "inject 'myrack-obama' '> 0'" + expect(bundled_app_lock.read).to match(/myrack-obama/) end end context "with injected gems already in the Gemfile" do it "doesn't add existing gems" do - bundle "inject 'rack' '> 0'", raise_on_error: false + bundle "inject 'myrack' '> 0'", raise_on_error: false expect(err).to match(/cannot specify the same gem twice/i) end end @@ -53,25 +53,25 @@ Usage: "bundle inject GEM VERSION" context "with source option" do it "add gem with source option in gemfile" do - bundle "inject 'foo' '>0' --source #{file_uri_for(gem_repo1)}" + bundle "inject 'foo' '>0' --source https://gem.repo1" gemfile = bundled_app_gemfile.read - str = "gem \"foo\", \"> 0\", :source => \"#{file_uri_for(gem_repo1)}\"" + str = "gem \"foo\", \"> 0\", :source => \"https://gem.repo1\"" 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" + bundle "inject 'myrack-obama' '>0' --group=development" gemfile = bundled_app_gemfile.read - str = "gem \"rack-obama\", \"> 0\", :group => :development" + str = "gem \"myrack-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" + bundle "inject 'myrack-obama' '>0' --group=development,test" gemfile = bundled_app_gemfile.read - str = "gem \"rack-obama\", \"> 0\", :groups => [:development, :test]" + str = "gem \"myrack-obama\", \"> 0\", :groups => [:development, :test]" expect(gemfile).to include str end end @@ -87,31 +87,31 @@ Usage: "bundle inject GEM VERSION" end it "injects anyway" do - bundle "inject 'rack-obama' '> 0'" - expect(bundled_app_gemfile.read).to match(/rack-obama/) + bundle "inject 'myrack-obama' '> 0'" + expect(bundled_app_gemfile.read).to match(/myrack-obama/) end it "locks with the injected gems" do - expect(bundled_app_lock.read).not_to match(/rack-obama/) - bundle "inject 'rack-obama' '> 0'" - expect(bundled_app_lock.read).to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/myrack-obama/) + bundle "inject 'myrack-obama' '> 0'" + expect(bundled_app_lock.read).to match(/myrack-obama/) end it "restores frozen afterwards" do - bundle "inject 'rack-obama' '> 0'" + bundle "inject 'myrack-obama' '> 0'" config = Psych.load(bundled_app(".bundle/config").read) expect(config["BUNDLE_DEPLOYMENT"] || config["BUNDLE_FROZEN"]).to eq("true") end it "doesn't allow Gemfile changes" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack-obama" G - bundle "inject 'rack' '> 0'", raise_on_error: false + bundle "inject 'myrack' '> 0'", raise_on_error: false expect(err).to match(/the lockfile can't be updated because frozen mode is set/) - expect(bundled_app_lock.read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/myrack-obama/) end end end diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index edc5887d7b..dc92aab35d 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle install with gem sources" do describe "the simple case" do it "prints output and returns if no dependencies are specified" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G bundle :install @@ -22,8 +22,8 @@ RSpec.describe "bundle install with gem sources" do it "creates a Gemfile.lock" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G expect(bundled_app_lock).to exist @@ -31,8 +31,8 @@ RSpec.describe "bundle install with gem sources" do it "does not create ./.bundle by default", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :install # can't use install_gemfile since it sets retry @@ -41,8 +41,8 @@ RSpec.describe "bundle install with gem sources" do it "does not create ./.bundle by default when installing to system gems" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :install, env: { "BUNDLE_PATH__SYSTEM" => "true" } # can't use install_gemfile since it sets retry @@ -51,8 +51,8 @@ RSpec.describe "bundle install with gem sources" do it "creates lock files based on the Gemfile name" do gemfile bundled_app("OmgFile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0" + source "https://gem.repo1" + gem "myrack", "1.0" G bundle "install --gemfile OmgFile" @@ -62,8 +62,8 @@ RSpec.describe "bundle install with gem sources" do it "doesn't delete the lockfile if one already exists" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G lockfile = File.read(bundled_app_lock) @@ -77,8 +77,8 @@ RSpec.describe "bundle install with gem sources" do it "does not touch the lockfile if nothing changed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G expect { run "1" }.not_to change { File.mtime(bundled_app_lock) } @@ -86,60 +86,60 @@ RSpec.describe "bundle install with gem sources" do it "fetches gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G - expect(default_bundle_path("gems/rack-1.0.0")).to exist - expect(the_bundle).to include_gems("rack 1.0.0") + expect(default_bundle_path("gems/myrack-1.0.0")).to exist + expect(the_bundle).to include_gems("myrack 1.0.0") end it "auto-heals missing gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G - FileUtils.rm_rf(default_bundle_path("gems/rack-1.0.0")) + FileUtils.rm_rf(default_bundle_path("gems/myrack-1.0.0")) bundle "install --verbose" - expect(out).to include("Installing rack 1.0.0") - expect(default_bundle_path("gems/rack-1.0.0")).to exist - expect(the_bundle).to include_gems("rack 1.0.0") + expect(out).to include("Installing myrack 1.0.0") + expect(default_bundle_path("gems/myrack-1.0.0")).to exist + expect(the_bundle).to include_gems("myrack 1.0.0") end it "fetches gems when multiple versions are specified" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', "> 0.9", "< 1.0" + source "https://gem.repo1" + gem 'myrack', "> 0.9", "< 1.0" G - expect(default_bundle_path("gems/rack-0.9.1")).to exist - expect(the_bundle).to include_gems("rack 0.9.1") + expect(default_bundle_path("gems/myrack-0.9.1")).to exist + expect(the_bundle).to include_gems("myrack 0.9.1") end it "fetches gems when multiple versions are specified take 2" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', "< 1.0", "> 0.9" + source "https://gem.repo1" + gem 'myrack', "< 1.0", "> 0.9" G - expect(default_bundle_path("gems/rack-0.9.1")).to exist - expect(the_bundle).to include_gems("rack 0.9.1") + expect(default_bundle_path("gems/myrack-0.9.1")).to exist + expect(the_bundle).to include_gems("myrack 0.9.1") end it "raises an appropriate error when gems are specified using symbols" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem :rack + source "https://gem.repo1" + gem :myrack G expect(exitstatus).to eq(4) end it "pulls in dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -148,11 +148,11 @@ RSpec.describe "bundle install with gem sources" do it "does the right version" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G - expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).to include_gems "myrack 0.9.1" end it "does not install the development dependency" do @@ -163,7 +163,7 @@ RSpec.describe "bundle install with gem sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "with_development_dependency" G @@ -173,7 +173,7 @@ RSpec.describe "bundle install with gem sources" do it "resolves correctly" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activemerchant" gem "rails" G @@ -183,12 +183,12 @@ RSpec.describe "bundle install with gem sources" do it "activates gem correctly according to the resolved gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", "2.3.5" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activemerchant" gem "rails" G @@ -206,7 +206,7 @@ RSpec.describe "bundle install with gem sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activerecord", "2.3.2" G @@ -216,25 +216,23 @@ RSpec.describe "bundle install with gem sources" do it "works when the gemfile specifies gems that only exist in the system" do build_gem "foo", to_bundle: true install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "foo" G - expect(the_bundle).to include_gems "rack 1.0.0", "foo 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0", "foo 1.0.0" end it "prioritizes local gems over remote gems" do - build_gem "rack", "1.0.0", to_bundle: true do |s| - s.add_dependency "activesupport", "2.3.5" - end + build_gem "myrack", "9.0.0", to_bundle: true install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.5" + expect(the_bundle).to include_gems "myrack 9.0.0" end it "loads env plugins" do @@ -242,8 +240,8 @@ RSpec.describe "bundle install with gem sources" do create_file "plugins/rubygems_plugin.rb", "puts '#{plugin_msg}'" rubylib = ENV["RUBYLIB"].to_s.split(File::PATH_SEPARATOR).unshift(bundled_app("plugins").to_s).join(File::PATH_SEPARATOR) install_gemfile <<-G, env: { "RUBYLIB" => rubylib } - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G expect(last_command.stdboth).to include(plugin_msg) @@ -251,102 +249,96 @@ RSpec.describe "bundle install with gem sources" do describe "with a gem that installs multiple platforms" do it "installs gems for the local platform as first choice" do - skip "version is 1.0, not 1.0.0" if Gem.win_platform? - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 #{Bundler.local_platform}") + expect(the_bundle).to include_gems("platform_specific 1.0 #{Bundler.local_platform}") end it "falls back on plain ruby" do simulate_platform "foo-bar-baz" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 RUBY") + expect(the_bundle).to include_gems("platform_specific 1.0 ruby") end it "installs gems for java" do simulate_platform "java" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 JAVA") + expect(the_bundle).to include_gems("platform_specific 1.0 java") end it "installs gems for windows" do simulate_platform x86_mswin32 install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0 x86-mswin32") + expect(the_bundle).to include_gems("platform_specific 1.0 x86-mswin32") end end describe "doing bundle install foo" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end it "works" do bundle "config set --local path vendor" bundle "install" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "allows running bundle install --system without deleting foo", bundler: "< 3" do bundle "install --path vendor" bundle "install --system" FileUtils.rm_rf(bundled_app("vendor")) - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "allows running bundle install --system after deleting foo", bundler: "< 3" do bundle "install --path vendor" FileUtils.rm_rf(bundled_app("vendor")) bundle "install --system" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end it "finds gems in multiple sources", bundler: "< 3" do build_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - source "#{file_uri_for(gem_repo2)}" + install_gemfile <<-G, artifice: "compact_index_extra" + source "https://gemserver.test" + source "https://gemserver.test/extra" gem "activesupport", "1.2.3" - gem "rack", "1.2" + gem "myrack", "1.2" G - expect(the_bundle).to include_gems "rack 1.2", "activesupport 1.2.3" + expect(the_bundle).to include_gems "myrack 1.2", "activesupport 1.2.3" end it "gives a useful error if no sources are set" do install_gemfile <<-G, raise_on_error: false - gem "rack" + gem "myrack" G expect(err).to include("This Gemfile does not include an explicit global source. " \ @@ -357,7 +349,7 @@ RSpec.describe "bundle install with gem sources" do it "creates a Gemfile.lock on a blank Gemfile" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G expect(File.exist?(bundled_app_lock)).to eq(true) @@ -367,12 +359,12 @@ RSpec.describe "bundle install with gem sources" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" - gem "rack" + source "https://gem.repo2" + gem "myrack" + gem "myrack" G - expect(err).to include("Your Gemfile lists the gem rack (>= 0) more than once.") + expect(err).to include("Your Gemfile lists the gem myrack (>= 0) more than once.") expect(err).to include("Remove any duplicate entries and specify the gem only once.") expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") end @@ -381,12 +373,12 @@ RSpec.describe "bundle install with gem sources" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", "1.0" - gem "rack", "1.0" + source "https://gem.repo2" + gem "myrack", "1.0" + gem "myrack", "1.0" G - expect(err).to include("Your Gemfile lists the gem rack (= 1.0) more than once.") + expect(err).to include("Your Gemfile lists the gem myrack (= 1.0) more than once.") expect(err).to include("Remove any duplicate entries and specify the gem only once.") expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") end @@ -395,14 +387,14 @@ RSpec.describe "bundle install with gem sources" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", :platform => :jruby - gem "rack" + source "https://gem.repo2" + gem "myrack", :platform => :jruby + gem "myrack" G bundle "install" - expect(err).to include("Your Gemfile lists the gem rack (>= 0) more than once.") + expect(err).to include("Your Gemfile lists the gem myrack (>= 0) more than once.") expect(err).to include("Remove any duplicate entries and specify the gem only once.") expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") end @@ -417,7 +409,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gemspec @@ -441,7 +433,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec @@ -461,8 +453,8 @@ RSpec.describe "bundle install with gem sources" do end it "includes the gem without warning if two gemspecs add it with the same requirement" do - gem1 = tmp.join("my-gem-1") - gem2 = tmp.join("my-gem-2") + gem1 = tmp("my-gem-1") + gem2 = tmp("my-gem-2") build_lib "my-gem", path: gem1 do |s| s.add_development_dependency "rubocop", "~> 1.36.0" @@ -477,7 +469,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec path: "#{gem1}" gemspec path: "#{gem2}" @@ -499,7 +491,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rails", "~> 7.0.8" @@ -530,11 +522,11 @@ RSpec.describe "bundle install with gem sources" do build_git "activesupport", "1.0", path: lib_path("activesupport") install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec - gem "activesupport", :git => "#{file_uri_for(lib_path("activesupport"))}" + gem "activesupport", :git => "#{lib_path("activesupport")}" G expect(err).to be_empty @@ -542,9 +534,9 @@ RSpec.describe "bundle install with gem sources" do # if the Gemfile dependency is specified first install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" - gem "activesupport", :git => "#{file_uri_for(lib_path("activesupport"))}" + gem "activesupport", :git => "#{lib_path("activesupport")}" gemspec G @@ -564,7 +556,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec @@ -579,31 +571,31 @@ RSpec.describe "bundle install with gem sources" do it "throws an error if a gem is added twice in Gemfile when version of one dependency is not specified" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" - gem "rack" - gem "rack", "1.0" + source "https://gem.repo2" + gem "myrack" + gem "myrack", "1.0" G expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).to include("You specified: rack (>= 0) and rack (= 1.0).") + expect(err).to include("You specified: myrack (>= 0) and myrack (= 1.0).") end it "throws an error if a gem is added twice in Gemfile when different versions of both dependencies are specified" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" - gem "rack", "1.0" - gem "rack", "1.1" + source "https://gem.repo2" + gem "myrack", "1.0" + gem "myrack", "1.1" G expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).to include("You specified: rack (= 1.0) and rack (= 1.1).") + expect(err).to include("You specified: myrack (= 1.0) and myrack (= 1.1).") end it "gracefully handles error when rubygems server is unavailable" do skip "networking issue" if Gem.win_platform? install_gemfile <<-G, artifice: nil, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" source "http://0.0.0.0:9384" do gem 'foo' end @@ -627,7 +619,7 @@ RSpec.describe "bundle install with gem sources" do end install_gemfile <<-G, full_index: true, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "ajp-rails", "0.0.0" G @@ -642,7 +634,7 @@ RSpec.describe "bundle install with gem sources" do FileUtils.touch(bundled_app(".bundle/config")) install_gemfile(<<-G) - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo' G @@ -653,7 +645,7 @@ RSpec.describe "bundle install with gem sources" do FileUtils.touch("#{Bundler.rubygems.user_home}/.bundle/config") install_gemfile(<<-G) - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo' G @@ -665,7 +657,7 @@ RSpec.describe "bundle install with gem sources" do it "prints an error" do install_gemfile <<-G, raise_on_error: false ruby '~> 1.2' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G expect(err).to include("Your Ruby version is #{Gem.ruby_version}, but your Gemfile specified ~> 1.2") end @@ -675,7 +667,7 @@ RSpec.describe "bundle install with gem sources" do before do install_gemfile <<-G ruby '~> #{Gem.ruby_version}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end @@ -683,7 +675,7 @@ RSpec.describe "bundle install with gem sources" do checksums = checksums_section_when_existing expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -702,14 +694,14 @@ RSpec.describe "bundle install with gem sources" do it "updates Gemfile.lock with updated yet still compatible ruby version" do install_gemfile <<-G ruby '~> #{current_ruby_minor}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G checksums = checksums_section_when_existing expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -727,7 +719,7 @@ RSpec.describe "bundle install with gem sources" do it "does not crash when unlocking" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby '>= 2.1.0' G @@ -746,7 +738,7 @@ RSpec.describe "bundle install with gem sources" do build_lib "foo" gemfile = <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "#{lib_path("foo-1.0")}" G File.open("#{root_dir}/Gemfile", "w") do |file| @@ -763,7 +755,7 @@ RSpec.describe "bundle install with gem sources" do build_lib "foo", path: root_dir gemfile = <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G File.open("#{root_dir}/Gemfile", "w") do |file| @@ -779,8 +771,8 @@ RSpec.describe "bundle install with gem sources" do bundle "config set force_ruby_platform true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle :install, quiet: true @@ -809,7 +801,7 @@ RSpec.describe "bundle install with gem sources" do RUBY gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'non-existing-gem' G @@ -820,14 +812,14 @@ RSpec.describe "bundle install with gem sources" do end end - describe "when bundle path does not have write access", :permissions do + describe "when bundle path does not have cd permission", :permissions do let(:bundle_path) { bundled_app("vendor") } before do FileUtils.mkdir_p(bundle_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G end @@ -841,14 +833,14 @@ RSpec.describe "bundle install with gem sources" do end end - describe "when bundle gems path does not have write access", :permissions do + describe "when bundle gems path does not have cd permission", :permissions do let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") } before do FileUtils.mkdir_p(gems_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G end @@ -865,19 +857,79 @@ RSpec.describe "bundle install with gem sources" do expect(err).not_to include("ERROR REPORT TEMPLATE") expect(err).to include( - "There was an error while trying to create `#{gems_path.join("rack-1.0.0")}`. " \ + "There was an error while trying to create `#{gems_path.join("myrack-1.0.0")}`. " \ "It is likely that you need to grant executable permissions for all parent directories and write permissions for `#{gems_path}`." ) end end + describe "when bundle bin dir does not have cd permission", :permissions do + let(:bin_dir) { bundled_app("vendor/#{Bundler.ruby_scope}/bin") } + + before do + FileUtils.mkdir_p(bin_dir) + gemfile <<-G + source "https://gem.repo1" + gem 'myrack' + G + end + + it "should display a proper message to explain the problem" do + FileUtils.chmod("-x", bin_dir) + bundle "config set --local path vendor" + + begin + bundle :install, raise_on_error: false + ensure + FileUtils.chmod("+x", bin_dir) + end + + expect(err).not_to include("ERROR REPORT TEMPLATE") + + expect(err).to include( + "There was an error while trying to write to `#{bin_dir}`. " \ + "It is likely that you need to grant write permissions for that path." + ) + end + end + + describe "when bundle bin dir does not have write access", :permissions do + let(:bin_dir) { bundled_app("vendor/#{Bundler.ruby_scope}/bin") } + + before do + FileUtils.mkdir_p(bin_dir) + gemfile <<-G + source "https://gem.repo1" + gem "myrack" + G + end + + it "should display a proper message to explain the problem" do + FileUtils.chmod("-w", bin_dir) + bundle "config set --local path vendor" + + begin + bundle :install, raise_on_error: false + ensure + FileUtils.chmod("+w", bin_dir) + end + + expect(err).not_to include("ERROR REPORT TEMPLATE") + + expect(err).to include( + "There was an error while trying to write to `#{bin_dir}`. " \ + "It is likely that you need to grant write permissions for that path." + ) + end + end + describe "when bundle extensions path does not have write access", :permissions do let(:extensions_path) { bundled_app("vendor/#{Bundler.ruby_scope}/extensions/#{Gem::Platform.local}/#{Gem.extension_api_version}") } before do FileUtils.mkdir_p(extensions_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'simple_binary' G end @@ -901,7 +953,7 @@ RSpec.describe "bundle install with gem sources" do end end - describe "when the path of a specific gem is not writable", :permissions do + describe "when the path of a specific gem does not have cd permission", :permissions do let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") } let(:foo_path) { gems_path.join("foo-1.0.0") } @@ -913,7 +965,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo' G end @@ -949,7 +1001,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo' G end @@ -984,7 +1036,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo' G end @@ -1009,8 +1061,8 @@ RSpec.describe "bundle install with gem sources" do before do FileUtils.mkdir_p(cache_path) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G end @@ -1025,12 +1077,12 @@ RSpec.describe "bundle install with gem sources" do end describe "when gemspecs are unreadable", :permissions do - let(:gemspec_path) { vendored_gems("specifications/rack-1.0.0.gemspec") } + let(:gemspec_path) { vendored_gems("specifications/myrack-1.0.0.gemspec") } before do gemfile <<~G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle "config path vendor/bundle" bundle :install @@ -1050,16 +1102,16 @@ RSpec.describe "bundle install with gem sources" do context "after installing with --standalone" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set --local path bundle" bundle "install", standalone: true end it "includes the standalone path" do - bundle "binstubs rack", standalone: true - standalone_line = File.read(bundled_app("bin/rackup")).each_line.find {|line| line.include? "$:.unshift" }.strip + bundle "binstubs myrack", standalone: true + standalone_line = File.read(bundled_app("bin/myrackup")).each_line.find {|line| line.include? "$:.unshift" }.strip expect(standalone_line).to eq %($:.unshift File.expand_path "../bundle", __dir__) end end @@ -1089,14 +1141,14 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "libv8" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: libv8 (8.4.255.0-x86_64-darwin-19) @@ -1130,19 +1182,19 @@ RSpec.describe "bundle install with gem sources" do build_gem "nokogiri", "1.12.4" do |s| s.platform = "x86_64-darwin" - s.add_runtime_dependency "racca", "~> 1.4" + s.add_dependency "racca", "~> 1.4" end build_gem "nokogiri", "1.12.4" do |s| s.platform = "x86_64-linux" - s.add_runtime_dependency "racca", "~> 1.4" + s.add_dependency "racca", "~> 1.4" end build_gem "crass", "1.0.6" build_gem "loofah", "2.12.0" do |s| - s.add_runtime_dependency "crass", "~> 1.0.2" - s.add_runtime_dependency "nokogiri", ">= 1.5.9" + s.add_dependency "crass", "~> 1.0.2" + s.add_dependency "nokogiri", ">= 1.5.9" end end @@ -1235,15 +1287,15 @@ RSpec.describe "bundle install with gem sources" do context "with --local flag" do before do - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path end it "respects installed gems without fetching any remote sources" do install_gemfile <<-G, local: true - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" source "https://not-existing-source" do - gem "rack" + gem "myrack" end G @@ -1258,14 +1310,14 @@ RSpec.describe "bundle install with gem sources" do it "installs only gems of the specified groups" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" - gem "rack", group: :a + gem "myrack", group: :a gem "rake", group: :b gem "yard", group: :c G - expect(out).to include("Installing rack") + expect(out).to include("Installing myrack") expect(out).to include("Installing rake") expect(out).not_to include("Installing yard") end @@ -1284,7 +1336,7 @@ RSpec.describe "bundle install with gem sources" do it "fetches remote sources only when not available locally" do install_gemfile <<-G, "prefer-local": true, verbose: true - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "foo" gem "bar" @@ -1321,7 +1373,7 @@ RSpec.describe "bundle install with gem sources" do it "installs fine" do install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "binman" G @@ -1343,7 +1395,7 @@ RSpec.describe "bundle install with gem sources" do it "does not crash unexpectedly" do gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "autobuild", "1.10.rc2" G @@ -1366,7 +1418,7 @@ RSpec.describe "bundle install with gem sources" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "aaa" gem "zzz" @@ -1374,7 +1426,7 @@ RSpec.describe "bundle install with gem sources" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: aaa (0.2.0) zzz (< 0.2.0) @@ -1400,7 +1452,7 @@ RSpec.describe "bundle install with gem sources" do context "when --jobs option given" do before do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"", jobs: 1 + install_gemfile "source 'https://gem.repo1'", jobs: 1 end it "does not save the flag to config" do @@ -1418,7 +1470,7 @@ RSpec.describe "bundle install with gem sources" do it "shows a proper error" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1430,7 +1482,7 @@ RSpec.describe "bundle install with gem sources" do 9.99.8 L - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"", env: { "BUNDLER_VERSION" => "9.99.8" }, raise_on_error: false + install_gemfile "source \"https://gem.repo1\"", env: { "BUNDLER_VERSION" => "9.99.8" }, raise_on_error: false expect(err).not_to include("ERROR REPORT TEMPLATE") expect(err).to include("The running version of Bundler (9.99.9) does not match the version of the specification installed for it (9.99.8)") diff --git a/spec/bundler/commands/issue_spec.rb b/spec/bundler/commands/issue_spec.rb index 143f6333ce..346cdedc42 100644 --- a/spec/bundler/commands/issue_spec.rb +++ b/spec/bundler/commands/issue_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "bundle issue" do it "exits with a message" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G diff --git a/spec/bundler/commands/licenses_spec.rb b/spec/bundler/commands/licenses_spec.rb index a203984890..bfec938efd 100644 --- a/spec/bundler/commands/licenses_spec.rb +++ b/spec/bundler/commands/licenses_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "bundle licenses" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" gem "with_license" G @@ -24,7 +24,7 @@ RSpec.describe "bundle licenses" do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" gem "with_license" gem "foo" diff --git a/spec/bundler/commands/list_spec.rb b/spec/bundler/commands/list_spec.rb index 5ac2077d81..cc0db9169d 100644 --- a/spec/bundler/commands/list_spec.rb +++ b/spec/bundler/commands/list_spec.rb @@ -20,9 +20,9 @@ RSpec.describe "bundle list" do describe "with without-group option" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" gem "rspec", :group => [:test] gem "rails", :group => [:production] G @@ -32,7 +32,7 @@ RSpec.describe "bundle list" do it "prints the gems not in the specified group" do bundle "list --without-group test" - expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * myrack (1.0.0)") expect(out).to include(" * rails (2.3.2)") expect(out).not_to include(" * rspec (1.2.7)") end @@ -50,7 +50,7 @@ RSpec.describe "bundle list" do it "prints the gems not in the specified groups" do bundle "list --without-group test production" - expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * myrack (1.0.0)") expect(out).not_to include(" * rails (2.3.2)") expect(out).not_to include(" * rspec (1.2.7)") end @@ -60,9 +60,9 @@ RSpec.describe "bundle list" do describe "with only-group option" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" gem "rspec", :group => [:test] gem "rails", :group => [:production] G @@ -72,7 +72,7 @@ RSpec.describe "bundle list" do it "prints the gems in the specified group" do bundle "list --only-group default" - expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * myrack (1.0.0)") expect(out).not_to include(" * rspec (1.2.7)") end end @@ -89,7 +89,7 @@ RSpec.describe "bundle list" do it "prints the gems in the specified groups" do bundle "list --only-group default production" - expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * myrack (1.0.0)") expect(out).to include(" * rails (2.3.2)") expect(out).not_to include(" * rspec (1.2.7)") end @@ -99,9 +99,9 @@ RSpec.describe "bundle list" do context "with name-only option" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" gem "rspec", :group => [:test] G end @@ -109,7 +109,7 @@ RSpec.describe "bundle list" do it "prints only the name of the gems in the bundle" do bundle "list --name-only" - expect(out).to include("rack") + expect(out).to include("myrack") expect(out).to include("rspec") end end @@ -117,8 +117,8 @@ RSpec.describe "bundle list" do context "with paths option" do before do build_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "bar" @@ -126,23 +126,23 @@ RSpec.describe "bundle list" do build_git "git_test", "1.0.0", path: lib_path("git_test") - build_lib("gemspec_test", path: tmp.join("gemspec_test")) do |s| + build_lib("gemspec_test", path: tmp("gemspec_test")) do |s| s.add_dependency "bar", "=1.0.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" gem "rails" gem "git_test", :git => "#{lib_path("git_test")}" - gemspec :path => "#{tmp.join("gemspec_test")}" + gemspec :path => "#{tmp("gemspec_test")}" G end it "prints the path of each gem in the bundle" do bundle "list --paths" expect(out).to match(%r{.*\/rails\-2\.3\.2}) - expect(out).to match(%r{.*\/rack\-1\.2}) + expect(out).to match(%r{.*\/myrack\-1\.2}) expect(out).to match(%r{.*\/git_test\-\w}) expect(out).to match(%r{.*\/gemspec_test}) end @@ -151,7 +151,7 @@ RSpec.describe "bundle list" do context "when no gems are in the gemfile" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end @@ -164,25 +164,25 @@ RSpec.describe "bundle list" do context "without options" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" gem "rspec", :group => [:test] G end it "lists gems installed in the bundle" do bundle "list" - expect(out).to include(" * rack (1.0.0)") + expect(out).to include(" * myrack (1.0.0)") end end context "when using the ls alias" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" gem "rspec", :group => [:test] G end diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index b0d6fa9134..450436372e 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -1,31 +1,31 @@ # frozen_string_literal: true RSpec.describe "bundle lock" do - let(:repo) { gem_repo1 } - before :each do + build_repo2 + gemfile <<-G - source "#{file_uri_for(repo)}" + source "https://gem.repo2" gem "rails" gem "weakling" gem "foo" G checksums = checksums_section_when_existing do |c| - c.checksum repo, "actionmailer", "2.3.2" - c.checksum repo, "actionpack", "2.3.2" - c.checksum repo, "activerecord", "2.3.2" - c.checksum repo, "activeresource", "2.3.2" - c.checksum repo, "activesupport", "2.3.2" - c.checksum repo, "foo", "1.0" - c.checksum repo, "rails", "2.3.2" - c.checksum repo, "rake", rake_version - c.checksum repo, "weakling", "0.0.3" + c.checksum gem_repo2, "actionmailer", "2.3.2" + c.checksum gem_repo2, "actionpack", "2.3.2" + c.checksum gem_repo2, "activerecord", "2.3.2" + c.checksum gem_repo2, "activeresource", "2.3.2" + c.checksum gem_repo2, "activesupport", "2.3.2" + c.checksum gem_repo2, "foo", "1.0" + c.checksum gem_repo2, "rails", "2.3.2" + c.checksum gem_repo2, "rake", rake_version + c.checksum gem_repo2, "weakling", "0.0.3" end @lockfile = <<~L GEM - remote: #{file_uri_for(repo)}/ + remote: https://gem.repo2/ specs: actionmailer (2.3.2) activesupport (= 2.3.2) @@ -151,8 +151,8 @@ RSpec.describe "bundle lock" do end it "works with --gemfile flag" do - create_file "CustomGemfile", <<-G - source "#{file_uri_for(repo)}" + gemfile "CustomGemfile", <<-G + source "https://gem.repo2" gem "foo" G checksums = checksums_section_when_existing do |c| @@ -161,7 +161,7 @@ RSpec.describe "bundle lock" do lockfile = <<~L GEM - remote: #{file_uri_for(repo)}/ + remote: https://gem.repo2/ specs: foo (1.0) @@ -194,20 +194,20 @@ RSpec.describe "bundle lock" do bundle "lock --lockfile=lock" checksums = checksums_section_when_existing do |c| - c.checksum repo, "actionmailer", "2.3.2" - c.checksum repo, "actionpack", "2.3.2" - c.checksum repo, "activerecord", "2.3.2" - c.checksum repo, "activeresource", "2.3.2" - c.checksum repo, "activesupport", "2.3.2" - c.checksum repo, "foo", "1.0" - c.checksum repo, "rails", "2.3.2" - c.checksum repo, "rake", rake_version - c.checksum repo, "weakling", "0.0.3" + c.checksum gem_repo2, "actionmailer", "2.3.2" + c.checksum gem_repo2, "actionpack", "2.3.2" + c.checksum gem_repo2, "activerecord", "2.3.2" + c.checksum gem_repo2, "activeresource", "2.3.2" + c.checksum gem_repo2, "activesupport", "2.3.2" + c.checksum gem_repo2, "foo", "1.0" + c.checksum gem_repo2, "rails", "2.3.2" + c.checksum gem_repo2, "rake", rake_version + c.checksum gem_repo2, "weakling", "0.0.3" end lockfile = <<~L GEM - remote: #{file_uri_for(repo)}/ + remote: https://gem.repo2/ specs: actionmailer (2.3.2) activesupport (= 2.3.2) @@ -275,7 +275,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "tapioca" gem "ruby-lsp" @@ -283,7 +283,7 @@ RSpec.describe "bundle lock" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: prism (0.15.1) ruby-lsp (0.12.0) @@ -338,7 +338,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "tapioca" gem "ruby-lsp" @@ -347,7 +347,7 @@ RSpec.describe "bundle lock" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: other-prism-dependent (1.0.0) prism (>= 0.15.1) @@ -388,14 +388,14 @@ RSpec.describe "bundle lock" do build_git("foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}" G # Change uri format to end with "/" and reinstall install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}/" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}/" G expect(out).to include("using resolution from the lockfile") @@ -406,21 +406,21 @@ RSpec.describe "bundle lock" do ref = build_git("foo").ref_for("HEAD") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :branch => "deadbeef" + gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "deadbeef" G lockfile <<~L GIT - remote: #{file_uri_for(lib_path("foo-1.0"))} + remote: #{lib_path("foo-1.0")} revision: #{ref} branch: deadbeef specs: foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: rake (10.0.1) @@ -451,10 +451,10 @@ RSpec.describe "bundle lock" do it "can lock without downloading gems" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "thin" - gem "rack_middleware", :group => "test" + gem "myrack_middleware", :group => "test" G bundle "config set without test" bundle "config set path vendor/bundle" @@ -485,7 +485,7 @@ RSpec.describe "bundle lock" do # establish a lockfile set to 1.4.3 install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo', '1.4.3' gem 'bar', '2.0.3' gem 'qux', '1.0.0' @@ -494,7 +494,7 @@ RSpec.describe "bundle lock" do # remove 1.4.3 requirement and bar altogether # to setup update specs below gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo' gem 'qux' G @@ -517,7 +517,7 @@ RSpec.describe "bundle lock" do it "shows proper error when Gemfile changes forbid patch upgrades, and --patch --strict is given" do # force next minor via Gemfile gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo', '1.5.0' gem 'qux' G @@ -568,13 +568,13 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'sequel' G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sequel (5.71.0) @@ -606,7 +606,7 @@ RSpec.describe "bundle lock" do system_gems "bundler-55", gem_repo: gem_repo4 install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } - source "https://gems.repo4" + source "https://gem.repo4" G lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') @@ -629,10 +629,66 @@ RSpec.describe "bundle lock" do expect(lockfile.platforms).to match_array(default_platform_list(java, x86_mingw32)) end + it "supports adding new platforms, when most specific locked platform is not the current platform, and current resolve is not compatible with the target platform" do + simulate_platform "arm64-darwin-23" do + build_repo4 do + build_gem "foo" do |s| + s.platform = "arm64-darwin" + end + + build_gem "foo" do |s| + s.platform = "java" + end + end + + gemfile <<-G + source "https://gem.repo4" + + gem "foo" + G + + lockfile <<-L + GEM + remote: https://gem.repo4/ + specs: + foo (1.0-arm64-darwin) + + PLATFORMS + arm64-darwin + + DEPENDENCIES + foo + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "lock --add-platform java" + + expect(lockfile).to eq <<~L + GEM + remote: https://gem.repo4/ + specs: + foo (1.0-arm64-darwin) + foo (1.0-java) + + PLATFORMS + arm64-darwin + java + + DEPENDENCIES + foo + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + it "supports adding new platforms with force_ruby_platform = true" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: platform_specific (1.0) platform_specific (1.0-x86-64_linux) @@ -694,7 +750,7 @@ RSpec.describe "bundle lock" do simulate_platform "x86_64-darwin-22" do install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" G @@ -702,7 +758,7 @@ RSpec.describe "bundle lock" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.12.0) nokogiri (1.12.0-x86_64-darwin) @@ -726,7 +782,7 @@ RSpec.describe "bundle lock" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.12.0-x86_64-darwin) @@ -777,7 +833,7 @@ RSpec.describe "bundle lock" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "mixlib-shellout" gem "gssapi" @@ -794,7 +850,7 @@ RSpec.describe "bundle lock" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: ffi (1.9.14-x86-mingw32) gssapi (1.2.0) @@ -823,7 +879,7 @@ RSpec.describe "bundle lock" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: ffi (1.9.14) ffi (1.9.14-x86-mingw32) @@ -861,14 +917,14 @@ RSpec.describe "bundle lock" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "libv8" G lockfile <<-G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: libv8 (8.4.255.0) libv8 (8.4.255.0-x86_64-darwin-19) @@ -901,7 +957,7 @@ RSpec.describe "bundle lock" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "libv8" G @@ -915,7 +971,7 @@ RSpec.describe "bundle lock" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: libv8 (8.4.255.0-x86_64-darwin-19) libv8 (8.4.255.0-x86_64-darwin-20) @@ -949,14 +1005,14 @@ RSpec.describe "bundle lock" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "libv8" G lockfile <<-G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: libv8 (8.4.255.0-x86_64-darwin-19) libv8 (8.4.255.0-x86_64-darwin-20) @@ -1008,14 +1064,14 @@ RSpec.describe "bundle lock" do end gemfile <<-G - source "https://localgemserver.test" + source "https://gem.repo4" gem "raygun-apm" G lockfile <<-L GEM - remote: https://localgemserver.test/ + remote: https://gem.repo4/ specs: raygun-apm (1.0.78-universal-darwin) @@ -1029,7 +1085,61 @@ RSpec.describe "bundle lock" do #{Bundler::VERSION} L - bundle "lock --add-platform x86_64-linux", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + bundle "lock --add-platform x86_64-linux" + end + + it "adds platform specific gems as necessary, even when adding the current platform" do + build_repo4 do + build_gem "nokogiri", "1.16.0" + + build_gem "nokogiri", "1.16.0" do |s| + s.platform = "x86_64-linux" + end + end + + gemfile <<-G + source "https://gem.repo4" + + gem "nokogiri" + G + + lockfile <<~L + GEM + remote: https://gem.repo4/ + specs: + nokogiri (1.16.0) + + PLATFORMS + ruby + + DEPENDENCIES + nokogiri + + BUNDLED WITH + #{Bundler::VERSION} + L + + simulate_platform "x86_64-linux" do + bundle "lock --add-platform x86_64-linux" + end + + expect(lockfile).to eq <<~L + GEM + remote: https://gem.repo4/ + specs: + nokogiri (1.16.0) + nokogiri (1.16.0-x86_64-linux) + + PLATFORMS + ruby + x86_64-linux + + DEPENDENCIES + nokogiri + + BUNDLED WITH + #{Bundler::VERSION} + L end it "does not crash on conflicting ruby requirements between platform versions in two different gems" do @@ -1121,14 +1231,11 @@ RSpec.describe "bundle lock" do end context "when an update is available" do - let(:repo) do + before do build_repo2 do build_gem "foo", "2.0" end - gem_repo2 - end - before do lockfile(@lockfile) end @@ -1136,20 +1243,20 @@ RSpec.describe "bundle lock" do bundle "lock" checksums = checksums_section_when_existing do |c| - c.checksum repo, "actionmailer", "2.3.2" - c.checksum repo, "actionpack", "2.3.2" - c.checksum repo, "activerecord", "2.3.2" - c.checksum repo, "activeresource", "2.3.2" - c.checksum repo, "activesupport", "2.3.2" - c.checksum repo, "foo", "1.0" - c.checksum repo, "rails", "2.3.2" - c.checksum repo, "rake", rake_version - c.checksum repo, "weakling", "0.0.3" + c.checksum gem_repo2, "actionmailer", "2.3.2" + c.checksum gem_repo2, "actionpack", "2.3.2" + c.checksum gem_repo2, "activerecord", "2.3.2" + c.checksum gem_repo2, "activeresource", "2.3.2" + c.checksum gem_repo2, "activesupport", "2.3.2" + c.checksum gem_repo2, "foo", "1.0" + c.checksum gem_repo2, "rails", "2.3.2" + c.checksum gem_repo2, "rake", rake_version + c.checksum gem_repo2, "weakling", "0.0.3" end expected_lockfile = <<~L GEM - remote: #{file_uri_for(repo)}/ + remote: https://gem.repo2/ specs: actionmailer (2.3.2) activesupport (= 2.3.2) @@ -1190,20 +1297,20 @@ RSpec.describe "bundle lock" do bundle "lock" checksums = checksums_section_when_existing do |c| - c.checksum repo, "actionmailer", "2.3.2" - c.checksum repo, "actionpack", "2.3.2" - c.checksum repo, "activerecord", "2.3.2" - c.checksum repo, "activeresource", "2.3.2" - c.checksum repo, "activesupport", "2.3.2" + c.checksum gem_repo2, "actionmailer", "2.3.2" + c.checksum gem_repo2, "actionpack", "2.3.2" + c.checksum gem_repo2, "activerecord", "2.3.2" + c.checksum gem_repo2, "activeresource", "2.3.2" + c.checksum gem_repo2, "activesupport", "2.3.2" c.no_checksum "foo", "2.0" - c.checksum repo, "rails", "2.3.2" - c.checksum repo, "rake", rake_version - c.checksum repo, "weakling", "0.0.3" + c.checksum gem_repo2, "rails", "2.3.2" + c.checksum gem_repo2, "rake", rake_version + c.checksum gem_repo2, "weakling", "0.0.3" end expected_lockfile = <<~L GEM - remote: #{file_uri_for(repo)}/ + remote: https://gem.repo2/ specs: actionmailer (2.3.2) activesupport (= 2.3.2) @@ -1262,14 +1369,19 @@ RSpec.describe "bundle lock" do it "respects the existing lockfile, even when reresolving" do gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "debug" G + checksums = checksums_section_when_existing do |c| + c.checksum gem_repo4, "debug", "1.6.3" + c.checksum gem_repo4, "irb", "1.5.0" + end + lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: debug (1.6.3) irb (>= 1.3.6) @@ -1280,7 +1392,7 @@ RSpec.describe "bundle lock" do DEPENDENCIES debug - #{checksums_section} + #{checksums} BUNDLED WITH #{Bundler::VERSION} L @@ -1289,14 +1401,9 @@ RSpec.describe "bundle lock" do bundle "lock" end - checksums = checksums_section do |c| - c.no_checksum "debug", "1.6.3" - c.no_checksum "irb", "1.5.0" - end - expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: debug (1.6.3) irb (>= 1.3.6) @@ -1335,7 +1442,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rails", ">= 7.0.3.1" gem "activeadmin", "2.13.1" @@ -1349,7 +1456,7 @@ RSpec.describe "bundle lock" do Because rails >= 7.0.4 depends on railties = 7.0.4 and rails < 7.0.4 depends on railties = 7.0.3.1, railties = 7.0.3.1 OR = 7.0.4 is required. - So, because railties = 7.0.3.1 OR = 7.0.4 could not be found in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally, + So, because railties = 7.0.3.1 OR = 7.0.4 could not be found in rubygems repository https://gem.repo4/ or installed locally, version solving has failed. ERR end @@ -1390,7 +1497,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rails", ">= 7.0.2.3" gem "activeadmin", "= 2.13.1" @@ -1398,7 +1505,7 @@ RSpec.describe "bundle lock" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: activeadmin (2.13.1) ransack (= 3.1.0) @@ -1416,54 +1523,34 @@ RSpec.describe "bundle lock" do #{Bundler::VERSION} L - bundle "lock", raise_on_error: false - - expect(err).to eq <<~ERR.strip + expected_error = <<~ERR.strip Could not find compatible versions - Because every version of activemodel depends on activesupport = 6.0.4 - and rails >= 7.0.2.3, < 7.0.3.1 depends on activesupport = 7.0.2.3, - every version of activemodel is incompatible with rails >= 7.0.2.3, < 7.0.3.1. - And because rails >= 7.0.2.3, < 7.0.3.1 depends on activemodel = 7.0.2.3, - rails >= 7.0.2.3, < 7.0.3.1 cannot be used. - (1) So, because rails >= 7.0.3.1, < 7.0.4 depends on activemodel = 7.0.3.1 - and rails >= 7.0.4 depends on activemodel = 7.0.4, - rails >= 7.0.2.3 requires activemodel = 7.0.3.1 OR = 7.0.4. + Because rails >= 7.0.4 depends on activemodel = 7.0.4 + and rails >= 7.0.3.1, < 7.0.4 depends on activemodel = 7.0.3.1, + rails >= 7.0.3.1 requires activemodel = 7.0.3.1 OR = 7.0.4. + (1) So, because rails >= 7.0.2.3, < 7.0.3.1 depends on activemodel = 7.0.2.3 + and every version of activemodel depends on activesupport = 6.0.4, + rails >= 7.0.2.3 requires activesupport = 6.0.4. - Because rails >= 7.0.2.3, < 7.0.3.1 depends on activemodel = 7.0.2.3 + Because rails >= 7.0.2.3, < 7.0.3.1 depends on activesupport = 7.0.2.3 and rails >= 7.0.3.1, < 7.0.4 depends on activesupport = 7.0.3.1, - rails >= 7.0.2.3, < 7.0.4 requires activemodel = 7.0.2.3 or activesupport = 7.0.3.1. - And because rails >= 7.0.4 depends on activesupport = 7.0.4 - and every version of activemodel depends on activesupport = 6.0.4, - activemodel != 7.0.2.3 is incompatible with rails >= 7.0.2.3. - And because rails >= 7.0.2.3 requires activemodel = 7.0.3.1 OR = 7.0.4 (1), + rails >= 7.0.2.3, < 7.0.4 requires activesupport = 7.0.2.3 OR = 7.0.3.1. + And because rails >= 7.0.4 depends on activesupport = 7.0.4, + rails >= 7.0.2.3 requires activesupport = 7.0.2.3 OR = 7.0.3.1 OR = 7.0.4. + And because rails >= 7.0.2.3 requires activesupport = 6.0.4 (1), rails >= 7.0.2.3 cannot be used. So, because Gemfile depends on rails >= 7.0.2.3, version solving has failed. ERR - lockfile lockfile.gsub(/PLATFORMS\n #{local_platform}/m, "PLATFORMS\n #{lockfile_platforms("ruby")}") - bundle "lock", raise_on_error: false + expect(err).to eq(expected_error) - expect(err).to eq <<~ERR.strip - Could not find compatible versions + lockfile lockfile.gsub(/PLATFORMS\n #{local_platform}/m, "PLATFORMS\n #{lockfile_platforms("ruby")}") - Because rails >= 7.0.3.1, < 7.0.4 depends on activemodel = 7.0.3.1 - and rails >= 7.0.2.3, < 7.0.3.1 depends on activemodel = 7.0.2.3, - rails >= 7.0.2.3, < 7.0.4 requires activemodel = 7.0.2.3 OR = 7.0.3.1. - And because every version of activemodel depends on activesupport = 6.0.4, - rails >= 7.0.2.3, < 7.0.4 requires activesupport = 6.0.4. - Because rails >= 7.0.3.1, < 7.0.4 depends on activesupport = 7.0.3.1 - and rails >= 7.0.2.3, < 7.0.3.1 depends on activesupport = 7.0.2.3, - rails >= 7.0.2.3, < 7.0.4 requires activesupport = 7.0.2.3 OR = 7.0.3.1. - Thus, rails >= 7.0.2.3, < 7.0.4 cannot be used. - And because rails >= 7.0.4 depends on activemodel = 7.0.4, - rails >= 7.0.2.3 requires activemodel = 7.0.4. - So, because activemodel = 7.0.4 could not be found in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally - and Gemfile depends on rails >= 7.0.2.3, - version solving has failed. - ERR + bundle "lock", raise_on_error: false + expect(err).to eq(expected_error) end it "does not accidentally resolves to prereleases" do @@ -1483,7 +1570,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "autoproj", ">= 2.0.0" G @@ -1508,7 +1595,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rails" G @@ -1531,7 +1618,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "activerecord", "6.0.6" gem "activerecord-jdbc-adapter", "61.0" G @@ -1557,7 +1644,7 @@ RSpec.describe "bundle lock" do it "does not end up including gems scoped to other platforms in the lockfile" do gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rails" gem "tzinfo-data", platform: :windows G @@ -1584,7 +1671,7 @@ RSpec.describe "bundle lock" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec G end @@ -1607,12 +1694,13 @@ RSpec.describe "bundle lock" do nokogiri GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.2) PLATFORMS - #{lockfile_platforms} + ruby + x86_64-linux DEPENDENCIES foo! @@ -1644,7 +1732,7 @@ RSpec.describe "bundle lock" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "govuk_app_config" gem "activesupport", "7.0.4.3" @@ -1655,7 +1743,7 @@ RSpec.describe "bundle lock" do # version lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: actionpack (7.0.4.1) activesupport (7.0.4.1) @@ -1690,7 +1778,7 @@ RSpec.describe "bundle lock" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: actionpack (7.0.4.3) activesupport (7.0.4.3) diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index 4c391b268c..2d6fc2fd9d 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -33,9 +33,9 @@ RSpec.describe "bundle gem" do let(:minitest_test_class_name) { "class TestMygem < Minitest::Test" } before do - sys_exec("git config --global user.name 'Bundler User'") - sys_exec("git config --global user.email [email protected]") - sys_exec("git config --global github.user bundleuser") + git("config --global user.name 'Bundler User'") + git("config --global user.email [email protected]") + git("config --global github.user bundleuser") global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__LINTER" => "false", "BUNDLE_GEM__CI" => "false", "BUNDLE_GEM__CHANGELOG" => "false" @@ -109,7 +109,7 @@ RSpec.describe "bundle gem" do end it "generates the README with a section for the Code of Conduct, respecting the configured git default branch", git: ">= 2.28.0" do - sys_exec("git config --global init.defaultBranch main") + git("config --global init.defaultBranch main") bundle "gem #{gem_name} --coc" expect(bundled_app("#{gem_name}/README.md").read).to include("## Code of Conduct") @@ -269,11 +269,11 @@ RSpec.describe "bundle gem" do end end - shared_examples_for "--linter=none flag" do + shared_examples_for "--no-linter flag" do define_negated_matcher :exclude, :include before do - bundle "gem #{gem_name} --linter=none" + bundle "gem #{gem_name} --no-linter" end it "generates a gem skeleton without rubocop" do @@ -419,7 +419,7 @@ RSpec.describe "bundle gem" do context "git config github.user is absent" do before do - sys_exec("git config --global --unset github.user") + git("config --global --unset github.user") bundle "gem #{gem_name}" end @@ -601,8 +601,8 @@ RSpec.describe "bundle gem" do context "git config user.{name,email} is not set" do before do - sys_exec("git config --global --unset user.name") - sys_exec("git config --global --unset user.email") + git("config --global --unset user.name") + git("config --global --unset user.email") bundle "gem #{gem_name}" end @@ -854,6 +854,17 @@ RSpec.describe "bundle gem" do end end + context "--test parameter set to an invalid value" do + before do + bundle "gem #{gem_name} --test=foo", raise_on_error: false + end + + it "fails loudly" do + expect(last_command).to be_failure + expect(err).to match(/Expected '--test' to be one of .*; got foo/) + end + end + context "gem.test setting set to test-unit" do before do bundle "config set gem.test test-unit" @@ -937,6 +948,15 @@ RSpec.describe "bundle gem" do it_behaves_like "test framework is absent" end + context "gem.test setting set to a test framework and --no-test" do + before do + bundle "config set gem.test rspec" + bundle "gem #{gem_name} --no-test" + end + + it_behaves_like "test framework is absent" + end + context "--ci with no argument" do it "does not generate any CI config" do bundle "gem #{gem_name}" @@ -947,24 +967,6 @@ RSpec.describe "bundle gem" do end end - context "--ci set to travis" do - it "generates a GitHub Actions config file" do - bundle "gem #{gem_name} --ci=travis", raise_on_error: false - expect(err).to include("Support for Travis CI was removed from gem skeleton generator.") - - expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist - end - end - - context "--ci set to travis" do - it "generates a GitHub Actions config file" do - bundle "gem #{gem_name} --ci=travis", raise_on_error: false - expect(err).to include("Support for Travis CI was removed from gem skeleton generator.") - - expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist - end - end - context "--ci set to github" do it "generates a GitHub Actions config file" do bundle "gem #{gem_name} --ci=github" @@ -1007,6 +1009,17 @@ RSpec.describe "bundle gem" do end end + context "--ci set to an invalid value" do + before do + bundle "gem #{gem_name} --ci=foo", raise_on_error: false + end + + it "fails loudly" do + expect(last_command).to be_failure + expect(err).to match(/Expected '--ci' to be one of .*; got foo/) + end + end + context "gem.ci setting set to none" do it "doesn't generate any CI config" do expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to_not exist @@ -1015,18 +1028,6 @@ RSpec.describe "bundle gem" do end end - context "gem.ci setting set to travis" do - it "errors with friendly message" do - bundle "config set gem.ci travis" - bundle "gem #{gem_name}", raise_on_error: false - - expect(err).to include("Support for Travis CI was removed from gem skeleton generator,") - expect(err).to include("bundle config unset gem.ci") - - expect(bundled_app("#{gem_name}/.travis.yml")).to_not exist - end - end - context "gem.ci setting set to github" do it "generates a GitHub Actions config file" do bundle "config set gem.ci github" @@ -1105,6 +1106,19 @@ RSpec.describe "bundle gem" do end end + context "gem.ci setting set to a CI service and --no-ci" do + before do + bundle "config set gem.ci github" + bundle "gem #{gem_name} --no-ci" + end + + it "does not generate any CI config" do + expect(bundled_app("#{gem_name}/.github/workflows/main.yml")).to_not exist + expect(bundled_app("#{gem_name}/.gitlab-ci.yml")).to_not exist + expect(bundled_app("#{gem_name}/.circleci/config.yml")).to_not exist + end + end + context "--linter with no argument" do it "does not generate any linter config" do bundle "gem #{gem_name}" @@ -1132,6 +1146,17 @@ RSpec.describe "bundle gem" do end end + context "--linter set to an invalid value" do + before do + bundle "gem #{gem_name} --linter=foo", raise_on_error: false + end + + it "fails loudly" do + expect(last_command).to be_failure + expect(err).to match(/Expected '--linter' to be one of .*; got foo/) + end + end + context "gem.linter setting set to none" do it "doesn't generate any linter config" do bundle "gem #{gem_name}" @@ -1232,6 +1257,18 @@ RSpec.describe "bundle gem" do end end + context "gem.linter setting set to a linter and --no-linter" do + before do + bundle "config set gem.linter rubocop" + bundle "gem #{gem_name} --no-linter" + end + + it "does not generate any linter config" do + expect(bundled_app("#{gem_name}/.rubocop.yml")).to_not exist + expect(bundled_app("#{gem_name}/.standard.yml")).to_not exist + end + end + context "--edit option" do it "opens the generated gemspec in the user's text editor" do output = bundle "gem #{gem_name} --edit=echo" @@ -1284,7 +1321,7 @@ RSpec.describe "bundle gem" do end it_behaves_like "--linter=rubocop flag" it_behaves_like "--linter=standard flag" - it_behaves_like "--linter=none flag" + it_behaves_like "--no-linter flag" it_behaves_like "--rubocop flag" it_behaves_like "--no-rubocop flag" end @@ -1295,7 +1332,7 @@ RSpec.describe "bundle gem" do end it_behaves_like "--linter=rubocop flag" it_behaves_like "--linter=standard flag" - it_behaves_like "--linter=none flag" + it_behaves_like "--no-linter flag" it_behaves_like "--rubocop flag" it_behaves_like "--no-rubocop flag" end @@ -1306,7 +1343,7 @@ RSpec.describe "bundle gem" do end it_behaves_like "--linter=rubocop flag" it_behaves_like "--linter=standard flag" - it_behaves_like "--linter=none flag" + it_behaves_like "--no-linter flag" end context "with linter option in bundle config settings set to standard" do @@ -1315,7 +1352,7 @@ RSpec.describe "bundle gem" do end it_behaves_like "--linter=rubocop flag" it_behaves_like "--linter=standard flag" - it_behaves_like "--linter=none flag" + it_behaves_like "--no-linter flag" end context "with linter option in bundle config settings set to false" do @@ -1324,7 +1361,7 @@ RSpec.describe "bundle gem" do end it_behaves_like "--linter=rubocop flag" it_behaves_like "--linter=standard flag" - it_behaves_like "--linter=none flag" + it_behaves_like "--no-linter flag" end context "with changelog option in bundle config settings set to true" do @@ -1347,7 +1384,7 @@ RSpec.describe "bundle gem" do context "testing --github-username option against git and bundle config settings" do context "without git config set" do before do - sys_exec("git config --global --unset github.user") + git("config --global --unset github.user") end context "with github-username option in bundle config settings set to some value" do before do @@ -1384,7 +1421,7 @@ RSpec.describe "bundle gem" do context "testing github_username bundle config against git config settings" do context "without git config set" do before do - sys_exec("git config --global --unset github.user") + git("config --global --unset github.user") end it_behaves_like "github_username configuration" diff --git a/spec/bundler/commands/open_spec.rb b/spec/bundler/commands/open_spec.rb index 97374f30c3..e0c79aa407 100644 --- a/spec/bundler/commands/open_spec.rb +++ b/spec/bundler/commands/open_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle open" do context "when opening a regular gem" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G end @@ -39,12 +39,12 @@ RSpec.describe "bundle open" do ref = git.ref_for("main", 11) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{lib_path("foo-1.0")}" G bundle "open foo", env: { "EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => "" } - expect(out).to include("editor #{default_bundle_path.join("bundler", "gems", "foo-1.0-#{ref}")}") + expect(out).to include("editor #{default_bundle_path("bundler", "gems", "foo-1.0-#{ref}")}") end it "suggests alternatives for similar-sounding gems" do @@ -134,7 +134,7 @@ RSpec.describe "bundle open" do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" gem "foo" G @@ -163,8 +163,7 @@ RSpec.describe "bundle open" do skip "No default gems available on this test run" if default_gems.empty? install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "json" + source "https://gem.repo1" G end diff --git a/spec/bundler/commands/outdated_spec.rb b/spec/bundler/commands/outdated_spec.rb index e7edc67e57..c5663acfb8 100644 --- a/spec/bundler/commands/outdated_spec.rb +++ b/spec/bundler/commands/outdated_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -46,7 +46,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "AAA", "1.0.0" G @@ -77,7 +77,7 @@ RSpec.describe "bundle outdated" do it "adds gem group to dependency output when repo is updated" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "terranova", '8' @@ -109,7 +109,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -126,14 +126,14 @@ RSpec.describe "bundle outdated" do update_repo2 { build_gem "terranova", "9" } install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "terranova", '9' gem 'activesupport', '2.3.5' G gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "terranova", '8' gem 'activesupport', '2.3.5' @@ -225,7 +225,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "weakling", "~> 0.0.1" gem "terranova", '8' @@ -301,7 +301,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "bar_dependant", '7.0' G @@ -331,7 +331,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "weakling", "~> 0.0.1" gem "terranova", '8' @@ -375,7 +375,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "weakling", "~> 0.0.1" gem "terranova", '8' @@ -394,7 +394,7 @@ RSpec.describe "bundle outdated" do bundle "config set clean false" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.4" G @@ -428,7 +428,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -474,7 +474,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -507,7 +507,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -554,7 +554,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "3.0.0.beta.1" G @@ -578,7 +578,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -622,7 +622,7 @@ RSpec.describe "bundle outdated" do it "doesn't crash when some deps unused on the current platform" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", platforms: [:ruby_22] G @@ -633,8 +633,8 @@ RSpec.describe "bundle outdated" do it "only reports gem dependencies when they can actually be updated" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack_middleware", "1.0" + source "https://gem.repo2" + gem "myrack_middleware", "1.0" G bundle :outdated, "filter-strict": true @@ -645,7 +645,7 @@ RSpec.describe "bundle outdated" do describe "and filter options" do it "only reports gems that match requirement and patch filter level" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "~> 2.3" gem "weakling", ">= 0.0.1" G @@ -667,7 +667,7 @@ RSpec.describe "bundle outdated" do it "only reports gems that match requirement and minor filter level" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "~> 2.3" gem "weakling", ">= 0.0.1" G @@ -689,7 +689,7 @@ RSpec.describe "bundle outdated" do it "only reports gems that match requirement and major filter level" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "~> 2.3" gem "weakling", ">= 0.0.1" G @@ -719,7 +719,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -742,8 +742,8 @@ RSpec.describe "bundle outdated" do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" gem "foo" G @@ -757,9 +757,9 @@ RSpec.describe "bundle outdated" do build_repo2 gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack" + gem "myrack" gem "foo" G bundle :lock @@ -786,9 +786,9 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack" + gem "myrack" gem "foo" G bundle "config set --local deployment true" @@ -811,7 +811,7 @@ RSpec.describe "bundle outdated" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "laduradura", '= 5.15.2' G end @@ -829,7 +829,7 @@ RSpec.describe "bundle outdated" do it "reports that updates are available if the Ruby platform is used" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "laduradura", '= 5.15.2', :platforms => [:ruby, :jruby] G @@ -839,7 +839,7 @@ RSpec.describe "bundle outdated" do it "reports that updates are available if the JRuby platform is used", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "laduradura", '= 5.15.2', :platforms => [:ruby, :jruby] G @@ -872,7 +872,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -898,7 +898,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -928,7 +928,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -954,7 +954,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -987,7 +987,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -1013,7 +1013,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -1039,7 +1039,7 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "zebra", :git => "#{lib_path("zebra")}" gem "foo", :git => "#{lib_path("foo")}" gem "activesupport", "2.3.5" @@ -1123,7 +1123,7 @@ RSpec.describe "bundle outdated" do # establish a lockfile set to 1.0.0 install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'patch', '1.0.0' gem 'minor', '1.0.0' gem 'major', '1.0.0' @@ -1131,7 +1131,7 @@ RSpec.describe "bundle outdated" do # remove all version requirements gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'patch' gem 'minor' gem 'major' @@ -1196,7 +1196,7 @@ RSpec.describe "bundle outdated" do # establish a lockfile set to 1.4.3 install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo', '1.4.3' gem 'bar', '2.0.3' gem 'qux', '1.0.0' @@ -1205,7 +1205,7 @@ RSpec.describe "bundle outdated" do # remove 1.4.3 requirement and bar altogether # to setup update specs below gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo' gem 'qux' G @@ -1246,13 +1246,13 @@ RSpec.describe "bundle outdated" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'weakling', '0.2' gem 'bar', '2.1' G gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'weakling' G @@ -1283,7 +1283,7 @@ RSpec.describe "bundle outdated" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.11.1) nokogiri (1.11.1-#{Bundler.local_platform}) @@ -1300,7 +1300,7 @@ RSpec.describe "bundle outdated" do L gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" G end @@ -1330,14 +1330,14 @@ RSpec.describe "bundle outdated" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "mini_portile2" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: mini_portile2 (2.5.2) net-ftp (~> 0.1) diff --git a/spec/bundler/commands/platform_spec.rb b/spec/bundler/commands/platform_spec.rb index 61e615acae..370cc601c0 100644 --- a/spec/bundler/commands/platform_spec.rb +++ b/spec/bundler/commands/platform_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle platform" do context "without flags" do it "returns all the output" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" #{ruby_version_correct} @@ -27,7 +27,7 @@ G it "returns all the output including the patchlevel" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" #{ruby_version_correct_patchlevel} @@ -50,7 +50,7 @@ G it "doesn't print ruby version requirement if it isn't specified" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G @@ -68,7 +68,7 @@ G it "doesn't match the ruby version requirement" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" #{ruby_version_incorrect} @@ -93,7 +93,7 @@ G context "--ruby" do it "returns ruby version when explicit" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.9.3", :engine => 'ruby', :engine_version => '1.9.3' gem "foo" @@ -106,7 +106,7 @@ G it "defaults to MRI" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.9.3" gem "foo" @@ -119,7 +119,7 @@ G it "handles jruby" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.8.7", :engine => 'jruby', :engine_version => '1.6.5' gem "foo" @@ -132,7 +132,7 @@ G it "handles rbx" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.8.7", :engine => 'rbx', :engine_version => '1.2.4' gem "foo" @@ -145,7 +145,7 @@ G it "handles truffleruby" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "2.5.1", :engine => 'truffleruby', :engine_version => '1.0.0-rc6' gem "foo" @@ -158,7 +158,7 @@ G it "raises an error if engine is used but engine version is not" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.8.7", :engine => 'rbx' gem "foo" @@ -171,7 +171,7 @@ G it "raises an error if engine_version is used but engine is not" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.8.7", :engine_version => '1.2.4' gem "foo" @@ -184,7 +184,7 @@ G it "raises an error if engine version doesn't match ruby version for MRI" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "1.8.7", :engine => 'ruby', :engine_version => '1.2.4' gem "foo" @@ -197,7 +197,7 @@ G it "should print if no ruby version is specified" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G @@ -209,13 +209,13 @@ G it "handles when there is a locked requirement" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "< 1.8.7" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -236,12 +236,12 @@ G it "handles when there is a lockfile with no requirement" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -259,7 +259,7 @@ G it "handles when there is a requirement in the gemfile" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= 1.8.7" G @@ -269,7 +269,7 @@ G it "handles when there are multiple requirements in the gemfile" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= 1.8.7", "< 2.0.0" G @@ -315,8 +315,8 @@ G context "bundle install" do it "installs fine when the ruby version matches" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_correct} G @@ -326,8 +326,8 @@ G it "installs fine with any engine", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_correct_engineless} G @@ -337,8 +337,8 @@ G it "installs fine when the patchlevel matches" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_correct_patchlevel} G @@ -348,8 +348,8 @@ G it "doesn't install when the ruby version doesn't match" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_incorrect} G @@ -360,8 +360,8 @@ G it "doesn't install when engine doesn't match" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{engine_incorrect} G @@ -372,8 +372,8 @@ G it "doesn't install when engine version doesn't match", :jruby_only do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{engine_version_incorrect} G @@ -384,8 +384,8 @@ G it "doesn't install when patchlevel doesn't match" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G @@ -398,13 +398,13 @@ G context "bundle check" do it "checks fine when the ruby version matches" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_correct} G @@ -415,13 +415,13 @@ G it "checks fine with any engine", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_correct_engineless} G @@ -432,13 +432,13 @@ G it "fails when ruby version doesn't match" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{ruby_version_incorrect} G @@ -449,13 +449,13 @@ G it "fails when engine doesn't match" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{engine_incorrect} G @@ -466,13 +466,13 @@ G it "fails when engine version doesn't match", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{engine_version_incorrect} G @@ -483,13 +483,13 @@ G it "fails when patchlevel doesn't match" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G @@ -504,57 +504,57 @@ G build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" G end it "updates successfully when the ruby version matches" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" #{ruby_version_correct} G update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" end bundle "update", all: true - expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" + expect(the_bundle).to include_gems "myrack 1.2", "myrack-obama 1.0", "activesupport 3.0" end it "updates fine with any engine", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" #{ruby_version_correct_engineless} G update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" end bundle "update", all: true - expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" + expect(the_bundle).to include_gems "myrack 1.2", "myrack-obama 1.0", "activesupport 3.0" end it "fails when ruby version doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" #{ruby_version_incorrect} G @@ -568,9 +568,9 @@ G it "fails when ruby engine doesn't match", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" #{engine_incorrect} G @@ -584,9 +584,9 @@ G it "fails when ruby engine version doesn't match", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" #{engine_version_incorrect} G @@ -600,8 +600,8 @@ G it "fails when patchlevel doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G @@ -617,14 +617,14 @@ G context "bundle info" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G end it "prints path if ruby version is correct" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" #{ruby_version_correct} @@ -636,7 +636,7 @@ G it "prints path if ruby version is correct for any engine", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" #{ruby_version_correct_engineless} @@ -648,7 +648,7 @@ G it "fails if ruby version doesn't match", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" #{ruby_version_incorrect} @@ -660,7 +660,7 @@ G it "fails if engine doesn't match", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" #{engine_incorrect} @@ -672,7 +672,7 @@ G it "fails if engine version doesn't match", bundler: "< 3", jruby_only: true do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" #{engine_version_incorrect} @@ -684,8 +684,8 @@ G it "fails when patchlevel doesn't match", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G @@ -701,39 +701,39 @@ G context "bundle cache" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G end it "copies the .gem file to vendor/cache when ruby version matches" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{ruby_version_correct} G bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "copies the .gem file to vendor/cache when ruby version matches for any engine", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{ruby_version_correct_engineless} G bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "fails if the ruby version doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{ruby_version_incorrect} G @@ -744,8 +744,8 @@ G it "fails if the engine doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{engine_incorrect} G @@ -756,8 +756,8 @@ G it "fails if the engine version doesn't match", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{engine_version_incorrect} G @@ -768,8 +768,8 @@ G it "fails when patchlevel doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G @@ -782,39 +782,39 @@ G context "bundle pack" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G end it "copies the .gem file to vendor/cache when ruby version matches" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{ruby_version_correct} G bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "copies the .gem file to vendor/cache when ruby version matches any engine", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{ruby_version_correct_engineless} G bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end it "fails if the ruby version doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{ruby_version_incorrect} G @@ -825,8 +825,8 @@ G it "fails if the engine doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{engine_incorrect} G @@ -837,8 +837,8 @@ G it "fails if the engine version doesn't match", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' #{engine_version_incorrect} G @@ -849,8 +849,8 @@ G it "fails when patchlevel doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G @@ -863,78 +863,78 @@ G context "bundle exec" do before do ENV["BUNDLER_FORCE_TTY"] = "true" - system_gems "rack-1.0.0", "rack-0.9.1", path: default_bundle_path + system_gems "myrack-1.0.0", "myrack-0.9.1", path: default_bundle_path end it "activates the correct gem when ruby version matches" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" #{ruby_version_correct} G - bundle "exec rackup" + bundle "exec myrackup" expect(out).to include("0.9.1") end it "activates the correct gem when ruby version matches any engine", :jruby_only do - system_gems "rack-1.0.0", "rack-0.9.1", path: default_bundle_path + system_gems "myrack-1.0.0", "myrack-0.9.1", path: default_bundle_path gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" #{ruby_version_correct_engineless} G - bundle "exec rackup" + bundle "exec myrackup" expect(out).to include("0.9.1") end it "fails when the ruby version doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" #{ruby_version_incorrect} G - bundle "exec rackup", raise_on_error: false + bundle "exec myrackup", raise_on_error: false should_be_ruby_version_incorrect end it "fails when the engine doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" #{engine_incorrect} G - bundle "exec rackup", raise_on_error: false + bundle "exec myrackup", raise_on_error: false should_be_engine_incorrect end # it "fails when the engine version doesn't match", :jruby_only do # gemfile <<-G - # gem "rack", "0.9.1" + # gem "myrack", "0.9.1" # # #{engine_version_incorrect} # G # - # bundle "exec rackup" + # bundle "exec myrackup" # should_be_engine_version_incorrect # end it "fails when patchlevel doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" #{patchlevel_incorrect} G - bundle "exec rackup", raise_on_error: false + bundle "exec myrackup", raise_on_error: false should_be_patchlevel_incorrect end end @@ -942,25 +942,25 @@ G context "bundle console", bundler: "< 3" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development G end it "starts IRB with the default group loaded when ruby version matches", :readline do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development #{ruby_version_correct} G bundle "console" do |input, _, _| - input.puts("puts RACK") + input.puts("puts MYRACK") input.puts("exit") end expect(out).to include("0.9.1") @@ -968,16 +968,16 @@ G it "starts IRB with the default group loaded when ruby version matches", :readline, :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development #{ruby_version_correct_engineless} G bundle "console" do |input, _, _| - input.puts("puts RACK") + input.puts("puts MYRACK") input.puts("exit") end expect(out).to include("0.9.1") @@ -985,10 +985,10 @@ G it "fails when ruby version doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development #{ruby_version_incorrect} G @@ -999,10 +999,10 @@ G it "fails when engine doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development #{engine_incorrect} G @@ -1013,10 +1013,10 @@ G it "fails when engine version doesn't match", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development #{engine_version_incorrect} G @@ -1027,10 +1027,10 @@ G it "fails when patchlevel doesn't match" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test - gem "rack_middleware", :group => :development + gem "myrack_middleware", :group => :development #{patchlevel_incorrect} G @@ -1043,9 +1043,9 @@ G context "Bundler.setup" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack", :group => :test + gem "myrack", :group => :test G ENV["BUNDLER_FORCE_TTY"] = "true" @@ -1053,9 +1053,9 @@ G it "makes a Gemfile.lock if setup succeeds" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack" + gem "myrack" #{ruby_version_correct} G @@ -1068,9 +1068,9 @@ G it "makes a Gemfile.lock if setup succeeds for any engine", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack" + gem "myrack" #{ruby_version_correct_engineless} G @@ -1083,9 +1083,9 @@ G it "fails when ruby version doesn't match" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack" + gem "myrack" #{ruby_version_incorrect} G @@ -1100,9 +1100,9 @@ G it "fails when engine doesn't match" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack" + gem "myrack" #{engine_incorrect} G @@ -1117,9 +1117,9 @@ G it "fails when engine version doesn't match", :jruby_only do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack" + gem "myrack" #{engine_version_incorrect} G @@ -1134,9 +1134,9 @@ G it "fails when patchlevel doesn't match" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack" + gem "myrack" #{patchlevel_incorrect} G @@ -1157,7 +1157,7 @@ G end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" G @@ -1170,7 +1170,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" @@ -1196,7 +1196,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" @@ -1221,7 +1221,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" @@ -1239,7 +1239,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" @@ -1257,7 +1257,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" @@ -1275,7 +1275,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" @@ -1293,7 +1293,7 @@ G end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", "2.3.5" gem "foo", :git => "#{lib_path("foo")}" diff --git a/spec/bundler/commands/post_bundle_message_spec.rb b/spec/bundler/commands/post_bundle_message_spec.rb index 3c7fd3486d..8671504b25 100644 --- a/spec/bundler/commands/post_bundle_message_spec.rb +++ b/spec/bundler/commands/post_bundle_message_spec.rb @@ -3,13 +3,13 @@ RSpec.describe "post bundle message" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", "2.3.5", :group => [:emo, :test] group :test do gem "rspec" end - gem "rack-obama", :group => :obama + gem "myrack-obama", :group => :obama G end @@ -115,25 +115,25 @@ RSpec.describe "post bundle message" do it "should report a helpful error message" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "not-a-gem", :group => :development G expect(err).to include <<-EOS.strip -Could not find gem 'not-a-gem' in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally. +Could not find gem 'not-a-gem' in rubygems repository https://gem.repo1/ or installed locally. EOS end it "should report a helpful error message with reference to cache if available" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :cache - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "not-a-gem", :group => :development G expect(err).to include("Could not find gem 'not-a-gem' in"). diff --git a/spec/bundler/commands/pristine_spec.rb b/spec/bundler/commands/pristine_spec.rb index 1aec37f850..547aa12b6c 100644 --- a/spec/bundler/commands/pristine_spec.rb +++ b/spec/bundler/commands/pristine_spec.rb @@ -19,7 +19,7 @@ RSpec.describe "bundle pristine" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "weakling" gem "very_simple_binary" gem "foo", :git => "#{lib_path("foo")}", :branch => "main" diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 197fcde091..d2d7d1b6a8 100644 --- a/spec/bundler/commands/remove_spec.rb +++ b/spec/bundler/commands/remove_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle remove" do context "when no gems are specified" do it "throws error" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G bundle "remove", raise_on_error: false @@ -16,29 +16,29 @@ RSpec.describe "bundle remove" do context "after 'bundle install' is run" do describe "running 'bundle remove GEM_NAME'" do it "removes it from the lockfile" do - rack_dep = <<~L + myrack_dep = <<~L DEPENDENCIES - rack + myrack L gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G bundle "install" - expect(lockfile).to include(rack_dep) + expect(lockfile).to include(myrack_dep) - bundle "remove rack" + bundle "remove myrack" expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G - expect(lockfile).to_not include(rack_dep) + expect(lockfile).to_not include(myrack_dep) end end end @@ -46,15 +46,15 @@ RSpec.describe "bundle remove" do context "when --install flag is specified", bundler: "< 3" do it "removes gems from .bundle" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G - bundle "remove rack --install" + bundle "remove myrack --install" - expect(out).to include("rack was removed.") - expect(the_bundle).to_not include_gems "rack" + expect(out).to include("myrack was removed.") + expect(the_bundle).to_not include_gems "myrack" end end @@ -62,39 +62,39 @@ RSpec.describe "bundle remove" do context "when gem is present in gemfile" do it "shows success for removed gem" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") - expect(the_bundle).to_not include_gems "rack" + expect(out).to include("myrack was removed.") + expect(the_bundle).to_not include_gems "myrack" expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end context "when gem is specified in multiple lines" do it "shows success for removed gem" do - build_git "rack" + build_git "myrack" gemfile <<-G - source '#{file_uri_for(gem_repo1)}' + source 'https://gem.repo1' gem 'git' - gem 'rack', - git: "#{lib_path("rack-1.0")}", + gem 'myrack', + git: "#{lib_path("myrack-1.0")}", branch: 'main' gem 'nokogiri' G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source '#{file_uri_for(gem_repo1)}' + source 'https://gem.repo1' gem 'git' gem 'nokogiri' @@ -106,12 +106,12 @@ RSpec.describe "bundle remove" do context "when gem is not present in gemfile" do it "shows warning for gem that could not be removed" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G - bundle "remove rack", raise_on_error: false + bundle "remove myrack", raise_on_error: false - expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") + expect(err).to include("`myrack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end end end @@ -120,18 +120,18 @@ RSpec.describe "bundle remove" do context "when all gems are present in gemfile" do it "shows success fir all removed gems" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" gem "rails" G - bundle "remove rack rails" + bundle "remove myrack rails" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(out).to include("rails was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -139,18 +139,18 @@ RSpec.describe "bundle remove" do context "when some gems are not present in the gemfile" do it "shows warning for those not present and success for those that can be removed" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" gem "minitest" gem "rspec" G - bundle "remove rails rack minitest", raise_on_error: false + bundle "remove rails myrack minitest", raise_on_error: false - expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") + expect(err).to include("`myrack` is not specified in #{bundled_app_gemfile} so it could not be removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" gem "minitest" @@ -163,16 +163,16 @@ RSpec.describe "bundle remove" do context "with inline groups" do it "removes the specified gem" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", :group => [:dev] + gem "myrack", :group => [:dev] G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -181,7 +181,7 @@ RSpec.describe "bundle remove" do context "when single group block with gem to be removed is present" do it "removes the group block" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do gem "rspec" @@ -192,7 +192,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -200,19 +200,19 @@ RSpec.describe "bundle remove" do context "when gem to be removed is outside block" do it "does not modify group" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" group :test do gem "coffee-script-source" end G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do gem "coffee-script-source" @@ -224,7 +224,7 @@ RSpec.describe "bundle remove" do context "when an empty block is also present" do it "removes all empty blocks" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do gem "rspec" @@ -238,7 +238,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -246,7 +246,7 @@ RSpec.describe "bundle remove" do context "when the gem belongs to multiple groups" do it "removes the groups" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test, :serioustest do gem "rspec" @@ -257,7 +257,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -265,7 +265,7 @@ RSpec.describe "bundle remove" do context "when the gem is present in multiple groups" do it "removes all empty blocks" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :one do gem "rspec" @@ -280,7 +280,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -290,7 +290,7 @@ RSpec.describe "bundle remove" do context "when all the groups will be empty after removal" do it "removes the empty nested blocks" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do group :serioustest do @@ -303,7 +303,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -311,10 +311,10 @@ RSpec.describe "bundle remove" do context "when outer group will not be empty after removal" do it "removes only empty blocks" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do - gem "rack-test" + gem "myrack-test" group :serioustest do gem "rspec" @@ -326,10 +326,10 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do - gem "rack-test" + gem "myrack-test" end G @@ -339,12 +339,12 @@ RSpec.describe "bundle remove" do context "when inner group will not be empty after removal" do it "removes only empty blocks" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do group :serioustest do gem "rspec" - gem "rack-test" + gem "myrack-test" end end G @@ -353,11 +353,11 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do group :serioustest do - gem "rack-test" + gem "myrack-test" end end G @@ -369,16 +369,16 @@ RSpec.describe "bundle remove" do context "when multiple gems are present in same line" do it "shows warning for gems not removed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack"; gem "rails" + source "https://gem.repo1" + gem "myrack"; gem "rails" G bundle "remove rails", raise_on_error: false - expect(err).to include("Gems could not be removed. rack (>= 0) would also have been removed.") + expect(err).to include("Gems could not be removed. myrack (>= 0) would also have been removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" - gem "rack"; gem "rails" + source "https://gem.repo1" + gem "myrack"; gem "rails" G end end @@ -386,21 +386,21 @@ RSpec.describe "bundle remove" do context "when some gems could not be removed" do it "shows warning for gems not removed and success for those removed" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem"rack" + source "https://gem.repo1" + gem"myrack" gem"rspec" gem "rails" gem "minitest" G - bundle "remove rails rack rspec minitest" + bundle "remove rails myrack rspec minitest" expect(out).to include("rails was removed.") expect(out).to include("minitest was removed.") - expect(out).to include("rack, rspec could not be removed.") + expect(out).to include("myrack, rspec could not be removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" - gem"rack" + source "https://gem.repo1" + gem"myrack" gem"rspec" G end @@ -416,11 +416,11 @@ RSpec.describe "bundle remove" do it "removes gems and empty source blocks" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" - source "#{file_uri_for(gem_repo3)}" do + source "https://gem.repo3" do gem "rspec" end G @@ -431,9 +431,9 @@ RSpec.describe "bundle remove" do expect(out).to include("rspec was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G end end @@ -441,40 +441,40 @@ RSpec.describe "bundle remove" do describe "with eval_gemfile" do context "when gems are present in both gemfiles" do it "removes the gems" do - create_file "Gemfile-other", <<-G - gem "rack" + gemfile "Gemfile-other", <<-G + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" - gem "rack" + gem "myrack" G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") end end context "when gems are present in other gemfile" do it "removes the gems" do - create_file "Gemfile-other", <<-G - gem "rack" + gemfile "Gemfile-other", <<-G + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" G - bundle "remove rack" + bundle "remove myrack" - expect(bundled_app("Gemfile-other").read).to_not include("gem \"rack\"") - expect(out).to include("rack was removed.") + expect(bundled_app("Gemfile-other").read).to_not include("gem \"myrack\"") + expect(out).to include("myrack was removed.") end end @@ -486,36 +486,36 @@ RSpec.describe "bundle remove" do G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" G - bundle "remove rack", raise_on_error: false + bundle "remove myrack", raise_on_error: false - expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") + expect(err).to include("`myrack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end end context "when the gem is present in parent file but not in gemfile specified by eval_gemfile" do it "removes the gem" do - create_file "Gemfile-other", <<-G + gemfile "Gemfile-other", <<-G gem "rails" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" - gem "rack" + gem "myrack" G - bundle "remove rack", raise_on_error: false + bundle "remove myrack", raise_on_error: false - expect(out).to include("rack was removed.") - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile-other")} so it could not be removed.") + expect(out).to include("myrack was removed.") + expect(err).to include("`myrack` is not specified in #{bundled_app("Gemfile-other")} so it could not be removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" G @@ -524,23 +524,23 @@ RSpec.describe "bundle remove" do context "when gems cannot be removed from other gemfile" do it "shows error" do - create_file "Gemfile-other", <<-G - gem "rails"; gem "rack" + gemfile "Gemfile-other", <<-G + gem "rails"; gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" - gem "rack" + gem "myrack" G - bundle "remove rack", raise_on_error: false + bundle "remove myrack", raise_on_error: false - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(err).to include("Gems could not be removed. rails (>= 0) would also have been removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" G @@ -549,47 +549,47 @@ RSpec.describe "bundle remove" do context "when gems could not be removed from parent gemfile" do it "shows error" do - create_file "Gemfile-other", <<-G - gem "rack" + gemfile "Gemfile-other", <<-G + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" - gem "rails"; gem "rack" + gem "rails"; gem "myrack" G - bundle "remove rack", raise_on_error: false + bundle "remove myrack", raise_on_error: false expect(err).to include("Gems could not be removed. rails (>= 0) would also have been removed.") - expect(bundled_app("Gemfile-other").read).to include("gem \"rack\"") + expect(bundled_app("Gemfile-other").read).to include("gem \"myrack\"") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" - gem "rails"; gem "rack" + gem "rails"; gem "myrack" G end end context "when gem present in gemfiles but could not be removed from one from one of them" do it "removes gem which can be removed and shows warning for file from which it cannot be removed" do - create_file "Gemfile-other", <<-G - gem "rack" + gemfile "Gemfile-other", <<-G + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "Gemfile-other" - gem"rack" + gem"myrack" G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") - expect(bundled_app("Gemfile-other").read).to_not include("gem \"rack\"") + expect(out).to include("myrack was removed.") + expect(bundled_app("Gemfile-other").read).to_not include("gem \"myrack\"") end end end @@ -597,18 +597,18 @@ RSpec.describe "bundle remove" do context "with install_if" do it "removes gems inside blocks and empty blocks" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" install_if(lambda { false }) do - gem "rack" + gem "myrack" end G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -616,32 +616,32 @@ RSpec.describe "bundle remove" do context "with env" do it "removes gems inside blocks and empty blocks" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" env "BUNDLER_TEST" do - gem "rack" + gem "myrack" end G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end context "with gemspec" do it "should not remove the gem" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("foo.gemspec", "") - s.add_dependency "rack" + s.add_dependency "myrack" end install_gemfile(<<-G) - source "#{file_uri_for(gem_repo1)}" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + source "https://gem.repo1" + gemspec :path => '#{tmp("foo")}', :name => 'foo' G bundle "remove foo" @@ -654,19 +654,19 @@ RSpec.describe "bundle remove" do context "when comment is a separate line comment" do it "does not remove the line comment" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - # gem "rack" might be used in the future - gem "rack" + # gem "myrack" might be used in the future + gem "myrack" G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - # gem "rack" might be used in the future + # gem "myrack" might be used in the future G end end @@ -674,16 +674,16 @@ RSpec.describe "bundle remove" do context "when gem specified for removal has an inline comment" do it "removes the inline comment" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" # this can be removed + gem "myrack" # this can be removed G - bundle "remove rack" + bundle "remove myrack" - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end end @@ -691,19 +691,19 @@ RSpec.describe "bundle remove" do context "when gem specified for removal is mentioned in other gem's comment" do it "does not remove other gem" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "puma" # implements interface provided by gem "rack" + source "https://gem.repo1" + gem "puma" # implements interface provided by gem "myrack" - gem "rack" + gem "myrack" G - bundle "remove rack" + bundle "remove myrack" expect(out).to_not include("puma was removed.") - expect(out).to include("rack was removed.") + expect(out).to include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" - gem "puma" # implements interface provided by gem "rack" + source "https://gem.repo1" + gem "puma" # implements interface provided by gem "myrack" G end end @@ -711,20 +711,20 @@ RSpec.describe "bundle remove" do context "when gem specified for removal has a comment that mentions other gem" do it "does not remove other gem" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "puma" # implements interface provided by gem "rack" + source "https://gem.repo1" + gem "puma" # implements interface provided by gem "myrack" - gem "rack" + gem "myrack" G bundle "remove puma" expect(out).to include("puma was removed.") - expect(out).to_not include("rack was removed.") + expect(out).to_not include("myrack was removed.") expect(gemfile).to eq <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G end end diff --git a/spec/bundler/commands/show_spec.rb b/spec/bundler/commands/show_spec.rb index 2b6d4d2d00..7f32d0563b 100644 --- a/spec/bundler/commands/show_spec.rb +++ b/spec/bundler/commands/show_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle show", bundler: "< 3" do context "with a standard Gemfile" do before :each do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G end @@ -155,7 +155,7 @@ RSpec.describe "bundle show", bundler: "< 3" do it "performs an automatic bundle install" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo" G @@ -167,20 +167,20 @@ RSpec.describe "bundle show", bundler: "< 3" do context "with a valid regexp for gem name" do it "presents alternatives", :readline do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G bundle "show rac" - expect(out).to match(/\A1 : rack\n2 : rack-obama\n0 : - exit -(\n>.*)?\z/) + expect(out).to match(/\A1 : myrack\n2 : myrack-obama\n0 : - exit -(\n>|\z)/) end end context "with an invalid regexp for gem name" do it "does not find the gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -199,7 +199,7 @@ RSpec.describe "bundle show", bundler: "< 3" do it "doesn't update gems to newer versions" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" G diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index 8565e27ebf..c1874c3bc8 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -6,17 +6,17 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end it "updates the entire bundle" do update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" @@ -24,14 +24,14 @@ RSpec.describe "bundle update" do bundle "update" expect(out).to include("Bundle updated!") - expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" + expect(the_bundle).to include_gems "myrack 1.2", "myrack-obama 1.0", "activesupport 3.0" end it "doesn't delete the Gemfile.lock file if something goes wrong" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" exit! G bundle "update", raise_on_error: false @@ -44,17 +44,17 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end it "updates the entire bundle" do update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" @@ -62,16 +62,16 @@ RSpec.describe "bundle update" do bundle "update", all: true expect(out).to include("Bundle updated!") - expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 3.0" + expect(the_bundle).to include_gems "myrack 1.2", "myrack-obama 1.0", "activesupport 3.0" end it "doesn't delete the Gemfile.lock file if something goes wrong" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" exit! G bundle "update", all: true, raise_on_error: false @@ -82,8 +82,8 @@ RSpec.describe "bundle update" do describe "with --gemfile" do it "creates lock files based on the Gemfile name" do gemfile bundled_app("OmgFile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0" + source "https://gem.repo1" + gem "myrack", "1.0" G bundle "update --gemfile OmgFile", all: true @@ -96,19 +96,19 @@ RSpec.describe "bundle update" do before { bundle "config set update_requires_all_flag true" } it "errors when passed nothing" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" bundle :update, raise_on_error: false expect(err).to eq("To update everything, pass the `--all` flag.") end it "errors when passed --all and another option" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" bundle "update --all foo", raise_on_error: false expect(err).to eq("Cannot specify --all along with specific options.") end it "updates everything when passed --all" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" bundle "update --all" expect(out).to include("Bundle updated!") end @@ -119,9 +119,9 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end @@ -137,24 +137,24 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end it "unlocks all child dependencies that are unrelated to other locked dependencies" do update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" end - bundle "update rack-obama" - expect(the_bundle).to include_gems "rack 1.2", "rack-obama 1.0", "activesupport 2.3.5" + bundle "update myrack-obama" + expect(the_bundle).to include_gems "myrack 1.2", "myrack-obama 1.0", "activesupport 2.3.5" end end @@ -163,9 +163,9 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end @@ -185,22 +185,22 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end it "should update the child dependency" do update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end - bundle "update rack" - expect(the_bundle).to include_gems "rack 1.2" + bundle "update myrack" + expect(the_bundle).to include_gems "myrack 1.2" end end @@ -223,7 +223,7 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "slim-rails" gem "slim_lint" G @@ -269,7 +269,7 @@ RSpec.describe "bundle update" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "country_select" gem "countries" @@ -282,7 +282,7 @@ RSpec.describe "bundle update" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: countries (3.1.0) country_select (5.1.0) @@ -331,7 +331,7 @@ RSpec.describe "bundle update" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "oauth2" gem "quickbooks-ruby" @@ -339,7 +339,7 @@ RSpec.describe "bundle update" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: faraday (2.5.2) multi_json (1.15.0) @@ -390,7 +390,7 @@ RSpec.describe "bundle update" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec @@ -404,7 +404,7 @@ RSpec.describe "bundle update" do specs: GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: rake (13.0.6) sneakers (2.11.0) @@ -440,7 +440,7 @@ RSpec.describe "bundle update" do end install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "a" G @@ -464,7 +464,7 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "a" gem "b" G @@ -472,7 +472,7 @@ RSpec.describe "bundle update" do expect(the_bundle).to include_gems("a 1.0", "b 2.0") gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "a" gem "b", "1.0" G @@ -497,14 +497,14 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "activesupport", "~> 6.1.0" G expect(the_bundle).to include_gems("activesupport 6.1.4.1", "tzinfo 2.0.4") gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "activesupport", "~> 6.0.0" G @@ -517,7 +517,7 @@ RSpec.describe "bundle update" do expected_lockfile = <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: activesupport (6.0.4.1) tzinfo (~> 1.1) @@ -558,21 +558,21 @@ RSpec.describe "bundle update" do build_repo2 gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: activesupport (2.3.5) platform_specific (1.0-#{local_platform}) - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack PLATFORMS #{local_platform} @@ -580,7 +580,7 @@ RSpec.describe "bundle update" do DEPENDENCIES activesupport platform_specific - rack-obama + myrack-obama BUNDLED WITH #{Bundler::VERSION} @@ -604,26 +604,26 @@ RSpec.describe "bundle update" do it "should update only specified group gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", :group => :development - gem "rack" + gem "myrack" G update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" end bundle "update --group development" expect(the_bundle).to include_gems "activesupport 3.0" - expect(the_bundle).not_to include_gems "rack 1.2" + expect(the_bundle).not_to include_gems "myrack 1.2" end context "when conservatively updating a group with non-group sub-deps" do it "should update only specified group gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activemerchant", :group => :development gem "activesupport" G @@ -641,7 +641,7 @@ RSpec.describe "bundle update" do before do build_git "foo", path: lib_path("activesupport") install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport", :group => :development gem "foo", :git => "#{lib_path("activesupport")}" G @@ -660,13 +660,13 @@ RSpec.describe "bundle update" do context "when bundler itself is a transitive dependency" do it "executes without error" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", :group => :development - gem "rack" + gem "myrack" G update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "activesupport", "3.0" @@ -674,7 +674,7 @@ RSpec.describe "bundle update" do bundle "update --group development" expect(the_bundle).to include_gems "activesupport 2.3.5" expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}" - expect(the_bundle).not_to include_gems "rack 1.2" + expect(the_bundle).not_to include_gems "myrack 1.2" end end end @@ -684,9 +684,9 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" - gem "rack-obama" + gem "myrack-obama" gem "platform_specific" G end @@ -728,7 +728,7 @@ RSpec.describe "bundle update" do it "should not update gems not included in the source that happen to have the same name" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" G update_repo2 { build_gem "activesupport", "3.0" } @@ -739,7 +739,7 @@ RSpec.describe "bundle update" do it "should not update gems not included in the source that happen to have the same name" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" G update_repo2 { build_gem "activesupport", "3.0" } @@ -759,7 +759,7 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "harry" gem "fred" G @@ -791,7 +791,7 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "harry" gem "fred" G @@ -814,7 +814,7 @@ RSpec.describe "bundle update" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" G @@ -836,7 +836,7 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "bar" gem "foo" G @@ -849,13 +849,12 @@ RSpec.describe "bundle update" do end bundle "update", all: true - out.sub!("Removing foo (1.0)\n", "") - expect(out).to match(/Resolving dependencies\.\.\.\.*\nFetching foo 2\.0 \(was 1\.0\)\nInstalling foo 2\.0 \(was 1\.0\)\nBundle updated/) + expect(out.sub("Removing foo (1.0)\n", "")).to match(/Resolving dependencies\.\.\.\.*\nFetching foo 2\.0 \(was 1\.0\)\nInstalling foo 2\.0 \(was 1\.0\)\nBundle updated/) end it "shows error message when Gemfile.lock is not preset and gem is specified" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" G @@ -867,10 +866,10 @@ RSpec.describe "bundle update" do context "with multiple sources and caching enabled" do before do build_repo2 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" build_gem "request_store", "1.0.0" do |s| - s.add_dependency "rack", "1.0.0" + s.add_dependency "myrack", "1.0.0" end end @@ -879,24 +878,24 @@ RSpec.describe "bundle update" do end gemfile <<~G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "request_store" - source "#{file_uri_for(gem_repo4)}" do + source "https://gem.repo4" do end G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) request_store (1.0.0) - rack (= 1.0.0) + myrack (= 1.0.0) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: PLATFORMS @@ -916,7 +915,7 @@ RSpec.describe "bundle update" do update_repo2 do build_gem "request_store", "1.1.0" do |s| - s.add_dependency "rack", "1.0.0" + s.add_dependency "myrack", "1.0.0" end end @@ -926,14 +925,14 @@ RSpec.describe "bundle update" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) request_store (1.1.0) - rack (= 1.0.0) + myrack (= 1.0.0) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: PLATFORMS @@ -1018,49 +1017,49 @@ RSpec.describe "bundle update in more complicated situations" do it "will eagerly unlock dependencies of a specified gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "thin" - gem "rack-obama" + gem "myrack-obama" G update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "thin", "2.0" do |s| - s.add_dependency "rack" + s.add_dependency "myrack" end end bundle "update thin" - expect(the_bundle).to include_gems "thin 2.0", "rack 1.2", "rack-obama 1.0" + expect(the_bundle).to include_gems "thin 2.0", "myrack 1.2", "myrack-obama 1.0" end it "will warn when some explicitly updated gems are not updated" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "thin" - gem "rack-obama" + gem "myrack-obama" G update_repo2 do - build_gem("thin", "2.0") {|s| s.add_dependency "rack" } - build_gem "rack", "10.0" + build_gem("thin", "2.0") {|s| s.add_dependency "myrack" } + build_gem "myrack", "10.0" end - bundle "update thin rack-obama" - expect(last_command.stdboth).to include "Bundler attempted to update rack-obama but its version stayed the same" - expect(the_bundle).to include_gems "thin 2.0", "rack 10.0", "rack-obama 1.0" + bundle "update thin myrack-obama" + expect(last_command.stdboth).to include "Bundler attempted to update myrack-obama but its version stayed the same" + expect(the_bundle).to include_gems "thin 2.0", "myrack 10.0", "myrack-obama 1.0" end it "will not warn when an explicitly updated git gem changes sha but not version" do build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G @@ -1074,28 +1073,28 @@ RSpec.describe "bundle update in more complicated situations" do end it "will not warn when changing gem sources but not versions" do - build_git "rack" + build_git "myrack" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", :git => '#{lib_path("rack-1.0")}' + source "https://gem.repo2" + gem "myrack", :git => '#{lib_path("myrack-1.0")}' G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "update rack" + bundle "update myrack" expect(last_command.stdboth).not_to include "attempted to update" end it "will update only from pinned source" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - source "#{file_uri_for(gem_repo1)}" do + source "https://gem.repo1" do gem "thin" end G @@ -1104,7 +1103,7 @@ RSpec.describe "bundle update in more complicated situations" do build_gem "thin", "2.0" end - bundle "update" + bundle "update", artifice: "compact_index" expect(the_bundle).to include_gems "thin 1.0" end @@ -1118,13 +1117,13 @@ RSpec.describe "bundle update in more complicated situations" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "a" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: a (0.9-java) @@ -1157,13 +1156,13 @@ RSpec.describe "bundle update in more complicated situations" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "a", platform: :jruby G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: a (0.9-java) @@ -1190,14 +1189,14 @@ RSpec.describe "bundle update without a Gemfile.lock" do build_repo2 gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack", "1.0" + gem "myrack", "1.0" G bundle "update", all: true - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end @@ -1212,7 +1211,7 @@ RSpec.describe "bundle update when a gem depends on a newer version of bundler" end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0.1" G end @@ -1230,11 +1229,11 @@ RSpec.describe "bundle update --ruby" do before do install_gemfile <<-G ruby '~> #{Gem.ruby_version}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end @@ -1243,7 +1242,7 @@ RSpec.describe "bundle update --ruby" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1261,12 +1260,12 @@ RSpec.describe "bundle update --ruby" do before do install_gemfile <<-G ruby '~> #{Gem.ruby_version}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G gemfile <<-G ruby '~> #{current_ruby_minor}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end @@ -1275,7 +1274,7 @@ RSpec.describe "bundle update --ruby" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1296,12 +1295,12 @@ RSpec.describe "bundle update --ruby" do before do install_gemfile <<-G ruby '~> #{Gem.ruby_version}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G gemfile <<-G ruby '~> 2.1.0' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end it "shows a helpful error message" do @@ -1315,7 +1314,7 @@ RSpec.describe "bundle update --ruby" do before do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1334,7 +1333,7 @@ RSpec.describe "bundle update --ruby" do gemfile <<-G ruby '~> #{Gem.ruby_version}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G end @@ -1343,7 +1342,7 @@ RSpec.describe "bundle update --ruby" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1366,143 +1365,143 @@ end RSpec.describe "bundle update --bundler" do it "updates the bundler version in the lockfile" do build_repo4 do - build_gem "rack", "1.0" + build_gem "bundler", "2.5.9" + build_gem "myrack", "1.0" end checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo4, "rack", "1.0") + c.checksum(gem_repo4, "myrack", "1.0") end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} L lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') - bundle :update, bundler: true, artifice: "compact_index", verbose: true + bundle :update, bundler: true, verbose: true expect(out).to include("Using bundler #{Bundler::VERSION}") expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} L - expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).to include_gem "myrack 1.0" end it "updates the bundler version in the lockfile without re-resolving if the highest version is already installed" do - system_gems "bundler-2.3.9" - build_repo4 do - build_gem "rack", "1.0" + build_gem "bundler", "2.3.9" + build_gem "myrack", "1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo4, "rack", "1.0") + c.checksum(gem_repo4, "myrack", "1.0") end - bundle :update, bundler: true, artifice: "compact_index", verbose: true + bundle :update, bundler: true, verbose: true expect(out).to include("Using bundler #{Bundler::VERSION}") expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} L - expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).to include_gem "myrack 1.0" end it "updates the bundler version in the lockfile even if the latest version is not installed", :ruby_repo do - pristine_system_gems "bundler-2.3.9" + pristine_system_gems "bundler-2.99.9" build_repo4 do - build_gem "rack", "1.0" + build_gem "myrack", "1.0" build_bundler "999.0.0" end - install_gemfile <<-G, artifice: nil, env: { "BUNDLER_IGNORE_DEFAULT_GEM" => "true" } - source "#{file_uri_for(gem_repo4)}" - gem "rack" + install_gemfile <<-G + source "https://gem.repo4" + gem "myrack" G - lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.99.9") - bundle :update, bundler: true, artifice: "compact_index", verbose: true, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + bundle :update, bundler: true, verbose: true, preserve_ruby_flags: true # Only updates properly on modern RubyGems. if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") expect(out).to include("Updating bundler to 999.0.0") - expect(out).to include("Using bundler 999.0.0") - expect(out).not_to include("Installing Bundler 2.3.9 and restarting using that version.") + expect(out).to include("Running `bundle update --bundler \"> 0.a\" --verbose` with bundler 999.0.0") + expect(out).not_to include("Installing Bundler 2.99.9 and restarting using that version.") expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH 999.0.0 L expect(the_bundle).to include_gems "bundler 999.0.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" else # Old RubyGems versions do not trampoline but they still change BUNDLED # WITH to the latest bundler version. This means the below check fails # because it tries to use bundler 999.0.0 which did not get installed. # Workaround the bug by forcing the version we know is installed. - expect(the_bundle).to include_gems "rack 1.0", env: { "BUNDLER_VERSION" => "2.3.9" } + expect(the_bundle).to include_gems "myrack 1.0", env: { "BUNDLER_VERSION" => "2.99.9" } end end @@ -1510,27 +1509,27 @@ RSpec.describe "bundle update --bundler" do pristine_system_gems "bundler-2.99.0" build_repo4 do - build_gem "rack", "3.0.9.1" + build_gem "myrack", "3.0.9.1" build_bundler "2.99.0" end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (3.0.9.1) + myrack (3.0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH 2.99.0 @@ -1547,7 +1546,7 @@ RSpec.describe "bundle update --bundler" do pristine_system_gems "bundler-2.3.9" build_repo4 do - build_gem "rack", "1.0" + build_gem "myrack", "1.0" build_bundler "2.3.9" build_bundler "999.0.0" do |s| @@ -1556,8 +1555,8 @@ RSpec.describe "bundle update --bundler" do end install_gemfile <<-G, env: { "BUNDLER_IGNORE_DEFAULT_GEM" => "true" } - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") @@ -1567,34 +1566,34 @@ RSpec.describe "bundle update --bundler" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH 2.3.9 L expect(the_bundle).to include_gems "bundler 2.3.9" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "errors if the explicit target version does not exist" do pristine_system_gems "bundler-2.3.9" build_repo4 do - build_gem "rack", "1.0" + build_gem "myrack", "1.0" end install_gemfile <<-G, env: { "BUNDLER_IGNORE_DEFAULT_GEM" => "true" } - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") @@ -1612,12 +1611,12 @@ RSpec.describe "bundle update --bundler" do system_gems "bundler-2.3.0.dev" build_repo4 do - build_gem "rack", "1.0" + build_gem "myrack", "1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G bundle :update, bundler: "2.3.0.dev", verbose: "true" @@ -1625,20 +1624,20 @@ RSpec.describe "bundle update --bundler" do # Only updates properly on modern RubyGems. if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo4, "rack", "1.0") + c.checksum(gem_repo4, "myrack", "1.0") end expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH 2.3.0.dev @@ -1652,12 +1651,12 @@ RSpec.describe "bundle update --bundler" do system_gems "bundler-2.3.9" build_repo4 do - build_gem "rack", "1.0" + build_gem "myrack", "1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" G bundle :update, bundler: "2.3.9", verbose: true @@ -1666,21 +1665,21 @@ RSpec.describe "bundle update --bundler" do # Only updates properly on modern RubyGems. checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo4, "rack", "1.0") + c.checksum(gem_repo4, "myrack", "1.0") end if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH 2.3.9 @@ -1694,12 +1693,12 @@ RSpec.describe "bundle update --bundler" do system_gems "bundler-2.3.9" gemfile <<~G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: PLATFORMS @@ -1739,7 +1738,7 @@ RSpec.describe "bundle update conservative" do # establish a lockfile set to 1.4.3 install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo', '1.4.3' gem 'bar', '2.0.3' gem 'qux', '1.0.0' @@ -1748,7 +1747,7 @@ RSpec.describe "bundle update conservative" do # remove 1.4.3 requirement and bar altogether # to setup update specs below gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'foo' gem 'qux' G @@ -1844,7 +1843,7 @@ RSpec.describe "bundle update conservative" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'isolated_owner' gem 'shared_owner_a' @@ -1853,7 +1852,7 @@ RSpec.describe "bundle update conservative" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: isolated_dep (2.0.1) isolated_owner (1.0.1) @@ -1906,9 +1905,17 @@ RSpec.describe "bundle update conservative" do it "should only change direct dependencies when updating the lockfile with --conservative" do bundle "lock --update --conservative" + checksums = checksums_section_when_existing do |c| + c.checksum gem_repo4, "isolated_dep", "2.0.1" + c.checksum gem_repo4, "isolated_owner", "1.0.2" + c.checksum gem_repo4, "shared_dep", "5.0.1" + c.checksum gem_repo4, "shared_owner_a", "3.0.2" + c.checksum gem_repo4, "shared_owner_b", "4.0.2" + end + expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: isolated_dep (2.0.1) isolated_owner (1.0.2) @@ -1926,14 +1933,7 @@ RSpec.describe "bundle update conservative" do isolated_owner shared_owner_a shared_owner_b - - CHECKSUMS - isolated_dep (2.0.1) - isolated_owner (1.0.2) - shared_dep (5.0.1) - shared_owner_a (3.0.2) - shared_owner_b (4.0.2) - + #{checksums} BUNDLED WITH #{Bundler::VERSION} L @@ -1941,7 +1941,7 @@ RSpec.describe "bundle update conservative" do it "should match bundle install conservative update behavior when not eagerly unlocking" do gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'isolated_owner', '1.0.2' gem 'shared_owner_a', '3.0.2' @@ -1969,14 +1969,14 @@ RSpec.describe "bundle update conservative" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri", ">=1.16.4" gem "prism", ">=0.25.0" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.16.4-arm64-darwin) nokogiri (1.16.4-x86_64-linux) @@ -2002,7 +2002,7 @@ RSpec.describe "bundle update conservative" do context "error handling" do before do - gemfile "source \"#{file_uri_for(gem_repo1)}\"" + gemfile "source 'https://gem.repo1'" end it "raises if too many flags are provided" do diff --git a/spec/bundler/commands/viz_spec.rb b/spec/bundler/commands/viz_spec.rb index f8b5f7836e..c26e3c81ed 100644 --- a/spec/bundler/commands/viz_spec.rb +++ b/spec/bundler/commands/viz_spec.rb @@ -7,9 +7,9 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld it "graphs gems from the Gemfile" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G bundle "viz" @@ -25,11 +25,11 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld node[ fontname = "Arial, Helvetica, SansSerif"]; edge[ fontname = "Arial, Helvetica, SansSerif" , fontsize = "12"]; default [style = "filled", fillcolor = "#B9B9D5", shape = "box3d", fontsize = "16", label = "default"]; - rack [style = "filled", fillcolor = "#B9B9D5", label = "rack"]; - default -> rack [constraint = "false"]; - "rack-obama" [style = "filled", fillcolor = "#B9B9D5", label = "rack-obama"]; - default -> "rack-obama" [constraint = "false"]; - "rack-obama" -> rack; + myrack [style = "filled", fillcolor = "#B9B9D5", label = "myrack"]; + default -> myrack [constraint = "false"]; + "myrack-obama" [style = "filled", fillcolor = "#B9B9D5", label = "myrack-obama"]; + default -> "myrack-obama" [constraint = "false"]; + "myrack-obama" -> myrack; } debugging bundle viz... DOT @@ -37,13 +37,13 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld it "graphs gems that are prereleases" do build_repo2 do - build_gem "rack", "1.3.pre" + build_gem "myrack", "1.3.pre" end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack", "= 1.3.pre" - gem "rack-obama" + source "https://gem.repo2" + gem "myrack", "= 1.3.pre" + gem "myrack-obama" G bundle "viz" @@ -59,11 +59,11 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld node[ fontname = "Arial, Helvetica, SansSerif"]; edge[ fontname = "Arial, Helvetica, SansSerif" , fontsize = "12"]; default [style = "filled", fillcolor = "#B9B9D5", shape = "box3d", fontsize = "16", label = "default"]; - rack [style = "filled", fillcolor = "#B9B9D5", label = "rack\\n1.3.pre"]; - default -> rack [constraint = "false"]; - "rack-obama" [style = "filled", fillcolor = "#B9B9D5", label = "rack-obama\\n1.0"]; - default -> "rack-obama" [constraint = "false"]; - "rack-obama" -> rack; + myrack [style = "filled", fillcolor = "#B9B9D5", label = "myrack\\n1.3.pre"]; + default -> myrack [constraint = "false"]; + "myrack-obama" [style = "filled", fillcolor = "#B9B9D5", label = "myrack-obama\\n1.0"]; + default -> "myrack-obama" [constraint = "false"]; + "myrack-obama" -> myrack; } debugging bundle viz... EOS @@ -82,9 +82,9 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld it "loads the correct ruby-graphviz gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G bundle "viz", format: "debug" @@ -97,11 +97,11 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld node[ fontname = "Arial, Helvetica, SansSerif"]; edge[ fontname = "Arial, Helvetica, SansSerif" , fontsize = "12"]; default [style = "filled", fillcolor = "#B9B9D5", shape = "box3d", fontsize = "16", label = "default"]; - rack [style = "filled", fillcolor = "#B9B9D5", label = "rack"]; - default -> rack [constraint = "false"]; - "rack-obama" [style = "filled", fillcolor = "#B9B9D5", label = "rack-obama"]; - default -> "rack-obama" [constraint = "false"]; - "rack-obama" -> rack; + myrack [style = "filled", fillcolor = "#B9B9D5", label = "myrack"]; + default -> myrack [constraint = "false"]; + "myrack-obama" [style = "filled", fillcolor = "#B9B9D5", label = "myrack-obama"]; + default -> "myrack-obama" [constraint = "false"]; + "myrack-obama" -> myrack; } debugging bundle viz... DOT @@ -111,7 +111,7 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld context "--without option" do it "one group" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" group :rails do @@ -125,11 +125,11 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld it "two groups" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" - group :rack do - gem "rack" + group :myrack do + gem "myrack" end group :rails do @@ -137,7 +137,7 @@ RSpec.describe "bundle viz", bundler: "< 3", if: Bundler.which("dot"), realworld end G - bundle "viz --without=rails:rack" + bundle "viz --without=rails:myrack" expect(out).to include("gem_graph.png") end end diff --git a/spec/bundler/install/allow_offline_install_spec.rb b/spec/bundler/install/allow_offline_install_spec.rb index 8da94718e0..2d313531e0 100644 --- a/spec/bundler/install/allow_offline_install_spec.rb +++ b/spec/bundler/install/allow_offline_install_spec.rb @@ -9,15 +9,15 @@ RSpec.describe "bundle install with :allow_offline_install" do it "still installs" do install_gemfile <<-G, artifice: "compact_index" source "http://testgemserver.local" - gem "rack-obama" + gem "myrack-obama" G - expect(the_bundle).to include_gem("rack 1.0") + expect(the_bundle).to include_gem("myrack 1.0") end it "still fails when the network is down" do install_gemfile <<-G, artifice: "fail", raise_on_error: false source "http://testgemserver.local" - gem "rack-obama" + gem "myrack-obama" G expect(err).to include("Could not reach host testgemserver.local.") expect(the_bundle).to_not be_locked @@ -26,26 +26,26 @@ RSpec.describe "bundle install with :allow_offline_install" do context "with cached data locally" do it "will install from the compact index" do - system_gems ["rack-1.0.0"], path: default_bundle_path + system_gems ["myrack-1.0.0"], path: default_bundle_path bundle "config set clean false" install_gemfile <<-G, artifice: "compact_index" source "http://testgemserver.local" - gem "rack-obama" - gem "rack", "< 1.0" + gem "myrack-obama" + gem "myrack", "< 1.0" G - expect(the_bundle).to include_gems("rack-obama 1.0", "rack 0.9.1") + expect(the_bundle).to include_gems("myrack-obama 1.0", "myrack 0.9.1") gemfile <<-G source "http://testgemserver.local" - gem "rack-obama" + gem "myrack-obama" G bundle :update, artifice: "fail", all: true expect(last_command.stdboth).to include "Using the cached data for the new index because of a network error" - expect(the_bundle).to include_gems("rack-obama 1.0", "rack 1.0.0") + expect(the_bundle).to include_gems("myrack-obama 1.0", "myrack 1.0.0") end def break_git_remote_ops! @@ -78,7 +78,7 @@ RSpec.describe "bundle install with :allow_offline_install" do git = build_git "a", "1.0.0", path: lib_path("a") update_git("a", path: git.path, branch: "new_branch") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "a", :git => #{git.path.to_s.dump} G @@ -88,7 +88,7 @@ RSpec.describe "bundle install with :allow_offline_install" do break_git_remote_ops! do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "a", :git => #{git.path.to_s.dump}, :branch => "new_branch" G end diff --git a/spec/bundler/install/binstubs_spec.rb b/spec/bundler/install/binstubs_spec.rb index 928ba80b15..00765ac6dd 100644 --- a/spec/bundler/install/binstubs_spec.rb +++ b/spec/bundler/install/binstubs_spec.rb @@ -6,14 +6,14 @@ RSpec.describe "bundle install" do expect(Pathname.new("/usr/bin")).not_to be_writable gemfile <<-G def Gem.bindir; "/usr/bin"; end - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G config "BUNDLE_SYSTEM_BINDIR" => system_gem_path("altbin").to_s bundle :install - expect(the_bundle).to include_gems "rack 1.0.0" - expect(system_gem_path("altbin/rackup")).to exist + expect(the_bundle).to include_gems "myrack 1.0.0" + expect(system_gem_path("altbin/myrackup")).to exist end end @@ -21,26 +21,26 @@ RSpec.describe "bundle install" do before do build_repo2 do build_gem "fake", "14" do |s| - s.executables = "rackup" + s.executables = "myrackup" end end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "fake" - gem "rack" + gem "myrack" G end it "warns about the situation" do - bundle "exec rackup" + bundle "exec myrackup" expect(last_command.stderr).to include( - "The `rackup` executable in the `fake` gem is being loaded, but it's also present in other gems (rack).\n" \ + "The `myrackup` executable in the `fake` gem is being loaded, but it's also present in other gems (myrack).\n" \ "If you meant to run the executable for another gem, make sure you use a project specific binstub (`bundle binstub <gem_name>`).\n" \ "If you plan to use multiple conflicting executables, generate binstubs for them and disambiguate their names." ).or include( - "The `rackup` executable in the `rack` gem is being loaded, but it's also present in other gems (fake).\n" \ + "The `myrackup` executable in the `myrack` gem is being loaded, but it's also present in other gems (fake).\n" \ "If you meant to run the executable for another gem, make sure you use a project specific binstub (`bundle binstub <gem_name>`).\n" \ "If you plan to use multiple conflicting executables, generate binstubs for them and disambiguate their names." ) diff --git a/spec/bundler/install/bundler_spec.rb b/spec/bundler/install/bundler_spec.rb index 19911f1154..95edf7859d 100644 --- a/spec/bundler/install/bundler_spec.rb +++ b/spec/bundler/install/bundler_spec.rb @@ -14,7 +14,7 @@ RSpec.describe "bundle install" do it "are forced to the current bundler version" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" G @@ -23,15 +23,15 @@ RSpec.describe "bundle install" do it "are forced to the current bundler version even if not already present" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}" end it "causes a conflict if explicitly requesting a different version of bundler" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" gem "bundler", "0.9.1" G @@ -51,7 +51,7 @@ RSpec.describe "bundle install" do it "causes a conflict if explicitly requesting a non matching requirement on bundler" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" gem "bundler", "~> 0.8" G @@ -74,7 +74,7 @@ RSpec.describe "bundle install" do it "causes a conflict if explicitly requesting a version of bundler that doesn't exist" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" gem "bundler", "0.9.2" G @@ -99,16 +99,16 @@ RSpec.describe "bundle install" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "multiple_versioned_deps" G install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "multiple_versioned_deps" - gem "rack" + gem "myrack" G expect(the_bundle).to include_gems "multiple_versioned_deps 1.0.0" @@ -116,7 +116,7 @@ RSpec.describe "bundle install" do it "includes bundler in the bundle when it's a child dependency" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" G @@ -126,8 +126,8 @@ RSpec.describe "bundle install" do it "allows gem 'bundler' when Bundler is not in the Gemfile or its dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G run "begin; gem 'bundler'; puts 'WIN'; rescue Gem::LoadError => e; puts e.backtrace; end" @@ -144,7 +144,7 @@ RSpec.describe "bundle install" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activemerchant" gem "rails_pinned_to_old_activesupport" G @@ -172,7 +172,7 @@ RSpec.describe "bundle install" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails_pinned_to_old_activesupport" gem "activesupport", "2.3.5" G @@ -197,12 +197,12 @@ RSpec.describe "bundle install" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'rails', "2.3.2" G install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails_pinned_to_old_activesupport" G @@ -219,17 +219,17 @@ RSpec.describe "bundle install" do bundle "config set path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'rails', "7.0.4" G install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'rails', "7.0.3" G install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'rails', "7.0.4" G @@ -243,7 +243,7 @@ RSpec.describe "bundle install" do system_gems "bundler-99999999.99.1" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" G @@ -257,7 +257,7 @@ RSpec.describe "bundle install" do system_gems "bundler-99999999.99.1" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0" G diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index d89fdea6f1..dfb352f170 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -3,8 +3,8 @@ RSpec.describe "install in deployment or frozen mode" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -37,7 +37,7 @@ RSpec.describe "install in deployment or frozen mode" do it "doesn't mess up a subsequent `bundle install` after you try to deploy without a lock" do bundle "install --deployment", raise_on_error: false bundle :install - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "installs gems by default to vendor/bundle" do @@ -60,15 +60,15 @@ RSpec.describe "install in deployment or frozen mode" do it "explodes with the --deployment flag if you make a change and don't check in the lockfile" do bundle :lock gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G bundle "install --deployment", raise_on_error: false expect(err).to include("frozen mode") expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") + expect(err).to include("* myrack-obama") expect(err).not_to include("You have deleted from the Gemfile") expect(err).not_to include("You have changed in the Gemfile") end @@ -80,13 +80,13 @@ RSpec.describe "install in deployment or frozen mode" do bundle "config set --local deployment true" bundle "config set --local path vendor/bundle" bundle "install --gemfile #{tmp}/bundled_app/Gemfile", dir: tmp - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "works if you exclude a group with a git gem" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" group :test do gem "foo", :git => "#{lib_path("foo-1.0")}" end @@ -110,7 +110,7 @@ RSpec.describe "install in deployment or frozen mode" do build_lib "foo", path: lib_path("nested/foo") build_lib "bar", path: lib_path("nested/bar") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.0", :path => "#{lib_path("nested")}" gem "bar", :path => "#{lib_path("nested")}" G @@ -123,7 +123,7 @@ RSpec.describe "install in deployment or frozen mode" do it "works when path gems are specified twice" do build_lib "foo", path: lib_path("nested/foo") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("nested/foo")}" gem "foo", :path => "#{lib_path("nested/foo")}" G @@ -137,7 +137,7 @@ RSpec.describe "install in deployment or frozen mode" do install_gemfile(<<-G, artifice: "endpoint_strict_basic_authentication", quiet: true) source "http://user:[email protected]/" - gem "rack-obama", ">= 1.0" + gem "myrack-obama", ">= 1.0" G bundle "config set --local deployment true" @@ -146,16 +146,16 @@ RSpec.describe "install in deployment or frozen mode" do it "works with sources given by a block" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - source "#{file_uri_for(gem_repo1)}" do - gem "rack" + source "https://gem.repo1" + source "https://gem.repo1" do + gem "myrack" end G bundle "config set --local deployment true" bundle :install - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end context "when replacing a host with the same host with credentials" do @@ -164,20 +164,20 @@ RSpec.describe "install in deployment or frozen mode" do bundle "install" gemfile <<-G source "http://user_name:[email protected]/" - gem "rack" + gem "myrack" G lockfile <<-G GEM remote: http://localgemserver.test/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{generic_local_platform} DEPENDENCIES - rack + myrack G bundle "config set --local deployment true" @@ -231,16 +231,16 @@ RSpec.describe "install in deployment or frozen mode" do it "explodes with the `deployment` setting if you make a change and don't check in the lockfile" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G bundle "config set --local deployment true" bundle :install, raise_on_error: false expect(err).to include("frozen mode") expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") + expect(err).to include("* myrack-obama") expect(err).not_to include("You have deleted from the Gemfile") expect(err).not_to include("You have changed in the Gemfile") end @@ -248,7 +248,7 @@ RSpec.describe "install in deployment or frozen mode" do it "works if a path gem is missing but is in a without group" do build_lib "path_gem" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" gem "path_gem", :path => "#{lib_path("path_gem-1.0")}", :group => :development G @@ -267,9 +267,9 @@ RSpec.describe "install in deployment or frozen mode" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - source "#{file_uri_for(gem_repo1)}" do + source "https://gem.repo1" do gem "rake", platform: :#{not_local_tag} end G @@ -315,7 +315,7 @@ RSpec.describe "install in deployment or frozen mode" do it "explodes if a path gem is missing" do build_lib "path_gem" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" gem "path_gem", :path => "#{lib_path("path_gem-1.0")}", :group => :development G @@ -330,32 +330,32 @@ RSpec.describe "install in deployment or frozen mode" do it "can have --frozen set via an environment variable" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G ENV["BUNDLE_FROZEN"] = "1" bundle "install", raise_on_error: false expect(err).to include("frozen mode") expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") + expect(err).to include("* myrack-obama") expect(err).not_to include("You have deleted from the Gemfile") expect(err).not_to include("You have changed in the Gemfile") end it "can have --deployment set via an environment variable" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G ENV["BUNDLE_DEPLOYMENT"] = "true" bundle "install", raise_on_error: false expect(err).to include("frozen mode") expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") + expect(err).to include("* myrack-obama") expect(err).not_to include("You have deleted from the Gemfile") expect(err).not_to include("You have changed in the Gemfile") end @@ -375,9 +375,9 @@ RSpec.describe "install in deployment or frozen mode" do it "can have --frozen set to false via an environment variable" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G ENV["BUNDLE_FROZEN"] = "false" @@ -385,12 +385,12 @@ RSpec.describe "install in deployment or frozen mode" do bundle "install" expect(out).not_to include("frozen mode") expect(out).not_to include("You have added to the Gemfile") - expect(out).not_to include("* rack-obama") + expect(out).not_to include("* myrack-obama") end - it "explodes if you remove a gem and don't check in the lockfile" do + it "explodes if you replace a gem and don't check in the lockfile" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" G @@ -398,34 +398,45 @@ RSpec.describe "install in deployment or frozen mode" do bundle :install, raise_on_error: false expect(err).to include("frozen mode") expect(err).to include("You have added to the Gemfile:\n* activesupport\n\n") - expect(err).to include("You have deleted from the Gemfile:\n* rack") + expect(err).to include("You have deleted from the Gemfile:\n* myrack") + expect(err).not_to include("You have changed in the Gemfile") + end + + it "explodes if you remove a gem and don't check in the lockfile" do + gemfile 'source "https://gem.repo1"' + + bundle "config set --local deployment true" + bundle :install, raise_on_error: false + expect(err).to include("Some dependencies were deleted") + expect(err).to include("frozen mode") + expect(err).to include("You have deleted from the Gemfile:\n* myrack") expect(err).not_to include("You have changed in the Gemfile") end it "explodes if you add a source" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "git://hubz.com" + source "https://gem.repo1" + gem "myrack", :git => "git://hubz.com" G bundle "config set --local deployment true" bundle :install, raise_on_error: false expect(err).to include("frozen mode") expect(err).not_to include("You have added to the Gemfile") - expect(err).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `git://hubz.com`") + expect(err).to include("You have changed in the Gemfile:\n* myrack from `no specified source` to `git://hubz.com`") end it "explodes if you change a source" do - build_git "rack" + build_git "myrack" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-1.0")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-1.0")}" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set --local deployment true" @@ -433,29 +444,29 @@ RSpec.describe "install in deployment or frozen mode" do expect(err).to include("frozen mode") expect(err).not_to include("You have deleted from the Gemfile") expect(err).not_to include("You have added to the Gemfile") - expect(err).to include("You have changed in the Gemfile:\n* rack from `#{lib_path("rack-1.0")}` to `no specified source`") + expect(err).to include("You have changed in the Gemfile:\n* myrack from `#{lib_path("myrack-1.0")}` to `no specified source`") end it "explodes if you change a source" do - build_lib "foo", path: lib_path("rack/foo") - build_git "rack", path: lib_path("rack") + build_lib "foo", path: lib_path("myrack/foo") + build_git "myrack", path: lib_path("myrack") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack")}" - gem "foo", :git => "#{lib_path("rack")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack")}" + gem "foo", :git => "#{lib_path("myrack")}" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "foo", :git => "#{lib_path("rack")}" + source "https://gem.repo1" + gem "myrack" + gem "foo", :git => "#{lib_path("myrack")}" G bundle "config set --local deployment true" bundle :install, raise_on_error: false expect(err).to include("frozen mode") - expect(err).to include("You have changed in the Gemfile:\n* rack from `#{lib_path("rack")}` to `no specified source`") + expect(err).to include("You have changed in the Gemfile:\n* myrack from `#{lib_path("myrack")}` to `no specified source`") expect(err).not_to include("You have added to the Gemfile") expect(err).not_to include("You have deleted from the Gemfile") end @@ -466,21 +477,21 @@ RSpec.describe "install in deployment or frozen mode" do bundle "config set --local deployment true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack", "1.0.0" + gem "myrack-obama" G - run "require 'rack'", raise_on_error: false + run "require 'myrack'", raise_on_error: false expect(err).to include <<~E.strip The dependencies in your gemfile changed, but the lockfile can't be updated because frozen mode is set (Bundler::ProductionError) You have added to the Gemfile: - * rack (= 1.0.0) - * rack-obama + * myrack (= 1.0.0) + * myrack-obama You have deleted from the Gemfile: - * rack + * myrack E end end @@ -489,7 +500,7 @@ RSpec.describe "install in deployment or frozen mode" do it "works fine after bundle package and bundle install --local" do build_lib "foo", path: lib_path("foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G diff --git a/spec/bundler/install/failure_spec.rb b/spec/bundler/install/failure_spec.rb index f972a37bf6..2c2773e849 100644 --- a/spec/bundler/install/failure_spec.rb +++ b/spec/bundler/install/failure_spec.rb @@ -15,7 +15,7 @@ RSpec.describe "bundle install" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" G expect(err).to start_with("Gem::Ext::BuildError: ERROR: Failed to build gem native extension.") @@ -40,7 +40,7 @@ In Gemfile: it "removes the downloaded .gem" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "a" G diff --git a/spec/bundler/install/gemfile/eval_gemfile_spec.rb b/spec/bundler/install/gemfile/eval_gemfile_spec.rb index cfa66e5986..a507e52485 100644 --- a/spec/bundler/install/gemfile/eval_gemfile_spec.rb +++ b/spec/bundler/install/gemfile/eval_gemfile_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do before do - build_lib("gunks", path: bundled_app.join("gems/gunks")) do |s| + build_lib("gunks", path: bundled_app("gems/gunks")) do |s| s.name = "gunks" s.version = "0.0.1" end @@ -10,15 +10,15 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do context "eval-ed Gemfile points to an internal gemspec" do before do - create_file "Gemfile-other", <<-G - source "#{file_uri_for(gem_repo1)}" + gemfile "Gemfile-other", <<-G + source "https://gem.repo1" gemspec :path => 'gems/gunks' G end it "installs the gemspec specified gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile 'Gemfile-other' G expect(out).to include("Resolving dependencies") @@ -36,12 +36,12 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do build_gem "zip-zip", "0.3" end - create_file bundled_app("gems/Gemfile"), <<-G - source "#{file_uri_for(gem_repo2)}" + gemfile bundled_app("gems/Gemfile"), <<-G + source "https://gem.repo2" gemspec :path => "\#{__dir__}/gunks" - source "#{file_uri_for(gem_repo2)}" do + source "https://gem.repo2" do gem "zip-zip" end G @@ -49,7 +49,7 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do it "installs and finds gems correctly" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails" @@ -65,13 +65,13 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do context "eval-ed Gemfile has relative-path gems" do before do build_lib("a", path: bundled_app("gems/a")) - create_file bundled_app("nested/Gemfile-nested"), <<-G - source "#{file_uri_for(gem_repo1)}" + gemfile bundled_app("nested/Gemfile-nested"), <<-G + source "https://gem.repo1" gem "a", :path => "../gems/a" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile "nested/Gemfile-nested" G end @@ -95,7 +95,7 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do it "installs the gemspec specified gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" eval_gemfile 'other/Gemfile-other' gemspec :path => 'gems/gunks' G @@ -108,15 +108,15 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do context "eval-ed Gemfile references other gemfiles" do it "works with relative paths" do - create_file "other/Gemfile-other", "gem 'rack'" - create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'" - create_file "Gemfile-alt", <<-G - source "#{file_uri_for(gem_repo1)}" + gemfile "other/Gemfile-other", "gem 'myrack'" + gemfile "other/Gemfile", "eval_gemfile 'Gemfile-other'" + gemfile "Gemfile-alt", <<-G + source "https://gem.repo1" eval_gemfile "other/Gemfile" G install_gemfile "eval_gemfile File.expand_path('Gemfile-alt')" - expect(the_bundle).to include_gem "rack 1.0.0" + expect(the_bundle).to include_gem "myrack 1.0.0" end end end diff --git a/spec/bundler/install/gemfile/force_ruby_platform_spec.rb b/spec/bundler/install/gemfile/force_ruby_platform_spec.rb index a29b79ad62..1e61369519 100644 --- a/spec/bundler/install/gemfile/force_ruby_platform_spec.rb +++ b/spec/bundler/install/gemfile/force_ruby_platform_spec.rb @@ -5,77 +5,68 @@ RSpec.describe "bundle install with force_ruby_platform DSL option", :jruby do before do build_repo4 do # Build a gem with platform specific versions - build_gem("platform_specific") do |s| - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'" - end + build_gem("platform_specific") build_gem("platform_specific") do |s| s.platform = Bundler.local_platform - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'" end # Build the exact same gem with a different name to compare using vs not using the option - build_gem("platform_specific_forced") do |s| - s.write "lib/platform_specific_forced.rb", "PLATFORM_SPECIFIC_FORCED = '1.0.0 RUBY'" - end + build_gem("platform_specific_forced") build_gem("platform_specific_forced") do |s| s.platform = Bundler.local_platform - s.write "lib/platform_specific_forced.rb", "PLATFORM_SPECIFIC_FORCED = '1.0.0 #{Bundler.local_platform}'" end end end it "pulls the pure ruby variant of the given gem" do install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "platform_specific_forced", :force_ruby_platform => true gem "platform_specific" G - expect(the_bundle).to include_gems "platform_specific_forced 1.0.0 RUBY" - expect(the_bundle).to include_gems "platform_specific 1.0.0 #{Bundler.local_platform}" + expect(the_bundle).to include_gems "platform_specific_forced 1.0 ruby" + expect(the_bundle).to include_gems "platform_specific 1.0 #{Bundler.local_platform}" end it "still respects a global `force_ruby_platform` config" do install_gemfile <<-G, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "true" } - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "platform_specific_forced", :force_ruby_platform => true gem "platform_specific" G - expect(the_bundle).to include_gems "platform_specific_forced 1.0.0 RUBY" - expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY" + expect(the_bundle).to include_gems "platform_specific_forced 1.0 ruby" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" end end context "when also a transitive dependency" do before do build_repo4 do - build_gem("depends_on_platform_specific") {|s| s.add_runtime_dependency "platform_specific" } + build_gem("depends_on_platform_specific") {|s| s.add_dependency "platform_specific" } - build_gem("platform_specific") do |s| - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'" - end + build_gem("platform_specific") build_gem("platform_specific") do |s| s.platform = Bundler.local_platform - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'" end end end it "still pulls the ruby variant" do install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "depends_on_platform_specific" gem "platform_specific", :force_ruby_platform => true G - expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" end end @@ -83,42 +74,37 @@ RSpec.describe "bundle install with force_ruby_platform DSL option", :jruby do before do build_repo4 do build_gem("depends_on_platform_specific") do |s| - s.add_runtime_dependency "platform_specific" - s.write "lib/depends_on_platform_specific.rb", "DEPENDS_ON_PLATFORM_SPECIFIC = '1.0.0 RUBY'" + s.add_dependency "platform_specific" end build_gem("depends_on_platform_specific") do |s| - s.add_runtime_dependency "platform_specific" + s.add_dependency "platform_specific" s.platform = Bundler.local_platform - s.write "lib/depends_on_platform_specific.rb", "DEPENDS_ON_PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'" end - build_gem("platform_specific") do |s| - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'" - end + build_gem("platform_specific") build_gem("platform_specific") do |s| s.platform = Bundler.local_platform - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Bundler.local_platform}'" end end end it "ignores ruby variants for the transitive dependencies" do install_gemfile <<-G, env: { "DEBUG_RESOLVER" => "true" } - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "depends_on_platform_specific", :force_ruby_platform => true G - expect(the_bundle).to include_gems "depends_on_platform_specific 1.0.0 RUBY" - expect(the_bundle).to include_gems "platform_specific 1.0.0 #{Bundler.local_platform}" + expect(the_bundle).to include_gems "depends_on_platform_specific 1.0 ruby" + expect(the_bundle).to include_gems "platform_specific 1.0 #{Bundler.local_platform}" end - it "reinstalls the ruby variant when a platform specific variant is already installed, the lockile has only RUBY platform, and :force_ruby_platform is used in the Gemfile" do + it "reinstalls the ruby variant when a platform specific variant is already installed, the lockile has only ruby platform, and :force_ruby_platform is used in the Gemfile" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: platform_specific (1.0) @@ -135,12 +121,12 @@ RSpec.describe "bundle install with force_ruby_platform DSL option", :jruby do system_gems "platform_specific-1.0-#{Gem::Platform.local}", path: default_bundle_path install_gemfile <<-G, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }, artifice: "compact_index" - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "platform_specific", :force_ruby_platform => true G - expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" end end end diff --git a/spec/bundler/install/gemfile/gemspec_spec.rb b/spec/bundler/install/gemfile/gemspec_spec.rb index 63778567cf..2f3eb3236c 100644 --- a/spec/bundler/install/gemfile/gemspec_spec.rb +++ b/spec/bundler/install/gemfile/gemspec_spec.rb @@ -39,14 +39,14 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should install runtime and development dependencies" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("Gemfile", "source :rubygems\ngemspec") s.add_dependency "bar", "=1.0.0" s.add_development_dependency "bar-dev", "=1.0.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}' G expect(the_bundle).to include_gems "bar 1.0.0" @@ -54,16 +54,16 @@ RSpec.describe "bundle install from an existing gemspec" do end it "that is hidden should install runtime and development dependencies" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("Gemfile", "source :rubygems\ngemspec") s.add_dependency "bar", "=1.0.0" s.add_development_dependency "bar-dev", "=1.0.0" end - FileUtils.mv tmp.join("foo", "foo.gemspec"), tmp.join("foo", ".gemspec") + FileUtils.mv tmp("foo", "foo.gemspec"), tmp("foo", ".gemspec") install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}' G expect(the_bundle).to include_gems "bar 1.0.0" @@ -76,50 +76,50 @@ RSpec.describe "bundle install from an existing gemspec" do build_gem "baz", "1.1" end - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("Gemfile", "source :rubygems\ngemspec") s.add_dependency "baz", ">= 1.0", "< 1.1" end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}' G expect(the_bundle).to include_gems "baz 1.0" end it "should raise if there are no gemspecs available" do - build_lib("foo", path: tmp.join("foo"), gemspec: false) + build_lib("foo", path: tmp("foo"), gemspec: false) install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}' G - expect(err).to match(/There are no gemspecs at #{tmp.join("foo")}/) + expect(err).to match(/There are no gemspecs at #{tmp("foo")}/) end it "should raise if there are too many gemspecs available" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("foo2.gemspec", build_spec("foo", "4.0").first.to_ruby) end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}' G - expect(err).to match(/There are multiple gemspecs at #{tmp.join("foo")}/) + expect(err).to match(/There are multiple gemspecs at #{tmp("foo")}/) end it "should pick a specific gemspec" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("foo2.gemspec", "") s.add_dependency "bar", "=1.0.0" s.add_development_dependency "bar-dev", "=1.0.0" end install_gemfile(<<-G) - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}', :name => 'foo' G expect(the_bundle).to include_gems "bar 1.0.0" @@ -127,15 +127,15 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should use a specific group for development dependencies" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.write("foo2.gemspec", "") s.add_dependency "bar", "=1.0.0" s.add_development_dependency "bar-dev", "=1.0.0" end install_gemfile(<<-G) - source "#{file_uri_for(gem_repo2)}" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo', :development_group => :dev + source "https://gem.repo2" + gemspec :path => '#{tmp("foo")}', :name => 'foo', :development_group => :dev G expect(the_bundle).to include_gems "bar 1.0.0" @@ -144,33 +144,33 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should match a lockfile even if the gemspec defines development dependencies" do - build_lib("foo", path: tmp.join("foo")) do |s| - s.write("Gemfile", "source '#{file_uri_for(gem_repo1)}'\ngemspec") + build_lib("foo", path: tmp("foo")) do |s| + s.write("Gemfile", "source 'https://gem.repo1'\ngemspec") s.add_dependency "actionpack", "=2.3.2" s.add_development_dependency "rake", rake_version end - bundle "install", dir: tmp.join("foo") + bundle "install", dir: tmp("foo"), artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } # This should really be able to rely on $stderr, but, it's not written # right, so we can't. In fact, this is a bug negation test, and so it'll # ghost pass in future, and will only catch a regression if the message # doesn't change. Exit codes should be used correctly (they can be more # than just 0 and 1). bundle "config set --local deployment true" - output = bundle("install", dir: tmp.join("foo")) + output = bundle("install", dir: tmp("foo"), artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s }) expect(output).not_to match(/You have added to the Gemfile/) expect(output).not_to match(/You have deleted from the Gemfile/) expect(output).not_to match(/the lockfile can't be updated because frozen mode is set/) end it "should match a lockfile without needing to re-resolve" do - build_lib("foo", path: tmp.join("foo")) do |s| - s.add_dependency "rack" + build_lib("foo", path: tmp("foo")) do |s| + s.add_dependency "myrack" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo1" + gemspec :path => '#{tmp("foo")}' G bundle "install", verbose: true @@ -182,14 +182,14 @@ RSpec.describe "bundle install from an existing gemspec" do it "should match a lockfile without needing to re-resolve with development dependencies" do simulate_platform java - build_lib("foo", path: tmp.join("foo")) do |s| - s.add_dependency "rack" + build_lib("foo", path: tmp("foo")) do |s| + s.add_dependency "myrack" s.add_development_dependency "thin" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gemspec :path => '#{tmp.join("foo")}' + source "https://gem.repo1" + gemspec :path => '#{tmp("foo")}' G bundle "install", verbose: true @@ -199,28 +199,28 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should match a lockfile on non-ruby platforms with a transitive platform dependency", :jruby_only do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.add_dependency "platform_specific" end system_gems "platform_specific-1.0-java", path: default_bundle_path install_gemfile <<-G - gemspec :path => '#{tmp.join("foo")}' + gemspec :path => '#{tmp("foo")}' G bundle "update --bundler", artifice: "compact_index", verbose: true - expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 JAVA" + expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 java" end it "should evaluate the gemspec in its directory" do - build_lib("foo", path: tmp.join("foo")) - File.open(tmp.join("foo/foo.gemspec"), "w") do |s| - s.write "raise 'ahh' unless Dir.pwd == '#{tmp.join("foo")}'" + build_lib("foo", path: tmp("foo")) + File.open(tmp("foo/foo.gemspec"), "w") do |s| + s.write "raise 'ahh' unless Dir.pwd == '#{tmp("foo")}'" end install_gemfile <<-G, raise_on_error: false - gemspec :path => '#{tmp.join("foo")}' + gemspec :path => '#{tmp("foo")}' G expect(last_command.stdboth).not_to include("ahh") end @@ -231,16 +231,16 @@ RSpec.describe "bundle install from an existing gemspec" do # # issue was caused by rubygems having an unresolved gem during a require, # so emulate that - system_gems %w[rack-1.0.0 rack-0.9.1 rack-obama-1.0] + system_gems %w[myrack-1.0.0 myrack-0.9.1 myrack-obama-1.0] build_lib("foo", path: bundled_app) gemspec = bundled_app("foo.gemspec").read bundled_app("foo.gemspec").open("w") do |f| - f.write "#{gemspec.strip}.tap { gem 'rack-obama'; require 'rack/obama' }" + f.write "#{gemspec.strip}.tap { gem 'myrack-obama'; require 'myrack/obama' }" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G @@ -248,7 +248,7 @@ RSpec.describe "bundle install from an existing gemspec" do end it "allows conflicts" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.version = "1.0.0" s.add_dependency "bar", "= 1.0.0" end @@ -258,16 +258,16 @@ RSpec.describe "bundle install from an existing gemspec" do build_gem "foo", "0.0.1", to_bundle: true install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "deps" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + gemspec :path => '#{tmp("foo")}', :name => 'foo' G expect(the_bundle).to include_gems "foo 1.0.0" end it "does not break Gem.finish_resolve with conflicts" do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.version = "1.0.0" s.add_dependency "bar", "= 1.0.0" end @@ -279,9 +279,9 @@ RSpec.describe "bundle install from an existing gemspec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "deps" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + gemspec :path => '#{tmp("foo")}', :name => 'foo' G expect(the_bundle).to include_gems "foo 1.0.0" @@ -294,7 +294,7 @@ RSpec.describe "bundle install from an existing gemspec" do build_lib "omg", "2.0", path: lib_path("omg") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec :path => "#{lib_path("omg")}" G @@ -313,7 +313,7 @@ RSpec.describe "bundle install from an existing gemspec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G @@ -335,23 +335,23 @@ RSpec.describe "bundle install from an existing gemspec" do before do # build the "parent" gem that depends on another gem in the same repo build_lib "source_conflict", path: bundled_app do |s| - s.add_dependency "rack_middleware" + s.add_dependency "myrack_middleware" end # build the "child" gem that is the same version as a released gem, but # has completely different and conflicting dependency requirements - build_lib "rack_middleware", "1.0", path: bundled_app("rack_middleware") do |s| - s.add_dependency "rack", "1.0" # anything other than 0.9.1 + build_lib "myrack_middleware", "1.0", path: bundled_app("myrack_middleware") do |s| + s.add_dependency "myrack", "1.0" # anything other than 0.9.1 end end it "should install the child gemspec's deps" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end @@ -359,8 +359,8 @@ RSpec.describe "bundle install from an existing gemspec" do let(:source_uri) { "http://localgemserver.test" } before do - build_lib("foo", path: tmp.join("foo")) do |s| - s.add_dependency "rack", "=1.0.0" + build_lib("foo", path: tmp("foo")) do |s| + s.add_dependency "myrack", "=1.0.0" end gemfile <<-G @@ -377,12 +377,12 @@ RSpec.describe "bundle install from an existing gemspec" do remote: ../foo specs: foo (1.0) - rack (= 1.0.0) + myrack (= 1.0.0) GEM remote: #{source_uri} specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{generic_local_platform} @@ -398,9 +398,9 @@ RSpec.describe "bundle install from an existing gemspec" do context "using JRuby with explicit platform", :jruby_only do before do create_file( - tmp.join("foo", "foo-java.gemspec"), + tmp("foo", "foo-java.gemspec"), build_spec("foo", "1.0", "java") do - dep "rack", "=1.0.0" + dep "myrack", "=1.0.0" @spec.authors = "authors" @spec.summary = "summary" end.first.to_ruby @@ -409,15 +409,15 @@ RSpec.describe "bundle install from an existing gemspec" do it "should install" do results = bundle "install", artifice: "endpoint" - expect(results).to include("Installing rack 1.0.0") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(results).to include("Installing myrack 1.0.0") + expect(the_bundle).to include_gems "myrack 1.0.0" end end it "should install", :jruby do results = bundle "install", artifice: "endpoint" - expect(results).to include("Installing rack 1.0.0") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(results).to include("Installing myrack 1.0.0") + expect(the_bundle).to include_gems "myrack 1.0.0" end context "bundled for multiple platforms" do @@ -441,7 +441,7 @@ RSpec.describe "bundle install from an existing gemspec" do end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gemspec G @@ -461,7 +461,7 @@ RSpec.describe "bundle install from an existing gemspec" do context "as a runtime dependency" do it "keeps all platform dependencies in the lockfile" do - expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 ruby" checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" @@ -478,7 +478,7 @@ RSpec.describe "bundle install from an existing gemspec" do platform_specific GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: platform_specific (1.0) platform_specific (1.0-java) @@ -502,7 +502,7 @@ RSpec.describe "bundle install from an existing gemspec" do let(:platform_specific_type) { :development } it "keeps all platform dependencies in the lockfile" do - expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 ruby" checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" @@ -518,7 +518,7 @@ RSpec.describe "bundle install from an existing gemspec" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: platform_specific (1.0) platform_specific (1.0-java) @@ -544,7 +544,7 @@ RSpec.describe "bundle install from an existing gemspec" do let(:dependency) { "indirect_platform_specific" } it "keeps all platform dependencies in the lockfile" do - expect(the_bundle).to include_gems "foo 1.0", "indirect_platform_specific 1.0", "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "foo 1.0", "indirect_platform_specific 1.0", "platform_specific 1.0 ruby" checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" @@ -561,7 +561,7 @@ RSpec.describe "bundle install from an existing gemspec" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: indirect_platform_specific (1.0) platform_specific @@ -589,10 +589,10 @@ RSpec.describe "bundle install from an existing gemspec" do context "with multiple platforms" do before do - build_lib("foo", path: tmp.join("foo")) do |s| + build_lib("foo", path: tmp("foo")) do |s| s.version = "1.0.0" - s.add_development_dependency "rack" - s.write "foo-universal-java.gemspec", build_spec("foo", "1.0.0", "universal-java") {|sj| sj.runtime "rack", "1.0.0" }.first.to_ruby + s.add_development_dependency "myrack" + s.write "foo-universal-java.gemspec", build_spec("foo", "1.0.0", "universal-java") {|sj| sj.runtime "myrack", "1.0.0" }.first.to_ruby end end @@ -600,11 +600,11 @@ RSpec.describe "bundle install from an existing gemspec" do bundle "config set --local force_ruby_platform true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + source "https://gem.repo1" + gemspec :path => '#{tmp("foo")}', :name => 'foo' G - expect(the_bundle).to include_gems "foo 1.0.0", "rack 1.0.0" + expect(the_bundle).to include_gems "foo 1.0.0", "myrack 1.0.0" end it "installs the ruby platform gemspec and skips dev deps with `without development` configured" do @@ -612,18 +612,18 @@ RSpec.describe "bundle install from an existing gemspec" do bundle "config set --local without development" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + source "https://gem.repo1" + gemspec :path => '#{tmp("foo")}', :name => 'foo' G expect(the_bundle).to include_gem "foo 1.0.0" - expect(the_bundle).not_to include_gem "rack" + expect(the_bundle).not_to include_gem "myrack" end end context "with multiple platforms and resolving for more specific platforms" do before do - build_lib("chef", path: tmp.join("chef")) do |s| + build_lib("chef", path: tmp("chef")) do |s| s.version = "17.1.17" s.write "chef-universal-mingw32.gemspec", build_spec("chef", "17.1.17", "universal-mingw32") {|sw| sw.runtime "win32-api", "~> 1.5.3" }.first.to_ruby end @@ -637,7 +637,7 @@ RSpec.describe "bundle install from an existing gemspec" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec :path => "../chef" G @@ -656,7 +656,7 @@ RSpec.describe "bundle install from an existing gemspec" do win32-api (~> 1.5.3) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: win32-api (1.5.3-universal-mingw32) @@ -682,7 +682,7 @@ RSpec.describe "bundle install from an existing gemspec" do context "with multiple locked platforms" do before do - build_lib("activeadmin", path: tmp.join("activeadmin")) do |s| + build_lib("activeadmin", path: tmp("activeadmin")) do |s| s.version = "2.9.0" s.add_dependency "railties", ">= 5.2", "< 6.2" end @@ -696,7 +696,7 @@ RSpec.describe "bundle install from an existing gemspec" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec :path => "../activeadmin" gem "jruby-openssl", :platform => :jruby G @@ -719,7 +719,7 @@ RSpec.describe "bundle install from an existing gemspec" do railties (>= 5.2, < 6.2) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: jruby-openssl (0.10.7-java) railties (6.1.4) @@ -735,7 +735,7 @@ RSpec.describe "bundle install from an existing gemspec" do #{Bundler::VERSION} L - gemspec = tmp.join("activeadmin/activeadmin.gemspec") + gemspec = tmp("activeadmin/activeadmin.gemspec") File.write(gemspec, File.read(gemspec).sub(">= 5.2", ">= 6.0")) previous_lockfile = lockfile diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 24cf30eadb..b1924876a7 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -8,7 +8,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem 'foo' end @@ -31,7 +31,7 @@ RSpec.describe "bundle install with git sources" do end it "does not write to cache on bundler/setup" do - cache_path = default_bundle_path.join("cache") + cache_path = default_bundle_path("cache") FileUtils.rm_rf(cache_path) ruby "require 'bundler/setup'" expect(cache_path).not_to exist @@ -59,7 +59,7 @@ RSpec.describe "bundle install with git sources" do bundle "update foo" sha = git.ref_for("main", 11) - spec_file = default_bundle_path.join("bundler/gems/foo-1.0-#{sha}/foo.gemspec") + spec_file = default_bundle_path("bundler/gems/foo-1.0-#{sha}/foo.gemspec") expect(spec_file).to exist ruby_code = Gem::Specification.load(spec_file.to_s).to_ruby file_code = File.read(spec_file) @@ -70,7 +70,7 @@ RSpec.describe "bundle install with git sources" do update_git "foo" install_gemfile bundled_app2("Gemfile"), <<-G, dir: bundled_app2 - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem 'foo' end @@ -93,7 +93,7 @@ RSpec.describe "bundle install with git sources" do build_git "foo" install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.1", :git => "#{lib_path("foo-1.0")}" G @@ -106,7 +106,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platforms :jruby do gem "only_java", "1.2", :git => "#{lib_path("only_java-1.0-java")}" end @@ -126,7 +126,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platforms :jruby do gem "only_java", "1.2", :git => "#{lib_path("only_java-1.1-java")}" end @@ -153,17 +153,17 @@ RSpec.describe "bundle install with git sources" do update_git "foo", "1.1", path: lib_path("foo-1.0") gemfile tmp("bundled_app.bck/Gemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem 'foo' end - gem "rack", "1.0" + gem "myrack", "1.0" G bundle "update foo", dir: tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.1", "rack 1.0", dir: tmp("bundled_app.bck") + expect(the_bundle).to include_gems "foo 1.1", "myrack 1.0", dir: tmp("bundled_app.bck") end end @@ -171,8 +171,8 @@ RSpec.describe "bundle install with git sources" do before do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" git "#{lib_path("foo-1.0")}" do # this page left intentionally blank @@ -182,7 +182,7 @@ RSpec.describe "bundle install with git sources" do it "does not explode" do bundle "install" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end @@ -195,7 +195,7 @@ RSpec.describe "bundle install with git sources" do it "works" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :ref => "#{@revision}" do gem "foo" end @@ -212,7 +212,7 @@ RSpec.describe "bundle install with git sources" do it "works when the revision is a symbol" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :ref => #{@revision.to_sym.inspect} do gem "foo" end @@ -229,14 +229,14 @@ RSpec.describe "bundle install with git sources" do it "works when an abbreviated revision is added after an initial, potentially shallow clone" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem "foo" end G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :ref => #{@revision[0..7].inspect} do gem "foo" end @@ -246,11 +246,11 @@ RSpec.describe "bundle install with git sources" do it "works when a tag that does not look like a commit hash is used as the value of :ref" do build_git "foo" @remote = build_git("bar", bare: true) - update_git "foo", remote: file_uri_for(@remote.path) + update_git "foo", remote: @remote.path update_git "foo", push: "main" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{@remote.path}" G @@ -259,7 +259,7 @@ RSpec.describe "bundle install with git sources" do update_git "foo", push: "v1.0.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{@remote.path}", :ref => "v1.0.0" G @@ -272,7 +272,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", dir: lib_path("foo-1.0")) + git("update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", path: lib_path("foo-1.0"), branch: "rando" do |s| @@ -280,7 +280,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :ref => "refs/bundler/1" do gem "foo" end @@ -297,7 +297,7 @@ RSpec.describe "bundle install with git sources" do it "works when the revision is a non-head ref and it was previously downloaded" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem "foo" end @@ -308,7 +308,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", dir: lib_path("foo-1.0")) + git("update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", path: lib_path("foo-1.0"), branch: "rando" do |s| @@ -316,7 +316,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :ref => "refs/bundler/1" do gem "foo" end @@ -332,12 +332,12 @@ RSpec.describe "bundle install with git sources" do end it "does not download random non-head refs" do - sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", dir: lib_path("foo-1.0")) + git("update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", lib_path("foo-1.0")) bundle "config set global_gem_cache true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem "foo" end @@ -346,7 +346,7 @@ RSpec.describe "bundle install with git sources" do # ensure we also git fetch after cloning bundle :update, all: true - sys_exec("git ls-remote .", dir: Dir[home(".bundle/cache/git/foo-*")].first) + git("ls-remote .", Dir[home(".bundle/cache/git/foo-*")].first) expect(out).not_to include("refs/bundler/1") end @@ -360,7 +360,7 @@ RSpec.describe "bundle install with git sources" do update_git("foo", path: repo, branch: branch) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{repo}", :branch => #{branch.dump} do gem "foo" end @@ -377,7 +377,7 @@ RSpec.describe "bundle install with git sources" do update_git("foo", path: repo, branch: branch) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{repo}", :branch => #{branch.dump} do gem "foo" end @@ -395,7 +395,7 @@ RSpec.describe "bundle install with git sources" do update_git("foo", path: repo, branch: branch) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{repo}", :branch => #{branch.dump} do gem "foo" end @@ -414,7 +414,7 @@ RSpec.describe "bundle install with git sources" do update_git("foo", path: repo, tag: tag) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{repo}", :tag => #{tag.dump} do gem "foo" end @@ -431,7 +431,7 @@ RSpec.describe "bundle install with git sources" do update_git("foo", path: repo, tag: tag) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{repo}", :tag => #{tag.dump} do gem "foo" end @@ -449,7 +449,7 @@ RSpec.describe "bundle install with git sources" do update_git("foo", path: repo, tag: tag) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{repo}", :tag => #{tag.dump} do gem "foo" end @@ -462,100 +462,100 @@ RSpec.describe "bundle install with git sources" do describe "when specifying local override" do it "uses the local repository instead of checking a new one out" do - build_git "rack", "0.8", path: lib_path("local-rack") do |s| - s.write "lib/rack.rb", "puts :LOCAL" + build_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install - run "require 'rack'" + run "require 'myrack'" expect(out).to eq("LOCAL") end it "chooses the local repository on runtime" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) - update_git "rack", "0.8", path: lib_path("local-rack") do |s| - s.write "lib/rack.rb", "puts :LOCAL" + update_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) - run "require 'rack'" + bundle %(config set local.myrack #{lib_path("local-myrack")}) + run "require 'myrack'" expect(out).to eq("LOCAL") end it "unlocks the source when the dependencies have changed while switching to the local" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) - update_git "rack", "0.8", path: lib_path("local-rack") do |s| - s.write "rack.gemspec", build_spec("rack", "0.8") { runtime "rspec", "> 0" }.first.to_ruby - s.write "lib/rack.rb", "puts :LOCAL" + update_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "myrack.gemspec", build_spec("myrack", "0.8") { runtime "rspec", "> 0" }.first.to_ruby + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install - run "require 'rack'" + run "require 'myrack'" expect(out).to eq("LOCAL") end it "updates specs on runtime" do system_gems "nokogiri-1.4.2" - build_git "rack", "0.8" + build_git "myrack", "0.8" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G lockfile0 = File.read(bundled_app_lock) - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) - update_git "rack", "0.8", path: lib_path("local-rack") do |s| + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) + update_git "myrack", "0.8", path: lib_path("local-myrack") do |s| s.add_dependency "nokogiri", "1.4.2" end - bundle %(config set local.rack #{lib_path("local-rack")}) - run "require 'rack'" + bundle %(config set local.myrack #{lib_path("local-myrack")}) + run "require 'myrack'" lockfile1 = File.read(bundled_app_lock) expect(lockfile1).not_to eq(lockfile0) end it "updates ref on install" do - build_git "rack", "0.8" + build_git "myrack", "0.8" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G lockfile0 = File.read(bundled_app_lock) - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) - update_git "rack", "0.8", path: lib_path("local-rack") + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) + update_git "myrack", "0.8", path: lib_path("local-myrack") - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install lockfile1 = File.read(bundled_app_lock) @@ -563,18 +563,18 @@ RSpec.describe "bundle install with git sources" do end it "explodes and gives correct solution if given path does not exist on install" do - build_git "rack", "0.8" + build_git "myrack", "0.8" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install, raise_on_error: false - expect(err).to match(/Cannot use local override for rack-0.8 because #{Regexp.escape(lib_path("local-rack").to_s)} does not exist/) + expect(err).to match(/Cannot use local override for myrack-0.8 because #{Regexp.escape(lib_path("local-myrack").to_s)} does not exist/) - solution = "config unset local.rack" + solution = "config unset local.myrack" expect(err).to match(/Run `bundle #{solution}` to remove the local override/) bundle solution @@ -584,19 +584,19 @@ RSpec.describe "bundle install with git sources" do end it "explodes and gives correct solution if branch is not given on install" do - build_git "rack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + build_git "myrack", "0.8" + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install, raise_on_error: false - expect(err).to match(/Cannot use local override for rack-0.8 at #{Regexp.escape(lib_path("local-rack").to_s)} because :branch is not specified in Gemfile/) + expect(err).to match(/Cannot use local override for myrack-0.8 at #{Regexp.escape(lib_path("local-myrack").to_s)} because :branch is not specified in Gemfile/) - solution = "config unset local.rack" + solution = "config unset local.myrack" expect(err).to match(/Specify a branch or run `bundle #{solution}` to remove the local override/) bundle solution @@ -606,69 +606,69 @@ RSpec.describe "bundle install with git sources" do end it "does not explode if disable_local_branch_check is given" do - build_git "rack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + build_git "myrack", "0.8" + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle %(config set disable_local_branch_check true) bundle :install expect(out).to match(/Bundle complete!/) end it "explodes on different branches on install" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) - update_git "rack", "0.8", path: lib_path("local-rack"), branch: "another" do |s| - s.write "lib/rack.rb", "puts :LOCAL" + update_git "myrack", "0.8", path: lib_path("local-myrack"), branch: "another" do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install, raise_on_error: false expect(err).to match(/is using branch another but Gemfile specifies main/) end it "explodes on invalid revision on install" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - build_git "rack", "0.8", path: lib_path("local-rack") do |s| - s.write "lib/rack.rb", "puts :LOCAL" + build_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install, raise_on_error: false expect(err).to match(/The Gemfile lock is pointing to revision \w+/) end it "does not explode on invalid revision on install" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - build_git "rack", "0.8", path: lib_path("local-rack") do |s| - s.write "lib/rack.rb", "puts :LOCAL" + build_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle %(config set disable_local_revision_check true) bundle :install expect(out).to match(/Bundle complete!/) @@ -693,66 +693,66 @@ RSpec.describe "bundle install with git sources" do # end it "installs from git even if a newer gem is available elsewhere" do - build_git "rack", "0.8" + build_git "myrack", "0.8" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}" G - expect(the_bundle).to include_gems "rack 0.8" + expect(the_bundle).to include_gems "myrack 0.8" end it "installs dependencies from git even if a newer gem is available elsewhere" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" - build_lib "rack", "1.0", path: lib_path("nested/bar") do |s| - s.write "lib/rack.rb", "puts 'WIN OVERRIDE'" + build_lib "myrack", "1.0", path: lib_path("nested/bar") do |s| + s.write "lib/myrack.rb", "puts 'WIN OVERRIDE'" end build_git "foo", path: lib_path("nested") do |s| - s.add_dependency "rack", "= 1.0" + s.add_dependency "myrack", "= 1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("nested")}" G - run "require 'rack'" + run "require 'myrack'" expect(out).to eq("WIN OVERRIDE") end it "correctly unlocks when changing to a git source" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G - build_git "rack", path: lib_path("rack") + build_git "myrack", path: lib_path("myrack") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0", :git => "#{lib_path("rack")}" + source "https://gem.repo1" + gem "myrack", "1.0.0", :git => "#{lib_path("myrack")}" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "correctly unlocks when changing to a git source without versions" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - build_git "rack", "1.2", path: lib_path("rack") + build_git "myrack", "1.2", path: lib_path("myrack") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack")}" G - expect(the_bundle).to include_gems "rack 1.2" + expect(the_bundle).to include_gems "myrack 1.2" end end @@ -762,7 +762,7 @@ RSpec.describe "bundle install with git sources" do build_lib "hi2u", path: lib_path("hi2u") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path("hi2u")}" do gem "omg" gem "hi2u" @@ -779,7 +779,7 @@ RSpec.describe "bundle install with git sources" do update_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{@revision}" G @@ -797,7 +797,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" gem "rails", "2.3.2" G @@ -827,7 +827,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :git => "#{lib_path("foo")}" gem "rails", "2.3.2" G @@ -844,7 +844,7 @@ RSpec.describe "bundle install with git sources" do build_git "foo", "1.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.0", :git => "#{lib_path("foo-1.0")}" G @@ -855,7 +855,7 @@ RSpec.describe "bundle install with git sources" do build_git "foo", gemspec: false install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.0", :git => "#{lib_path("foo-1.0")}" gem "rails", "2.3.2" G @@ -866,7 +866,7 @@ RSpec.describe "bundle install with git sources" do it "catches git errors and spits out useful output" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.0", :git => "omgomg" G @@ -881,7 +881,7 @@ RSpec.describe "bundle install with git sources" do build_git "foo", path: lib_path("foo space-1.0") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo space-1.0")}" G @@ -892,7 +892,7 @@ RSpec.describe "bundle install with git sources" do build_git "forced", "1.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("forced-1.0")}" do gem 'forced' end @@ -906,7 +906,7 @@ RSpec.describe "bundle install with git sources" do bundle "update", all: true expect(the_bundle).to include_gems "forced 1.1" - sys_exec("git reset --hard HEAD^", dir: lib_path("forced-1.0")) + git("reset --hard HEAD^", lib_path("forced-1.0")) bundle "update", all: true expect(the_bundle).to include_gems "forced 1.0" @@ -920,16 +920,16 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", dir: lib_path("has_submodule-1.0") - sys_exec "git commit -m \"submodulator\"", dir: lib_path("has_submodule-1.0") + git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0") + git "commit -m \"submodulator\"", lib_path("has_submodule-1.0") install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("has_submodule-1.0")}" do gem "has_submodule" end G - expect(err).to match(%r{submodule >= 0 could not be found in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally}) + expect(err).to match(%r{submodule >= 0 could not be found in rubygems repository https://gem.repo1/ or installed locally}) expect(the_bundle).not_to include_gems "has_submodule 1.0" end @@ -942,11 +942,11 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", dir: lib_path("has_submodule-1.0") - sys_exec "git commit -m \"submodulator\"", dir: lib_path("has_submodule-1.0") + git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0") + git "commit -m \"submodulator\"", lib_path("has_submodule-1.0") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("has_submodule-1.0")}", :submodules => true do gem "has_submodule" end @@ -962,11 +962,11 @@ RSpec.describe "bundle install with git sources" do build_git "submodule", "1.0" build_git "has_submodule", "1.0" - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", dir: lib_path("has_submodule-1.0") - sys_exec "git commit -m \"submodulator\"", dir: lib_path("has_submodule-1.0") + git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0") + git "commit -m \"submodulator\"", lib_path("has_submodule-1.0") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("has_submodule-1.0")}" do gem "has_submodule" end @@ -981,7 +981,7 @@ RSpec.describe "bundle install with git sources" do git = build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem "foo" end @@ -991,7 +991,7 @@ RSpec.describe "bundle install with git sources" do update_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :ref => "#{git.ref_for("HEAD^")}" do gem "foo" end @@ -1009,7 +1009,7 @@ RSpec.describe "bundle install with git sources" do build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1023,7 +1023,7 @@ RSpec.describe "bundle install with git sources" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1038,7 +1038,7 @@ RSpec.describe "bundle install with git sources" do FileUtils.touch(default_bundle_path("bundler")) install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1056,7 +1056,7 @@ RSpec.describe "bundle install with git sources" do build_git "bar", path: lib_path("nested") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("nested")}" gem "bar", :git => "#{lib_path("nested")}" G @@ -1075,12 +1075,12 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :path => "#{lib_path("bar")}" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :git => "#{lib_path("bar")}" G @@ -1089,19 +1089,19 @@ RSpec.describe "bundle install with git sources" do it "doesn't explode when switching Gem to Git source" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack-obama" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack-obama" + gem "myrack", "1.0.0" G - build_git "rack", "1.0" do |s| + build_git "myrack", "1.0" do |s| s.write "lib/new_file.rb", "puts 'USING GIT'" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack-obama" - gem "rack", "1.0.0", :git => "#{lib_path("rack-1.0")}" + source "https://gem.repo1" + gem "myrack-obama" + gem "myrack", "1.0.0", :git => "#{lib_path("myrack-1.0")}" G run "require 'new_file'" @@ -1114,8 +1114,8 @@ RSpec.describe "bundle install with git sources" do build_git "valim" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "valim", :git => "#{file_uri_for(lib_path("valim-1.0"))}" + source "https://gem.repo1" + gem "valim", :git => "#{lib_path("valim-1.0")}" G old_revision = revision_for(lib_path("valim-1.0")) @@ -1140,14 +1140,14 @@ RSpec.describe "bundle install with git sources" do revision = revision_for(lib_path("foo-1.0")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :ref => "#{revision}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{revision}" G expect(out).to_not match(/Revision.*does not exist/) install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :ref => "deadbeef" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "deadbeef" G expect(err).to include("Revision deadbeef does not exist in the repository") end @@ -1156,8 +1156,8 @@ RSpec.describe "bundle install with git sources" do build_git "foo" install_gemfile <<-G, env: { "LANG" => "en" }, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :branch => "deadbeef" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "deadbeef" G expect(err).to include("Revision deadbeef does not exist in the repository") @@ -1169,7 +1169,7 @@ RSpec.describe "bundle install with git sources" do build_git "valim", path: lib_path("valim") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "valim", "= 1.0", :git => "#{lib_path("valim")}" G @@ -1184,7 +1184,7 @@ RSpec.describe "bundle install with git sources" do it "runs pre-install hooks" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1204,7 +1204,7 @@ RSpec.describe "bundle install with git sources" do it "runs post-install hooks" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1224,7 +1224,7 @@ RSpec.describe "bundle install with git sources" do it "complains if the install hook fails" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1258,7 +1258,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1292,12 +1292,12 @@ RSpec.describe "bundle install with git sources" do void Init_foo() { rb_define_global_function("foo", &foo, 0); } C end - sys_exec("git commit -m \"commit for iteration #{i}\" ext/foo.c", dir: git_reader.path) + git("commit -m \"commit for iteration #{i}\" ext/foo.c", git_reader.path) git_commit_sha = git_reader.ref_for("HEAD") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{git_commit_sha}" G @@ -1322,7 +1322,7 @@ RSpec.describe "bundle install with git sources" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1352,7 +1352,7 @@ In Gemfile: end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1365,7 +1365,7 @@ In Gemfile: expect(installed_time).to match(/\A\d+\.\d+\z/) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1393,8 +1393,8 @@ In Gemfile: end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1407,8 +1407,8 @@ In Gemfile: expect(installed_time).to match(/\A\d+\.\d+\z/) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1436,7 +1436,7 @@ In Gemfile: end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1452,7 +1452,7 @@ In Gemfile: expect(installed_time).to match(/\A\d+\.\d+\z/) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "branch2" G @@ -1485,7 +1485,7 @@ In Gemfile: ENV["GIT_WORK_TREE"] = "bar" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("xxxxxx-1.0")}" do gem 'xxxxxx' end @@ -1499,7 +1499,7 @@ In Gemfile: describe "without git installed" do it "prints a better error message when installing" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake", git: "https://github.com/ruby/rake" G @@ -1536,7 +1536,7 @@ In Gemfile: build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem 'foo' end @@ -1553,7 +1553,7 @@ In Gemfile: build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem 'foo' end @@ -1583,7 +1583,7 @@ In Gemfile: build_git "foo", "1.0", path: lib_path("foo") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo")}", :branch => "main" G @@ -1599,7 +1599,7 @@ In Gemfile: it "does not display the password" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "https://#{credentials}@github.com/company/private-repo" do gem "foo" end @@ -1615,7 +1615,7 @@ In Gemfile: it "displays the oauth scheme but not the oauth token" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "https://#{credentials}:[email protected]/company/private-repo" do gem "foo" end diff --git a/spec/bundler/install/gemfile/groups_spec.rb b/spec/bundler/install/gemfile/groups_spec.rb index f7907a9cad..71871899a2 100644 --- a/spec/bundler/install/gemfile/groups_spec.rb +++ b/spec/bundler/install/gemfile/groups_spec.rb @@ -4,8 +4,8 @@ RSpec.describe "bundle install with groups" do describe "installing with no options" do before :each do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" group :emo do gem "activesupport", "2.3.5" end @@ -14,7 +14,7 @@ RSpec.describe "bundle install with groups" do end it "installs gems in the default group" do - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs gems in a group block into that group" do @@ -40,7 +40,7 @@ RSpec.describe "bundle install with groups" do end it "sets up everything if Bundler.setup is used with no groups" do - output = run("require 'rack'; puts RACK") + output = run("require 'myrack'; puts MYRACK") expect(output).to eq("1.0.0") output = run("require 'activesupport'; puts ACTIVESUPPORT") @@ -74,8 +74,8 @@ RSpec.describe "bundle install with groups" do describe "with gems assigned to a single group" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" group :emo do gem "activesupport", "2.3.5" end @@ -88,13 +88,13 @@ RSpec.describe "bundle install with groups" do it "installs gems in the default group" do bundle "config set --local without emo" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0", groups: [:default] + expect(the_bundle).to include_gems "myrack 1.0.0", groups: [:default] end it "respects global `without` configuration, but does not save it locally" do bundle "config set --global without emo" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0", groups: [:default] + expect(the_bundle).to include_gems "myrack 1.0.0", groups: [:default] bundle "config list" expect(out).not_to include("Set for your local app (#{bundled_app(".bundle/config")}): [:emo]") expect(out).to include("Set for the current user (#{home(".bundle/config")}): [:emo]") @@ -129,13 +129,13 @@ RSpec.describe "bundle install with groups" do it "allows Bundler.setup for specific groups" do bundle "config set --local without emo" bundle :install - run("require 'rack'; puts RACK", :default) + run("require 'myrack'; puts MYRACK", :default) expect(out).to eq("1.0.0") end it "does not effect the resolve" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" group :emo do gem "rails", "2.3.2" @@ -153,7 +153,7 @@ RSpec.describe "bundle install with groups" do bundle :install expect(out).not_to include("activesupport") - expect(the_bundle).to include_gems "rack 1.0.0", groups: [:default] + expect(the_bundle).to include_gems "myrack 1.0.0", groups: [:default] expect(the_bundle).not_to include_gems "activesupport 2.3.5", groups: [:default] ENV["BUNDLE_WITHOUT"] = nil @@ -257,8 +257,8 @@ RSpec.describe "bundle install with groups" do describe "with gems assigned to multiple groups" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" group :emo, :lolercoaster do gem "activesupport", "2.3.5" end @@ -268,20 +268,20 @@ RSpec.describe "bundle install with groups" do it "installs gems in the default group" do bundle "config set --local without emo lolercoaster" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs the gem if any of its groups are installed" do bundle "config set --local without emo" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.5" + expect(the_bundle).to include_gems "myrack 1.0.0", "activesupport 2.3.5" end describe "with a gem defined multiple times in different groups" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" group :emo do gem "activesupport", "2.3.5" @@ -316,8 +316,8 @@ RSpec.describe "bundle install with groups" do describe "nesting groups" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" group :emo do group :lolercoaster do gem "activesupport", "2.3.5" @@ -329,13 +329,13 @@ RSpec.describe "bundle install with groups" do it "installs gems in the default group" do bundle "config set --local without emo lolercoaster" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs the gem if any of its groups are installed" do bundle "config set --local without emo" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.5" + expect(the_bundle).to include_gems "myrack 1.0.0", "activesupport 2.3.5" end end end @@ -343,8 +343,8 @@ RSpec.describe "bundle install with groups" do describe "when loading only the default group" do it "should not load all groups" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :groups => :development G @@ -352,7 +352,7 @@ RSpec.describe "bundle install with groups" do require "bundler" Bundler.setup :default Bundler.require :default - puts RACK + puts MYRACK begin require "activesupport" rescue LoadError @@ -369,33 +369,33 @@ RSpec.describe "bundle install with groups" do before(:each) do build_repo2 - system_gems "rack-0.9.1" + system_gems "myrack-0.9.1" - bundle "config set --local without rack" + bundle "config set --local without myrack" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" - group :rack do - gem "rack_middleware" + group :myrack do + gem "myrack_middleware" end G end it "uses the correct versions even if --without was used on the original" do - expect(the_bundle).to include_gems "rack 0.9.1" - expect(the_bundle).not_to include_gems "rack_middleware 1.0" + expect(the_bundle).to include_gems "myrack 0.9.1" + expect(the_bundle).not_to include_gems "myrack_middleware 1.0" simulate_new_machine bundle :install - expect(the_bundle).to include_gems "rack 0.9.1" - expect(the_bundle).to include_gems "rack_middleware 1.0" + expect(the_bundle).to include_gems "myrack 0.9.1" + expect(the_bundle).to include_gems "myrack_middleware 1.0" end it "does not hit the remote a second time" do FileUtils.rm_rf gem_repo2 - bundle "config set --local without rack" + bundle "config set --local without myrack" bundle :install, verbose: true expect(last_command.stdboth).not_to match(/fetching/i) end diff --git a/spec/bundler/install/gemfile/install_if_spec.rb b/spec/bundler/install/gemfile/install_if_spec.rb index c7640d07e1..689c5ab501 100644 --- a/spec/bundler/install/gemfile/install_if_spec.rb +++ b/spec/bundler/install/gemfile/install_if_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "bundle install with install_if conditionals" do it "follows the install_if DSL" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" install_if(lambda { true }) do gem "activesupport", "2.3.5" end @@ -11,29 +11,29 @@ RSpec.describe "bundle install with install_if conditionals" do install_if(lambda { false }) do gem "foo" end - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems("rack 1.0", "activesupport 2.3.5") + expect(the_bundle).to include_gems("myrack 1.0", "activesupport 2.3.5") expect(the_bundle).not_to include_gems("thin") expect(the_bundle).not_to include_gems("foo") checksums = checksums_section_when_existing do |c| c.checksum gem_repo1, "activesupport", "2.3.5" c.no_checksum "foo", "1.0" - c.checksum gem_repo1, "rack", "1.0.0" + c.checksum gem_repo1, "myrack", "1.0.0" c.no_checksum "thin", "1.0" end expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: activesupport (2.3.5) foo (1.0) - rack (1.0.0) + myrack (1.0.0) thin (1.0) - rack + myrack PLATFORMS #{lockfile_platforms} @@ -41,7 +41,7 @@ RSpec.describe "bundle install with install_if conditionals" do DEPENDENCIES activesupport (= 2.3.5) foo - rack + myrack thin #{checksums} BUNDLED WITH diff --git a/spec/bundler/install/gemfile/lockfile_spec.rb b/spec/bundler/install/gemfile/lockfile_spec.rb index 4601d3e2a8..f80b21e562 100644 --- a/spec/bundler/install/gemfile/lockfile_spec.rb +++ b/spec/bundler/install/gemfile/lockfile_spec.rb @@ -2,9 +2,9 @@ RSpec.describe "bundle install with a lockfile present" do let(:gf) { <<-G } - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G subject do @@ -28,7 +28,7 @@ RSpec.describe "bundle install with a lockfile present" do it "does not evaluate the gemfile twice" do bundle :install - with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "rack 1.0.0" } + with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" } # The first eval is from the initial install, we're testing that the # second install doesn't double-eval @@ -41,7 +41,7 @@ RSpec.describe "bundle install with a lockfile present" do it "does not evaluate the gemfile twice" do bundle :install - with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "rack 1.0.0" } + with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" } # The first eval is from the initial install, we're testing that the # second install doesn't double-eval diff --git a/spec/bundler/install/gemfile/path_spec.rb b/spec/bundler/install/gemfile/path_spec.rb index a57b7ee560..ca712e24c8 100644 --- a/spec/bundler/install/gemfile/path_spec.rb +++ b/spec/bundler/install/gemfile/path_spec.rb @@ -16,7 +16,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path("foo-1.0")}" do gem 'foo' end @@ -29,7 +29,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "#{lib_path("foo-1.0")}" G @@ -42,7 +42,7 @@ RSpec.describe "bundle install with explicit source paths" do relative_path = lib_path("foo-1.0").relative_path_from(bundled_app) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "#{relative_path}" G @@ -55,7 +55,7 @@ RSpec.describe "bundle install with explicit source paths" do relative_path = lib_path("foo-1.0").relative_path_from(Pathname.new("~").expand_path) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "~/#{relative_path}" G @@ -70,7 +70,7 @@ RSpec.describe "bundle install with explicit source paths" do relative_path = lib_path("foo-1.0").relative_path_from(Pathname.new("/home/#{username}").expand_path) install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "~#{username}/#{relative_path}" G expect(err).to match("There was an error while trying to use the path `~#{username}/#{relative_path}`.") @@ -81,7 +81,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", path: bundled_app("foo-1.0") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "./foo-1.0" G @@ -93,7 +93,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "aaa", path: lib_path("demo/aaa") gemfile lib_path("demo/Gemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec gem "aaa", :path => "./aaa" G @@ -115,7 +115,7 @@ RSpec.describe "bundle install with explicit source paths" do aaa (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -139,7 +139,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", path: bundled_app("foo-1.0") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => File.expand_path("foo-1.0", __dir__) G @@ -148,22 +148,22 @@ RSpec.describe "bundle install with explicit source paths" do end it "installs dependencies from the path even if a newer gem is available elsewhere" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" - build_lib "rack", "1.0", path: lib_path("nested/bar") do |s| - s.write "lib/rack.rb", "puts 'WIN OVERRIDE'" + build_lib "myrack", "1.0", path: lib_path("nested/bar") do |s| + s.write "lib/myrack.rb", "puts 'WIN OVERRIDE'" end build_lib "foo", path: lib_path("nested") do |s| - s.add_dependency "rack", "= 1.0" + s.add_dependency "myrack", "= 1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("nested")}" G - run "require 'rack'" + run "require 'myrack'" expect(out).to eq("WIN OVERRIDE") end @@ -179,7 +179,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", "1.0.0", path: lib_path("omg/foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "omg", :path => "#{lib_path("omg")}" G @@ -190,7 +190,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", "0.0.0.dev", path: lib_path("foo") gemfile <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G @@ -201,7 +201,7 @@ RSpec.describe "bundle install with explicit source paths" do foo (0.0.0.dev) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -223,7 +223,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", "0.0.0.SNAPSHOT", path: lib_path("foo") gemfile <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G @@ -234,7 +234,7 @@ RSpec.describe "bundle install with explicit source paths" do foo (0.0.0.SNAPSHOT) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -256,7 +256,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "omg", "2.0", path: lib_path("omg") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "omg", :path => "#{lib_path("omg")}" G @@ -280,7 +280,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "premailer", :path => "#{lib_path("premailer")}" G @@ -302,7 +302,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" G @@ -314,17 +314,17 @@ RSpec.describe "bundle install with explicit source paths" do it "supports gemspec syntax" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "1.0" + s.add_dependency "myrack", "1.0" end gemfile lib_path("foo/Gemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G bundle "install", dir: lib_path("foo") expect(the_bundle).to include_gems "foo 1.0", dir: lib_path("foo") - expect(the_bundle).to include_gems "rack 1.0", dir: lib_path("foo") + expect(the_bundle).to include_gems "myrack 1.0", dir: lib_path("foo") end it "does not unlock dependencies of path sources" do @@ -340,7 +340,7 @@ RSpec.describe "bundle install with explicit source paths" do gemfile_path = lib_path("foo/Gemfile") gemfile gemfile_path, <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec G @@ -359,7 +359,7 @@ RSpec.describe "bundle install with explicit source paths" do graphql (~> 2.0) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: graphql (2.0.15) @@ -385,53 +385,53 @@ RSpec.describe "bundle install with explicit source paths" do it "supports gemspec syntax with an alternative path" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "1.0" + s.add_dependency "myrack", "1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec :path => "#{lib_path("foo")}" G expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end it "doesn't automatically unlock dependencies when using the gemspec syntax" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", ">= 1.0" + s.add_dependency "myrack", ">= 1.0" end install_gemfile lib_path("foo/Gemfile"), <<-G, dir: lib_path("foo") - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G - build_gem "rack", "1.0.1", to_system: true + build_gem "myrack", "1.0.1", to_system: true bundle "install", dir: lib_path("foo") expect(the_bundle).to include_gems "foo 1.0", dir: lib_path("foo") - expect(the_bundle).to include_gems "rack 1.0", dir: lib_path("foo") + expect(the_bundle).to include_gems "myrack 1.0", dir: lib_path("foo") end it "doesn't automatically unlock dependencies when using the gemspec syntax and the gem has development dependencies" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", ">= 1.0" + s.add_dependency "myrack", ">= 1.0" s.add_development_dependency "activesupport" end install_gemfile lib_path("foo/Gemfile"), <<-G, dir: lib_path("foo") - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G - build_gem "rack", "1.0.1", to_system: true + build_gem "myrack", "1.0.1", to_system: true bundle "install", dir: lib_path("foo") expect(the_bundle).to include_gems "foo 1.0", dir: lib_path("foo") - expect(the_bundle).to include_gems "rack 1.0", dir: lib_path("foo") + expect(the_bundle).to include_gems "myrack 1.0", dir: lib_path("foo") end it "raises if there are multiple gemspecs" do @@ -440,7 +440,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec :path => "#{lib_path("foo")}" G @@ -454,7 +454,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec :path => "#{lib_path("foo")}", :name => "foo" G @@ -467,7 +467,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path("foo-1.0")}" do gem 'foo' end @@ -485,7 +485,7 @@ RSpec.describe "bundle install with explicit source paths" do lib_path("foo-1.0").join("bin/performance").mkpath install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', '1.0', :path => "#{lib_path("foo-1.0")}" G expect(err).to be_empty @@ -495,7 +495,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :path => "#{lib_path("foo-1.0")}" G @@ -508,7 +508,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "hi2u" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "omg" gem "hi2u" @@ -527,7 +527,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" gem "omg", :path => "#{lib_path("omg")}" G @@ -539,7 +539,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", gemspec: false gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", "1.0", :path => "#{lib_path("foo-1.0")}" G @@ -569,18 +569,18 @@ RSpec.describe "bundle install with explicit source paths" do context "existing lockfile" do it "rubygems gems don't re-resolve without changes" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack-obama', '1.0' + source "https://gem.repo1" + gem 'myrack-obama', '1.0' gem 'net-ssh', '1.0' G bundle :check, env: { "DEBUG" => "1" } expect(out).to match(/using resolution from the lockfile/) - expect(the_bundle).to include_gems "rack-obama 1.0", "net-ssh 1.0" + expect(the_bundle).to include_gems "myrack-obama 1.0", "net-ssh 1.0" end it "source path gems w/deps don't re-resolve without changes" do - build_lib "rack-obama", "1.0", path: lib_path("omg") do |s| + build_lib "myrack-obama", "1.0", path: lib_path("omg") do |s| s.add_dependency "yard" end @@ -589,14 +589,14 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack-obama', :path => "#{lib_path("omg")}" + source "https://gem.repo1" + gem 'myrack-obama', :path => "#{lib_path("omg")}" gem 'net-ssh', :path => "#{lib_path("omg")}" G bundle :check, env: { "DEBUG" => "1" } expect(out).to match(/using resolution from the lockfile/) - expect(the_bundle).to include_gems "rack-obama 1.0", "net-ssh 1.0" + expect(the_bundle).to include_gems "myrack-obama 1.0", "net-ssh 1.0" end end @@ -606,7 +606,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" G @@ -622,7 +622,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "bar", "1.0", path: lib_path("foo/bar") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G end @@ -651,33 +651,33 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "foo", "1.0", path: lib_path("foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo")}" G end it "gets dependencies that are updated in the path" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack" + s.add_dependency "myrack" end bundle "install" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "keeps using the same version if it's compatible" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "0.9.1" + s.add_dependency "myrack", "0.9.1" end bundle "install" - expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).to include_gems "myrack 0.9.1" checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" - c.checksum gem_repo1, "rack", "0.9.1" + c.checksum gem_repo1, "myrack", "0.9.1" end expect(lockfile).to eq <<~G @@ -685,12 +685,12 @@ RSpec.describe "bundle install with explicit source paths" do remote: #{lib_path("foo")} specs: foo (1.0) - rack (= 0.9.1) + myrack (= 0.9.1) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} @@ -703,7 +703,7 @@ RSpec.describe "bundle install with explicit source paths" do G build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack" + s.add_dependency "myrack" end bundle "install" @@ -713,12 +713,12 @@ RSpec.describe "bundle install with explicit source paths" do remote: #{lib_path("foo")} specs: foo (1.0) - rack + myrack GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} @@ -730,21 +730,21 @@ RSpec.describe "bundle install with explicit source paths" do #{Bundler::VERSION} G - expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).to include_gems "myrack 0.9.1" end it "keeps using the same version even when another dependency is added" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "0.9.1" + s.add_dependency "myrack", "0.9.1" end bundle "install" - expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).to include_gems "myrack 0.9.1" checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" - c.checksum gem_repo1, "rack", "0.9.1" + c.checksum gem_repo1, "myrack", "0.9.1" end expect(lockfile).to eq <<~G @@ -752,12 +752,12 @@ RSpec.describe "bundle install with explicit source paths" do remote: #{lib_path("foo")} specs: foo (1.0) - rack (= 0.9.1) + myrack (= 0.9.1) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} @@ -770,7 +770,7 @@ RSpec.describe "bundle install with explicit source paths" do G build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack" + s.add_dependency "myrack" s.add_dependency "rake", rake_version end @@ -783,13 +783,13 @@ RSpec.describe "bundle install with explicit source paths" do remote: #{lib_path("foo")} specs: foo (1.0) - rack + myrack rake (= #{rake_version}) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) + myrack (0.9.1) rake (#{rake_version}) PLATFORMS @@ -802,12 +802,12 @@ RSpec.describe "bundle install with explicit source paths" do #{Bundler::VERSION} G - expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).to include_gems "myrack 0.9.1" end it "does not remove existing ruby platform" do build_lib "foo", "1.0", path: lib_path("foo") do |s| - s.add_dependency "rack", "0.9.1" + s.add_dependency "myrack", "0.9.1" end checksums = checksums_section_when_existing do |c| @@ -832,19 +832,19 @@ RSpec.describe "bundle install with explicit source paths" do bundle "lock" - checksums.no_checksum "rack", "0.9.1" + checksums.no_checksum "myrack", "0.9.1" expect(lockfile).to eq <<~G PATH remote: #{lib_path("foo")} specs: foo (1.0) - rack (= 0.9.1) + myrack (= 0.9.1) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms("ruby")} @@ -869,12 +869,12 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :git => "#{lib_path("bar")}" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :path => "#{lib_path("bar")}" G @@ -888,7 +888,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar" path "#{lib_path("foo")}" do gem "foo" @@ -898,7 +898,7 @@ RSpec.describe "bundle install with explicit source paths" do build_lib "bar", "1.0", path: lib_path("foo/bar") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path("foo")}" do gem "foo" gem "bar" @@ -915,13 +915,13 @@ RSpec.describe "bundle install with explicit source paths" do gemfile lib_path("private_lib/Gemfile"), <<-G source "http://localgemserver.test" gemspec - gem 'rack' + gem 'myrack' G bundle :install, env: { "DEBUG" => "1" }, artifice: "endpoint", dir: lib_path("private_lib") - expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) + expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=myrack$}) expect(out).not_to match(/^HTTP GET.*private_lib/) expect(the_bundle).to include_gems "private_lib 2.2", dir: lib_path("private_lib") - expect(the_bundle).to include_gems "rack 1.0", dir: lib_path("private_lib") + expect(the_bundle).to include_gems "myrack 1.0", dir: lib_path("private_lib") end end @@ -929,7 +929,7 @@ RSpec.describe "bundle install with explicit source paths" do it "runs pre-install hooks" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -949,7 +949,7 @@ RSpec.describe "bundle install with explicit source paths" do it "runs post-install hooks" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -969,7 +969,7 @@ RSpec.describe "bundle install with explicit source paths" do it "complains if the install hook fails" do build_git "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -1000,7 +1000,7 @@ RSpec.describe "bundle install with explicit source paths" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" gem "bar", :path => "#{lib_path("bar-1.0")}" G diff --git a/spec/bundler/install/gemfile/platform_spec.rb b/spec/bundler/install/gemfile/platform_spec.rb index d90dacdc02..dd7ee83c92 100644 --- a/spec/bundler/install/gemfile/platform_spec.rb +++ b/spec/bundler/install/gemfile/platform_spec.rb @@ -4,30 +4,30 @@ RSpec.describe "bundle install across platforms" do it "maintains the same lockfile if all gems are compatible across platforms" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{not_local} DEPENDENCIES - rack + myrack G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 0.9.1" + expect(the_bundle).to include_gems "myrack 0.9.1" end it "pulls in the correct platform specific gem" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)} + remote: https://gem.repo1 specs: platform_specific (1.0) platform_specific (1.0-java) @@ -42,18 +42,18 @@ RSpec.describe "bundle install across platforms" do simulate_platform "java" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - expect(the_bundle).to include_gems "platform_specific 1.0 JAVA" + expect(the_bundle).to include_gems "platform_specific 1.0 java" end it "pulls the pure ruby version on jruby if the java platform is not present in the lockfile and bundler is run in frozen mode", :jruby_only do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)} + remote: https://gem.repo1 specs: platform_specific (1.0) @@ -67,12 +67,12 @@ RSpec.describe "bundle install across platforms" do bundle "config set --local frozen true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" end context "on universal Rubies" do @@ -80,15 +80,12 @@ RSpec.describe "bundle install across platforms" do build_repo4 do build_gem "darwin_single_arch" do |s| s.platform = "ruby" - s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 RUBY'" end build_gem "darwin_single_arch" do |s| s.platform = "arm64-darwin" - s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 arm64-darwin'" end build_gem "darwin_single_arch" do |s| s.platform = "x86_64-darwin" - s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 x86_64-darwin'" end end end @@ -96,7 +93,7 @@ RSpec.describe "bundle install across platforms" do it "pulls in the correct architecture gem" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: darwin_single_arch (1.0) darwin_single_arch (1.0-arm64-darwin) @@ -112,7 +109,7 @@ RSpec.describe "bundle install across platforms" do simulate_platform "universal-darwin-21" simulate_ruby_platform "universal.x86_64-darwin21" do install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "darwin_single_arch" G @@ -124,7 +121,7 @@ RSpec.describe "bundle install across platforms" do it "pulls in the correct architecture gem on arm64e macOS Ruby" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: darwin_single_arch (1.0) darwin_single_arch (1.0-arm64-darwin) @@ -140,7 +137,7 @@ RSpec.describe "bundle install across platforms" do simulate_platform "universal-darwin-21" simulate_ruby_platform "universal.arm64e-darwin21" do install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "darwin_single_arch" G @@ -153,12 +150,12 @@ RSpec.describe "bundle install across platforms" do it "works with gems that have different dependencies" do simulate_platform "java" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" G - expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA", "weakling 0.0.3" + expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3" simulate_new_machine bundle "config set --local force_ruby_platform true" @@ -171,7 +168,7 @@ RSpec.describe "bundle install across platforms" do simulate_platform "java" bundle "install" - expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA", "weakling 0.0.3" + expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3" end it "does not keep unneeded platforms for gems that are used" do @@ -179,16 +176,16 @@ RSpec.describe "bundle install across platforms" do build_gem "empyrean", "0.1.0" build_gem "coderay", "1.1.2" build_gem "method_source", "0.9.0" - build_gem("spoon", "0.0.6") {|s| s.add_runtime_dependency "ffi" } + build_gem("spoon", "0.0.6") {|s| s.add_dependency "ffi" } build_gem "pry", "0.11.3" do |s| s.platform = "java" - s.add_runtime_dependency "coderay", "~> 1.1.0" - s.add_runtime_dependency "method_source", "~> 0.9.0" - s.add_runtime_dependency "spoon", "~> 0.0" + s.add_dependency "coderay", "~> 1.1.0" + s.add_dependency "method_source", "~> 0.9.0" + s.add_dependency "spoon", "~> 0.0" end build_gem "pry", "0.11.3" do |s| - s.add_runtime_dependency "coderay", "~> 1.1.0" - s.add_runtime_dependency "method_source", "~> 0.9.0" + s.add_dependency "coderay", "~> 1.1.0" + s.add_dependency "method_source", "~> 0.9.0" end build_gem("ffi", "1.9.23") {|s| s.platform = "java" } build_gem("ffi", "1.9.23") @@ -197,7 +194,7 @@ RSpec.describe "bundle install across platforms" do simulate_platform java install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "empyrean", "0.1.0" gem "pry" @@ -214,7 +211,7 @@ RSpec.describe "bundle install across platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: coderay (1.1.2) empyrean (0.1.0) @@ -242,7 +239,7 @@ RSpec.describe "bundle install across platforms" do good_lockfile = <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: coderay (1.1.2) empyrean (0.1.0) @@ -274,7 +271,7 @@ RSpec.describe "bundle install across platforms" do bad_lockfile = <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: coderay (1.1.2) empyrean (0.1.0) @@ -332,20 +329,20 @@ RSpec.describe "bundle install across platforms" do update_repo2 do build_gem "fspath", "3" build_gem "image_optim_pack", "1.2.3" do |s| - s.add_runtime_dependency "fspath", ">= 2.1", "< 4" + s.add_dependency "fspath", ">= 2.1", "< 4" end build_gem "image_optim_pack", "1.2.3" do |s| s.platform = "universal-darwin" - s.add_runtime_dependency "fspath", "< 4", ">= 2.1" + s.add_dependency "fspath", "< 4", ">= 2.1" end end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" G install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "image_optim_pack" G @@ -357,9 +354,9 @@ RSpec.describe "bundle install across platforms" do it "fetches gems again after changing the version of Ruby" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G bundle "config set --local path vendor/bundle" @@ -368,18 +365,18 @@ RSpec.describe "bundle install across platforms" do FileUtils.mv(vendored_gems, bundled_app("vendor/bundle", Gem.ruby_engine, "1.8")) bundle :install - expect(vendored_gems("gems/rack-1.0.0")).to exist + expect(vendored_gems("gems/myrack-1.0.0")).to exist end it "keeps existing platforms when installing with force_ruby_platform" do - checksums = checksums_section do |c| - c.no_checksum "platform_specific", "1.0" - c.no_checksum "platform_specific", "1.0", "java" + checksums = checksums_section_when_existing do |c| + c.checksum gem_repo1, "platform_specific", "1.0" + c.checksum gem_repo1, "platform_specific", "1.0", "java" end lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: platform_specific (1.0-java) @@ -394,17 +391,17 @@ RSpec.describe "bundle install across platforms" do bundle "config set --local force_ruby_platform true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G checksums.checksum gem_repo1, "platform_specific", "1.0" - expect(the_bundle).to include_gem "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gem "platform_specific 1.0 ruby" expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: platform_specific (1.0) platform_specific (1.0-java) @@ -425,7 +422,7 @@ end RSpec.describe "bundle install with platform conditionals" do it "installs gems tagged w/ the current platforms" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platforms :#{local_tag} do gem "nokogiri" @@ -437,14 +434,14 @@ RSpec.describe "bundle install with platform conditionals" do it "does not install gems tagged w/ another platforms" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" platforms :#{not_local_tag} do gem "nokogiri" end G - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" expect(the_bundle).not_to include_gems "nokogiri 1.4.2" end @@ -458,7 +455,7 @@ RSpec.describe "bundle install with platform conditionals" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "activesupport" @@ -469,7 +466,7 @@ RSpec.describe "bundle install with platform conditionals" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: activesupport (6.1.4.1) tzinfo (~> 2.0) @@ -493,7 +490,7 @@ RSpec.describe "bundle install with platform conditionals" do it "installs gems tagged w/ the current platforms inline" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri", :platforms => :#{local_tag} G expect(the_bundle).to include_gems "nokogiri 1.4.2" @@ -501,17 +498,17 @@ RSpec.describe "bundle install with platform conditionals" do it "does not install gems tagged w/ another platforms inline" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "nokogiri", :platforms => :#{not_local_tag} G - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" expect(the_bundle).not_to include_gems "nokogiri 1.4.2" end it "installs gems tagged w/ the current platform inline" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri", :platform => :#{local_tag} G expect(the_bundle).to include_gems "nokogiri 1.4.2" @@ -519,7 +516,7 @@ RSpec.describe "bundle install with platform conditionals" do it "doesn't install gems tagged w/ another platform inline" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri", :platform => :#{not_local_tag} G expect(the_bundle).not_to include_gems "nokogiri 1.4.2" @@ -529,7 +526,7 @@ RSpec.describe "bundle install with platform conditionals" do build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platform :#{not_local_tag} do gem "foo", :git => "#{lib_path("foo-1.0")}" end @@ -542,7 +539,7 @@ RSpec.describe "bundle install with platform conditionals" do bundle "config set --local force_ruby_platform true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "some_gem", :platform => :rbx G @@ -553,7 +550,7 @@ RSpec.describe "bundle install with platform conditionals" do it "does not attempt to install gems from other rubies when using --local" do bundle "config set --local force_ruby_platform true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "some_gem", platform: :ruby_22 G @@ -565,9 +562,9 @@ RSpec.describe "bundle install with platform conditionals" do bundle "config set --local force_ruby_platform true" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", :platform => [:windows, :mswin, :mswin64, :mingw, :x64_mingw, :jruby] + gem "myrack", :platform => [:windows, :mswin, :mswin64, :mingw, :x64_mingw, :jruby] G bundle "install" @@ -576,14 +573,14 @@ RSpec.describe "bundle install with platform conditionals" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS ruby DEPENDENCIES - rack + myrack #{checksums_section_when_existing} BUNDLED WITH #{Bundler::VERSION} @@ -602,7 +599,7 @@ RSpec.describe "bundle install with platform conditionals" do end install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "listen" gem "ffi", :platform => :windows diff --git a/spec/bundler/install/gemfile/ruby_spec.rb b/spec/bundler/install/gemfile/ruby_spec.rb index b64d633fd3..3e15d82bbe 100644 --- a/spec/bundler/install/gemfile/ruby_spec.rb +++ b/spec/bundler/install/gemfile/ruby_spec.rb @@ -10,77 +10,77 @@ RSpec.describe "ruby requirement" do # requirement. This test verifies the fix, committed in bfbad5c5. it "allows adding gems" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "#{Gem.ruby_version}" - gem "rack" + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "#{Gem.ruby_version}" - gem "rack" - gem "rack-obama" + gem "myrack" + gem "myrack-obama" G - expect(the_bundle).to include_gems "rack-obama 1.0" + expect(the_bundle).to include_gems "myrack-obama 1.0" end it "allows removing the ruby version requirement" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "~> #{Gem.ruby_version}" - gem "rack" + gem "myrack" G expect(lockfile).to include("RUBY VERSION") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(lockfile).not_to include("RUBY VERSION") end it "allows changing the ruby version requirement to something compatible" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= #{current_ruby_minor}" - gem "rack" + gem "myrack" G allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= #{Gem.ruby_version}" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) end it "allows changing the ruby version requirement to something incompatible" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= 1.0.0" - gem "rack" + gem "myrack" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack RUBY VERSION ruby 2.1.4p422 @@ -92,30 +92,30 @@ RSpec.describe "ruby requirement" do allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= #{current_ruby_minor}" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) end it "allows requirements with trailing whitespace" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "#{Gem.ruby_version}\\n \t\\n" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "fails gracefully with malformed requirements" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby ">= 0", "-.\\0" - gem "rack" + gem "myrack" G expect(err).to include("There was an error parsing") # i.e. DSL error, not error template @@ -125,9 +125,9 @@ RSpec.describe "ruby requirement" do create_file ".ruby-version", Gem.ruby_version.to_s install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby file: ".ruby-version" - gem "rack" + gem "myrack" G expect(lockfile).to include("RUBY VERSION") @@ -137,16 +137,16 @@ RSpec.describe "ruby requirement" do create_file ".ruby-version", Gem.ruby_version.to_s gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby file: ".ruby-version" - gem "rack" + gem "myrack" G nested_dir = bundled_app(".ruby-lsp") FileUtils.mkdir nested_dir - create_file ".ruby-lsp/Gemfile", <<-G + gemfile ".ruby-lsp/Gemfile", <<-G eval_gemfile(File.expand_path("../Gemfile", __dir__)) G diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index daee8a2744..eea39c4664 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -2,28 +2,28 @@ RSpec.describe "bundle install with gems on multiple sources" do # repo1 is built automatically before all of the specs run - # it contains rack-obama 1.0.0 and rack 0.9.1 & 1.0.0 amongst other gems + # it contains myrack-obama 1.0.0 and myrack 0.9.1 & 1.0.0 amongst other gems context "without source affinity" do before do - # Oh no! Someone evil is trying to hijack rack :( + # Oh no! Someone evil is trying to hijack myrack :( # need this to be broken to check for correct source ordering build_repo gem_repo3 do - build_gem "rack", repo3_rack_version do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", repo3_myrack_version do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end end end context "with multiple toplevel sources" do - let(:repo3_rack_version) { "1.0.0" } + let(:repo3_myrack_version) { "1.0.0" } before do gemfile <<-G source "https://gem.repo3" source "https://gem.repo1" - gem "rack-obama" - gem "rack" + gem "myrack-obama" + gem "myrack" G end @@ -33,13 +33,13 @@ RSpec.describe "bundle install with gems on multiple sources" do remote: https://gem.repo3/ remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{local_platform} DEPENDENCIES - depends_on_rack! + depends_on_myrack! BUNDLED WITH #{Bundler::VERSION} @@ -51,9 +51,9 @@ RSpec.describe "bundle install with gems on multiple sources" do expect(err).to eq <<~E.strip [DEPRECATED] Your Gemfile contains multiple global sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. Bundler found mismatched checksums. This is a potential security risk. - #{checksum_to_lock(gem_repo1, "rack", "1.0.0")} + #{checksum_to_lock(gem_repo1, "myrack", "1.0.0")} from the API at https://gem.repo1/ - #{checksum_to_lock(gem_repo3, "rack", "1.0.0")} + #{checksum_to_lock(gem_repo3, "myrack", "1.0.0")} from the API at https://gem.repo3/ Mismatched checksums each have an authoritative source: @@ -74,9 +74,9 @@ RSpec.describe "bundle install with gems on multiple sources" do it "warns about ambiguous gems, but installs anyway, prioritizing sources last to first", bundler: "< 3" do bundle :install, artifice: "compact_index" - expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include("Warning: the gem 'myrack' was found in multiple sources.") expect(err).to include("Installed from: https://gem.repo1") - expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0", source: "remote1") + expect(the_bundle).to include_gems("myrack-obama 1.0.0", "myrack 1.0.0", source: "remote1") end it "does not use the full index unnecessarily", bundler: "< 3" do @@ -97,22 +97,22 @@ RSpec.describe "bundle install with gems on multiple sources" do end context "when different versions of the same gem are in multiple sources" do - let(:repo3_rack_version) { "1.2" } + let(:repo3_myrack_version) { "1.2" } before do gemfile <<-G source "https://gem.repo3" source "https://gem.repo1" - gem "rack-obama" - gem "rack", "1.0.0" # force it to install the working version in repo1 + gem "myrack-obama" + gem "myrack", "1.0.0" # force it to install the working version in repo1 G end it "warns about ambiguous gems, but installs anyway", bundler: "< 3" do bundle :install, artifice: "compact_index" - expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include("Warning: the gem 'myrack' was found in multiple sources.") expect(err).to include("Installed from: https://gem.repo1") - expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0", source: "remote1") + expect(the_bundle).to include_gems("myrack-obama 1.0.0", "myrack 1.0.0", source: "remote1") end it "fails", bundler: "3" do @@ -154,15 +154,15 @@ RSpec.describe "bundle install with gems on multiple sources" do context "with source affinity" do context "with sources given by a block" do before do - # Oh no! Someone evil is trying to hijack rack :( + # Oh no! Someone evil is trying to hijack myrack :( # need this to be broken to check for correct source ordering build_repo gem_repo3 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end - build_gem "rack-obama" do |s| - s.add_dependency "rack" + build_gem "myrack-obama" do |s| + s.add_dependency "myrack" end end @@ -170,76 +170,76 @@ RSpec.describe "bundle install with gems on multiple sources" do source "https://gem.repo3" source "https://gem.repo1" do gem "thin" # comes first to test name sorting - gem "rack" + gem "myrack" end - gem "rack-obama" # should come from repo3! + gem "myrack-obama" # should come from repo3! G end it "installs the gems without any warning" do bundle :install, artifice: "compact_index" expect(err).not_to include("Warning") - expect(the_bundle).to include_gems("rack-obama 1.0.0") - expect(the_bundle).to include_gems("rack 1.0.0", source: "remote1") + expect(the_bundle).to include_gems("myrack-obama 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0", source: "remote1") end it "can cache and deploy" do bundle :cache, artifice: "compact_index" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/rack-obama-1.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/myrack-obama-1.0.gem")).to exist bundle "config set --local deployment true" bundle :install, artifice: "compact_index" - expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0") + expect(the_bundle).to include_gems("myrack-obama 1.0.0", "myrack 1.0.0") end end context "with sources set by an option" do before do - # Oh no! Someone evil is trying to hijack rack :( + # Oh no! Someone evil is trying to hijack myrack :( # need this to be broken to check for correct source ordering build_repo gem_repo3 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end - build_gem "rack-obama" do |s| - s.add_dependency "rack" + build_gem "myrack-obama" do |s| + s.add_dependency "myrack" end end install_gemfile <<-G, artifice: "compact_index" source "https://gem.repo3" - gem "rack-obama" # should come from repo3! - gem "rack", :source => "https://gem.repo1" + gem "myrack-obama" # should come from repo3! + gem "myrack", :source => "https://gem.repo1" G end it "installs the gems without any warning" do expect(err).not_to include("Warning") - expect(the_bundle).to include_gems("rack-obama 1.0.0", "rack 1.0.0") + expect(the_bundle).to include_gems("myrack-obama 1.0.0", "myrack 1.0.0") end end context "when a pinned gem has an indirect dependency in the pinned source" do before do build_repo gem_repo3 do - build_gem "depends_on_rack", "1.0.1" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack", "1.0.1" do |s| + s.add_dependency "myrack" end end - # we need a working rack gem in repo3 + # we need a working myrack gem in repo3 update_repo gem_repo3 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end gemfile <<-G source "https://gem.repo2" source "https://gem.repo3" do - gem "depends_on_rack" + gem "depends_on_myrack" end G end @@ -252,7 +252,7 @@ RSpec.describe "bundle install with gems on multiple sources" do it "installs from the same source without any warning" do bundle :install, artifice: "compact_index" expect(err).not_to include("Warning") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", source: "remote3") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote3") end end @@ -260,8 +260,8 @@ RSpec.describe "bundle install with gems on multiple sources" do before do # need this to be broken to check for correct source ordering build_repo gem_repo2 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end end end @@ -269,32 +269,32 @@ RSpec.describe "bundle install with gems on multiple sources" do it "installs from the same source without any warning" do bundle :install, artifice: "compact_index" - expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", source: "remote3") + expect(err).not_to include("Warning: the gem 'myrack' was found in multiple sources.") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote3") # In https://github.com/bundler/bundler/issues/3585 this failed # when there is already a lock file, and the gems are missing, so try again system_gems [] bundle :install, artifice: "compact_index" - expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", source: "remote3") + expect(err).not_to include("Warning: the gem 'myrack' was found in multiple sources.") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote3") end end end context "when a pinned gem has an indirect dependency in a different source" do before do - # In these tests, we need a working rack gem in repo2 and not repo3 + # In these tests, we need a working myrack gem in repo2 and not repo3 build_repo gem_repo3 do - build_gem "depends_on_rack", "1.0.1" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack", "1.0.1" do |s| + s.add_dependency "myrack" end end build_repo gem_repo2 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end end @@ -303,14 +303,14 @@ RSpec.describe "bundle install with gems on multiple sources" do install_gemfile <<-G, artifice: "compact_index" source "https://gem.repo2" source "https://gem.repo3" do - gem "depends_on_rack" + gem "depends_on_myrack" end G end it "installs from the other source without any warning" do expect(err).not_to include("Warning") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0") end end @@ -320,7 +320,7 @@ RSpec.describe "bundle install with gems on multiple sources" do source "https://gem.repo1" source "https://gem.repo2" source "https://gem.repo3" do - gem "depends_on_rack" + gem "depends_on_myrack" end G end @@ -331,9 +331,9 @@ RSpec.describe "bundle install with gems on multiple sources" do expect(err).to eq(<<~E.strip) [DEPRECATED] Your Gemfile contains multiple global sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. Bundler found mismatched checksums. This is a potential security risk. - #{checksum_to_lock(gem_repo2, "rack", "1.0.0")} + #{checksum_to_lock(gem_repo2, "myrack", "1.0.0")} from the API at https://gem.repo2/ - #{checksum_to_lock(gem_repo1, "rack", "1.0.0")} + #{checksum_to_lock(gem_repo1, "myrack", "1.0.0")} from the API at https://gem.repo1/ Mismatched checksums each have an authoritative source: @@ -348,20 +348,20 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "fails when the two sources agree, but the local gem calculates a different checksum", bundler: "< 3" do - rack_checksum = "c0ffee11" * 8 - bundle :install, artifice: "compact_index", env: { "BUNDLER_SPEC_RACK_CHECKSUM" => rack_checksum }, raise_on_error: false + myrack_checksum = "c0ffee11" * 8 + bundle :install, artifice: "compact_index", env: { "BUNDLER_SPEC_MYRACK_CHECKSUM" => myrack_checksum }, raise_on_error: false expect(err).to eq(<<~E.strip) [DEPRECATED] Your Gemfile contains multiple global sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. Bundler found mismatched checksums. This is a potential security risk. - rack (1.0.0) sha256=#{rack_checksum} + myrack (1.0.0) sha256=#{myrack_checksum} from the API at https://gem.repo2/ and the API at https://gem.repo1/ - #{checksum_to_lock(gem_repo2, "rack", "1.0.0")} - from the gem at #{default_bundle_path("cache", "rack-1.0.0.gem")} + #{checksum_to_lock(gem_repo2, "myrack", "1.0.0")} + from the gem at #{default_bundle_path("cache", "myrack-1.0.0.gem")} If you trust the API at https://gem.repo2/, to resolve this issue you can: - 1. remove the gem at #{default_bundle_path("cache", "rack-1.0.0.gem")} + 1. remove the gem at #{default_bundle_path("cache", "myrack-1.0.0.gem")} 2. run `bundle install` To ignore checksum security warnings, disable checksum validation with @@ -371,15 +371,15 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "installs from the other source and warns about ambiguous gems when the sources have the same checksum", bundler: "< 3" do - gem_checksum = checksum_digest(gem_repo2, "rack", "1.0.0") - bundle :install, artifice: "compact_index", env: { "BUNDLER_SPEC_RACK_CHECKSUM" => gem_checksum, "DEBUG" => "1" } + gem_checksum = checksum_digest(gem_repo2, "myrack", "1.0.0") + bundle :install, artifice: "compact_index", env: { "BUNDLER_SPEC_MYRACK_CHECKSUM" => gem_checksum, "DEBUG" => "1" } - expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include("Warning: the gem 'myrack' was found in multiple sources.") expect(err).to include("Installed from: https://gem.repo2") checksums = checksums_section_when_existing do |c| - c.checksum gem_repo3, "depends_on_rack", "1.0.1" - c.checksum gem_repo2, "rack", "1.0.0" + c.checksum gem_repo3, "depends_on_myrack", "1.0.1" + c.checksum gem_repo2, "myrack", "1.0.0" end expect(lockfile).to eq <<~L @@ -387,26 +387,26 @@ RSpec.describe "bundle install with gems on multiple sources" do remote: https://gem.repo1/ remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) GEM remote: https://gem.repo3/ specs: - depends_on_rack (1.0.1) - rack + depends_on_myrack (1.0.1) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - depends_on_rack! + depends_on_myrack! #{checksums} BUNDLED WITH #{Bundler::VERSION} L previous_lockfile = lockfile - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0") expect(lockfile).to eq(previous_lockfile) end @@ -414,12 +414,12 @@ RSpec.describe "bundle install with gems on multiple sources" do bundle "config set --local disable_checksum_validation true" bundle :install, artifice: "compact_index" - expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include("Warning: the gem 'myrack' was found in multiple sources.") expect(err).to include("Installed from: https://gem.repo2") checksums = checksums_section_when_existing do |c| - c.no_checksum "depends_on_rack", "1.0.1" - c.no_checksum "rack", "1.0.0" + c.no_checksum "depends_on_myrack", "1.0.1" + c.no_checksum "myrack", "1.0.0" end expect(lockfile).to eq <<~L @@ -427,26 +427,26 @@ RSpec.describe "bundle install with gems on multiple sources" do remote: https://gem.repo1/ remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) GEM remote: https://gem.repo3/ specs: - depends_on_rack (1.0.1) - rack + depends_on_myrack (1.0.1) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - depends_on_rack! + depends_on_myrack! #{checksums} BUNDLED WITH #{Bundler::VERSION} L previous_lockfile = lockfile - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0") expect(lockfile).to eq(previous_lockfile) end @@ -461,33 +461,33 @@ RSpec.describe "bundle install with gems on multiple sources" do before do # need this to be broken to check for correct source ordering build_repo gem_repo2 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end end gemfile <<-G - source "https://gem.repo3" # contains depends_on_rack - source "https://gem.repo2" # contains broken rack + source "https://gem.repo3" # contains depends_on_myrack + source "https://gem.repo2" # contains broken myrack - gem "depends_on_rack" # installed from gem_repo3 - gem "rack", :source => "https://gem.repo1" + gem "depends_on_myrack" # installed from gem_repo3 + gem "myrack", :source => "https://gem.repo1" G end it "installs the dependency from the pinned source without warning", bundler: "< 3" do bundle :install, artifice: "compact_index" - expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") + expect(err).not_to include("Warning: the gem 'myrack' was found in multiple sources.") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0") # In https://github.com/rubygems/bundler/issues/3585 this failed # when there is already a lock file, and the gems are missing, so try again system_gems [] bundle :install, artifice: "compact_index" - expect(err).not_to include("Warning: the gem 'rack' was found in multiple sources.") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0") + expect(err).not_to include("Warning: the gem 'myrack' was found in multiple sources.") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0") end it "fails", bundler: "3" do @@ -560,8 +560,8 @@ RSpec.describe "bundle install with gems on multiple sources" do context "when a top-level gem has an indirect dependency" do before do build_repo gem_repo2 do - build_gem "depends_on_rack", "1.0.1" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack", "1.0.1" do |s| + s.add_dependency "myrack" end end @@ -572,7 +572,7 @@ RSpec.describe "bundle install with gems on multiple sources" do gemfile <<-G source "https://gem.repo2" - gem "depends_on_rack" + gem "depends_on_myrack" source "https://gem.repo3" do gem "unrelated_gem" @@ -583,15 +583,15 @@ RSpec.describe "bundle install with gems on multiple sources" do context "and the dependency is only in the top-level source" do before do update_repo gem_repo2 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end end it "installs the dependency from the top-level source without warning" do bundle :install, artifice: "compact_index" expect(err).not_to include("Warning") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", "unrelated_gem 1.0.0") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", source: "remote2") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", "unrelated_gem 1.0.0") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote2") expect(the_bundle).to include_gems("unrelated_gem 1.0.0", source: "remote3") end end @@ -599,8 +599,8 @@ RSpec.describe "bundle install with gems on multiple sources" do context "and the dependency is only in a pinned source" do before do update_repo gem_repo3 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end end end @@ -610,10 +610,10 @@ RSpec.describe "bundle install with gems on multiple sources" do expect(err).to end_with <<~E.strip Could not find compatible versions - Because every version of depends_on_rack depends on rack >= 0 - and rack >= 0 could not be found in rubygems repository https://gem.repo2/ or installed locally, - depends_on_rack cannot be used. - So, because Gemfile depends on depends_on_rack >= 0, + Because every version of depends_on_myrack depends on myrack >= 0 + and myrack >= 0 could not be found in rubygems repository https://gem.repo2/ or installed locally, + depends_on_myrack cannot be used. + So, because Gemfile depends on depends_on_myrack >= 0, version solving has failed. E end @@ -622,12 +622,12 @@ RSpec.describe "bundle install with gems on multiple sources" do context "and the dependency is in both the top-level and a pinned source" do before do update_repo gem_repo2 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end update_repo gem_repo3 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end end end @@ -635,9 +635,9 @@ RSpec.describe "bundle install with gems on multiple sources" do it "installs the dependency from the top-level source without warning" do bundle :install, artifice: "compact_index" expect(err).not_to include("Warning") - expect(run("require 'rack'; puts RACK")).to eq("1.0.0") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", "unrelated_gem 1.0.0") - expect(the_bundle).to include_gems("depends_on_rack 1.0.1", "rack 1.0.0", source: "remote2") + expect(run("require 'myrack'; puts MYRACK")).to eq("1.0.0") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", "unrelated_gem 1.0.0") + expect(the_bundle).to include_gems("depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote2") expect(the_bundle).to include_gems("unrelated_gem 1.0.0", source: "remote3") end end @@ -646,12 +646,12 @@ RSpec.describe "bundle install with gems on multiple sources" do context "when a scoped gem has a deeply nested indirect dependency" do before do build_repo gem_repo3 do - build_gem "depends_on_depends_on_rack", "1.0.1" do |s| - s.add_dependency "depends_on_rack" + build_gem "depends_on_depends_on_myrack", "1.0.1" do |s| + s.add_dependency "depends_on_myrack" end - build_gem "depends_on_rack", "1.0.1" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack", "1.0.1" do |s| + s.add_dependency "myrack" end end @@ -659,7 +659,7 @@ RSpec.describe "bundle install with gems on multiple sources" do source "https://gem.repo2" source "https://gem.repo3" do - gem "depends_on_depends_on_rack" + gem "depends_on_depends_on_myrack" end G end @@ -667,15 +667,15 @@ RSpec.describe "bundle install with gems on multiple sources" do context "and the dependency is only in the top-level source" do before do update_repo gem_repo2 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end end it "installs the dependency from the top-level source" do bundle :install, artifice: "compact_index" - expect(the_bundle).to include_gems("depends_on_depends_on_rack 1.0.1", "depends_on_rack 1.0.1", "rack 1.0.0") - expect(the_bundle).to include_gems("rack 1.0.0", source: "remote2") - expect(the_bundle).to include_gems("depends_on_depends_on_rack 1.0.1", "depends_on_rack 1.0.1", source: "remote3") + expect(the_bundle).to include_gems("depends_on_depends_on_myrack 1.0.1", "depends_on_myrack 1.0.1", "myrack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0", source: "remote2") + expect(the_bundle).to include_gems("depends_on_depends_on_myrack 1.0.1", "depends_on_myrack 1.0.1", source: "remote3") end end @@ -684,32 +684,32 @@ RSpec.describe "bundle install with gems on multiple sources" do build_repo2 update_repo gem_repo3 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end end it "installs the dependency from the pinned source" do bundle :install, artifice: "compact_index" - expect(the_bundle).to include_gems("depends_on_depends_on_rack 1.0.1", "depends_on_rack 1.0.1", "rack 1.0.0", source: "remote3") + expect(the_bundle).to include_gems("depends_on_depends_on_myrack 1.0.1", "depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote3") end end context "and the dependency is in both the top-level and a pinned source" do before do update_repo gem_repo2 do - build_gem "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end end update_repo gem_repo3 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end end it "installs the dependency from the pinned source without warning" do bundle :install, artifice: "compact_index" - expect(the_bundle).to include_gems("depends_on_depends_on_rack 1.0.1", "depends_on_rack 1.0.1", "rack 1.0.0", source: "remote3") + expect(the_bundle).to include_gems("depends_on_depends_on_myrack 1.0.1", "depends_on_myrack 1.0.1", "myrack 1.0.0", source: "remote3") end end end @@ -742,12 +742,12 @@ RSpec.describe "bundle install with gems on multiple sources" do end build_gem "minitest", "5.14.3" - build_gem "rack", "2.2.3" + build_gem "myrack", "2.2.3" build_gem "redis", "4.2.5" build_gem "sidekiq", "6.1.3" do |s| s.add_dependency "connection_pool", ">= 2.2.2" - s.add_dependency "rack", "~> 2.0" + s.add_dependency "myrack", "~> 2.0" s.add_dependency "redis", ">= 4.2.0" end @@ -789,7 +789,7 @@ RSpec.describe "bundle install with gems on multiple sources" do c.checksum gem_repo2, "connection_pool", "2.2.3" c.checksum gem_repo2, "i18n", "1.8.9" c.checksum gem_repo2, "minitest", "5.14.3" - c.checksum gem_repo2, "rack", "2.2.3" + c.checksum gem_repo2, "myrack", "2.2.3" c.checksum gem_repo2, "redis", "4.2.5" c.checksum gem_repo2, "sidekiq", "6.1.3" c.checksum gem_repo3, "sidekiq-pro", "5.2.1" @@ -814,11 +814,11 @@ RSpec.describe "bundle install with gems on multiple sources" do i18n (1.8.9) concurrent-ruby (~> 1.0) minitest (5.14.3) - rack (2.2.3) + myrack (2.2.3) redis (4.2.5) sidekiq (6.1.3) connection_pool (>= 2.2.2) - rack (~> 2.0) + myrack (~> 2.0) redis (>= 4.2.0) sidekiq-pro (5.2.1) connection_pool (>= 2.2.3) @@ -866,11 +866,11 @@ RSpec.describe "bundle install with gems on multiple sources" do i18n (1.8.9) concurrent-ruby (~> 1.0) minitest (5.14.3) - rack (2.2.3) + myrack (2.2.3) redis (4.2.5) sidekiq (6.1.3) connection_pool (>= 2.2.2) - rack (~> 2.0) + myrack (~> 2.0) redis (>= 4.2.0) thread_safe (0.3.6) tzinfo (1.2.9) @@ -957,11 +957,11 @@ RSpec.describe "bundle install with gems on multiple sources" do i18n (1.8.9) concurrent-ruby (~> 1.0) minitest (5.14.3) - rack (2.2.3) + myrack (2.2.3) redis (4.2.5) sidekiq (6.1.3) connection_pool (>= 2.2.2) - rack (~> 2.0) + myrack (~> 2.0) redis (>= 4.2.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) @@ -1014,11 +1014,11 @@ RSpec.describe "bundle install with gems on multiple sources" do i18n (1.8.9) concurrent-ruby (~> 1.0) minitest (5.14.3) - rack (2.2.3) + myrack (2.2.3) redis (4.2.5) sidekiq (6.1.3) connection_pool (>= 2.2.2) - rack (~> 2.0) + myrack (~> 2.0) redis (>= 4.2.0) thread_safe (0.3.6) tzinfo (1.2.9) @@ -1174,7 +1174,7 @@ RSpec.describe "bundle install with gems on multiple sources" do context "with an existing lockfile" do before do - system_gems "rack-0.9.1", "rack-1.0.0", path: default_bundle_path + system_gems "myrack-0.9.1", "myrack-1.0.0", path: default_bundle_path lockfile <<-L GEM @@ -1184,26 +1184,26 @@ RSpec.describe "bundle install with gems on multiple sources" do GEM remote: https://gem.repo3 specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack! + myrack! L gemfile <<-G source "https://gem.repo1" source "https://gem.repo3" do - gem 'rack' + gem 'myrack' end G end # Reproduction of https://github.com/rubygems/bundler/issues/3298 it "does not unlock the installed gem on exec" do - expect(the_bundle).to include_gems("rack 0.9.1") + expect(the_bundle).to include_gems("myrack 0.9.1") end end @@ -1214,13 +1214,13 @@ RSpec.describe "bundle install with gems on multiple sources" do remote: https://gem.repo1/ remote: https://gem.repo3/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack! + myrack! #{checksums_section} BUNDLED WITH #{Bundler::VERSION} @@ -1236,13 +1236,13 @@ RSpec.describe "bundle install with gems on multiple sources" do GEM remote: https://gem.repo3/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack! + myrack! BUNDLED WITH #{Bundler::VERSION} @@ -1251,13 +1251,13 @@ RSpec.describe "bundle install with gems on multiple sources" do before do build_repo gem_repo3 do - build_gem "rack", "0.9.1" + build_gem "myrack", "0.9.1" end gemfile <<-G source "https://gem.repo1" source "https://gem.repo3" do - gem 'rack' + gem 'myrack' end G @@ -1272,7 +1272,7 @@ RSpec.describe "bundle install with gems on multiple sources" do expect(lockfile).to eq(aggregate_gem_section_lockfile) expect(err).to include("Your lockfile contains a single rubygems source section with multiple remotes, which is insecure.") - expect(the_bundle).to include_gems("rack 0.9.1", source: "remote3") + expect(the_bundle).to include_gems("myrack 0.9.1", source: "remote3") end it "prints a checksum warning when the checksums from both sources do not match", bundler: "< 3" do @@ -1280,16 +1280,16 @@ RSpec.describe "bundle install with gems on multiple sources" do bundle "install", artifice: "compact_index", raise_on_error: false - api_checksum1 = checksum_digest(gem_repo1, "rack", "0.9.1") - api_checksum3 = checksum_digest(gem_repo3, "rack", "0.9.1") + api_checksum1 = checksum_digest(gem_repo1, "myrack", "0.9.1") + api_checksum3 = checksum_digest(gem_repo3, "myrack", "0.9.1") expect(exitstatus).to eq(37) expect(err).to eq(<<~E.strip) [DEPRECATED] Your lockfile contains a single rubygems source section with multiple remotes, which is insecure. Make sure you run `bundle install` in non frozen mode and commit the result to make your lockfile secure. Bundler found mismatched checksums. This is a potential security risk. - rack (0.9.1) sha256=#{api_checksum3} + myrack (0.9.1) sha256=#{api_checksum3} from the API at https://gem.repo3/ - rack (0.9.1) sha256=#{api_checksum1} + myrack (0.9.1) sha256=#{api_checksum1} from the API at https://gem.repo1/ Mismatched checksums each have an authoritative source: @@ -1318,8 +1318,8 @@ RSpec.describe "bundle install with gems on multiple sources" do build_lib "foo" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :source => "https://gem.repo1" + source "https://gem.repo1" + gem "myrack", :source => "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" G end @@ -1336,17 +1336,17 @@ RSpec.describe "bundle install with gems on multiple sources" do context "when an older version of the same gem also ships with Ruby" do before do - system_gems "rack-0.9.1" + system_gems "myrack-0.9.1" install_gemfile <<-G, artifice: "compact_index" source "https://gem.repo1" - gem "rack" # should come from repo1! + gem "myrack" # should come from repo1! G end it "installs the gems without any warning" do expect(err).not_to include("Warning") - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") end end @@ -1361,7 +1361,7 @@ RSpec.describe "bundle install with gems on multiple sources" do # Installing this gemfile... gemfile <<-G source 'https://gem.repo1' - gem 'rack' + gem 'myrack' gem 'foo', '~> 0.1', :source => 'https://gem.repo4' gem 'bar', '~> 0.1', :source => 'https://gem.repo4' G @@ -1380,7 +1380,7 @@ RSpec.describe "bundle install with gems on multiple sources" do # And install this gemfile, updating only foo. install_gemfile <<-G, artifice: "compact_index" source 'https://gem.repo1' - gem 'rack' + gem 'myrack' gem 'foo', '~> 0.2', :source => 'https://gem.repo4' gem 'bar', '~> 0.1', :source => 'https://gem.repo4' G @@ -1394,7 +1394,7 @@ RSpec.describe "bundle install with gems on multiple sources" do context "when there is a mix of sources in the gemfile" do before do build_repo gem_repo3 do - build_gem "rack" + build_gem "myrack" end build_lib "path1" @@ -1407,7 +1407,7 @@ RSpec.describe "bundle install with gems on multiple sources" do gem "rails" source "https://gem.repo3" do - gem "rack" + gem "myrack" end gem "path1", :path => "#{lib_path("path1-1.0")}" @@ -1429,14 +1429,14 @@ RSpec.describe "bundle install with gems on multiple sources" do before do install_gemfile <<-G, artifice: "compact_index" source "https://gem.repo1" - gem "rack" + gem "myrack" G end context "and the gemfile changes" do it "is still able to find that gem from remote sources" do build_repo4 do - build_gem "rack", "2.0.1.1.forked" + build_gem "myrack", "2.0.1.1.forked" build_gem "thor", "0.19.1.1.forked" end @@ -1445,10 +1445,10 @@ RSpec.describe "bundle install with gems on multiple sources" do source "https://gem.repo1" source "https://gem.repo4" do - gem "rack", "2.0.1.1.forked" + gem "myrack", "2.0.1.1.forked" gem "thor" end - gem "rack-obama" + gem "myrack-obama" G # Then we change the Gemfile by adding a version to thor @@ -1456,13 +1456,13 @@ RSpec.describe "bundle install with gems on multiple sources" do source "https://gem.repo1" source "https://gem.repo4" do - gem "rack", "2.0.1.1.forked" + gem "myrack", "2.0.1.1.forked" gem "thor", "0.19.1.1.forked" end - gem "rack-obama" + gem "myrack-obama" G - # But we should still be able to find rack 2.0.1.1.forked and install it + # But we should still be able to find myrack 2.0.1.1.forked and install it bundle :install, artifice: "compact_index" end end @@ -1473,30 +1473,30 @@ RSpec.describe "bundle install with gems on multiple sources" do install_gemfile <<-G, artifice: "compact_index" source "https://gem.repo1" - gem "rack" + gem "myrack" G build_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end build_gem "bar" end - build_lib("gemspec_test", path: tmp.join("gemspec_test")) do |s| + build_lib("gemspec_test", path: tmp("gemspec_test")) do |s| s.add_dependency "bar", "=1.0.0" end install_gemfile <<-G, artifice: "compact_index" source "https://gem.repo2" - gem "rack" - gemspec :path => "#{tmp.join("gemspec_test")}" + gem "myrack" + gemspec :path => "#{tmp("gemspec_test")}" G end it "conservatively installs the existing locked version" do - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") end end @@ -1506,7 +1506,7 @@ RSpec.describe "bundle install with gems on multiple sources" do build_gem "bar" end - build_lib("gemspec_test", path: tmp.join("gemspec_test")) do |s| + build_lib("gemspec_test", path: tmp("gemspec_test")) do |s| s.add_development_dependency "bar" end @@ -1517,7 +1517,7 @@ RSpec.describe "bundle install with gems on multiple sources" do gem "bar" end - gemspec :path => "#{tmp.join("gemspec_test")}" + gemspec :path => "#{tmp("gemspec_test")}" G end @@ -1586,27 +1586,27 @@ RSpec.describe "bundle install with gems on multiple sources" do context "when an indirect dependency is available from multiple ambiguous sources", bundler: "< 3" do it "succeeds but warns, suggesting a source block" do build_repo4 do - build_gem "depends_on_rack" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack" do |s| + s.add_dependency "myrack" end - build_gem "rack" + build_gem "myrack" end - install_gemfile <<-G, artifice: "compact_index", raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + install_gemfile <<-G, artifice: "compact_index_extra_api", raise_on_error: false + source "https://global.source" - source "https://gem.repo4" do - gem "depends_on_rack" + source "https://scoped.source/extra" do + gem "depends_on_myrack" end - source "https://gem.repo1" do + source "https://scoped.source" do gem "thin" end G expect(err).to eq <<~EOS.strip - Warning: The gem 'rack' was found in multiple relevant sources. - * rubygems repository https://gem.repo1/ - * rubygems repository https://gem.repo4/ + Warning: The gem 'myrack' was found in multiple relevant sources. + * rubygems repository https://scoped.source/ + * rubygems repository https://scoped.source/extra/ You should add this gem to the source block for the source you wish it to be installed from. EOS expect(last_command).to be_success @@ -1617,26 +1617,28 @@ RSpec.describe "bundle install with gems on multiple sources" do context "when an indirect dependency is available from multiple ambiguous sources", bundler: "3" do it "raises, suggesting a source block" do build_repo4 do - build_gem "depends_on_rack" do |s| - s.add_dependency "rack" + build_gem "depends_on_myrack" do |s| + s.add_dependency "myrack" end - build_gem "rack" + build_gem "myrack" end - install_gemfile <<-G, artifice: "compact_index", raise_on_error: false - source "#{file_uri_for(gem_repo1)}" - source "https://gem.repo4" do - gem "depends_on_rack" + install_gemfile <<-G, artifice: "compact_index_extra_api", raise_on_error: false + source "https://global.source" + + source "https://scoped.source/extra" do + gem "depends_on_myrack" end - source "https://gem.repo1" do + + source "https://scoped.source" do gem "thin" end G expect(last_command).to be_failure expect(err).to eq <<~EOS.strip - The gem 'rack' was found in multiple relevant sources. - * rubygems repository https://gem.repo1/ - * rubygems repository https://gem.repo4/ + The gem 'myrack' was found in multiple relevant sources. + * rubygems repository https://scoped.source/ + * rubygems repository https://scoped.source/extra/ You must add this gem to the source block for the source you wish it to be installed from. EOS expect(the_bundle).not_to be_locked diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index 1a33053dc6..9b53a1e9de 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "bundle install with specific platforms" do let(:google_protobuf) { <<-G } - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "google-protobuf" G @@ -33,7 +33,7 @@ RSpec.describe "bundle install with specific platforms" do # simulate lockfile created with old bundler, which only locks for ruby platform lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: google-protobuf (3.0.0.alpha.5.0.5.1) @@ -55,7 +55,7 @@ RSpec.describe "bundle install with specific platforms" do end end - it "understands that a non-platform specific gem in a new lockfile locked only to RUBY doesn't necessarily mean installing the non-specific variant" do + it "understands that a non-platform specific gem in a new lockfile locked only to ruby doesn't necessarily mean installing the non-specific variant" do simulate_platform "x86_64-darwin-15" do setup_multiplatform_gem @@ -73,7 +73,7 @@ RSpec.describe "bundle install with specific platforms" do # simulate lockfile created with old bundler, which only locks for ruby platform lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: google-protobuf (3.0.0.alpha.4.0) @@ -97,7 +97,7 @@ RSpec.describe "bundle install with specific platforms" do # make sure we're still only locked to ruby expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: google-protobuf (3.0.0.alpha.5.0.5.1) @@ -113,7 +113,7 @@ RSpec.describe "bundle install with specific platforms" do end end - context "when running on a legacy lockfile locked only to RUBY" do + context "when running on a legacy lockfile locked only to ruby" do around do |example| build_repo4 do build_gem "nokogiri", "1.3.10" @@ -124,14 +124,14 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.3.10) @@ -148,12 +148,12 @@ RSpec.describe "bundle install with specific platforms" do simulate_platform "arm64-darwin-22", &example end - it "still installs the generic RUBY variant if necessary" do + it "still installs the generic ruby variant if necessary" do bundle "install --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } expect(out).to include("Installing nokogiri 1.3.10") end - it "still installs the generic RUBY variant if necessary, even in frozen mode" do + it "still installs the generic ruby variant if necessary, even in frozen mode" do bundle "install --verbose", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s, "BUNDLE_FROZEN" => "true" } expect(out).to include("Installing nokogiri 1.3.10") end @@ -166,7 +166,7 @@ RSpec.describe "bundle install with specific platforms" do build_gem("libv8", "8.4.255.0") {|s| s.platform = "universal-darwin" } build_gem("mini_racer", "1.0.0") do |s| - s.add_runtime_dependency "libv8" + s.add_dependency "libv8" end end @@ -268,7 +268,7 @@ RSpec.describe "bundle install with specific platforms" do git = build_git "pg_array_parser", "1.0" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "pg_array_parser", :git => "#{lib_path("pg_array_parser-1.0")}" G @@ -304,7 +304,7 @@ RSpec.describe "bundle install with specific platforms" do simulate_platform "x86_64-darwin-15" do setup_multiplatform_gem_with_different_dependencies_per_platform install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "facter" G allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) @@ -358,14 +358,14 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "sorbet-static", "0.5.6403" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: sorbet-static (0.5.6403-#{Bundler.local_platform}) @@ -389,13 +389,13 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "sorbet-static", "0.5.6433" G error_message = <<~ERROR.strip - Could not find gem 'sorbet-static (= 0.5.6433)' with platform 'arm64-darwin-21' in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally. + Could not find gem 'sorbet-static (= 0.5.6433)' with platform 'arm64-darwin-21' in rubygems repository https://gem.repo4/ or installed locally. The source contains the following gems matching 'sorbet-static (= 0.5.6433)': * sorbet-static-0.5.6433-universal-darwin-20 @@ -425,7 +425,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "sorbet", "0.5.6433" G @@ -434,7 +434,7 @@ RSpec.describe "bundle install with specific platforms" do Could not find compatible versions Because every version of sorbet depends on sorbet-static = 0.5.6433 - and sorbet-static = 0.5.6433 could not be found in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally for any resolution platforms (arm64-darwin-21), + and sorbet-static = 0.5.6433 could not be found in rubygems repository https://gem.repo4/ or installed locally for any resolution platforms (arm64-darwin-21), sorbet cannot be used. So, because Gemfile depends on sorbet = 0.5.6433, version solving has failed. @@ -459,13 +459,13 @@ RSpec.describe "bundle install with specific platforms" do expect(err).to include(error_message).once end - it "does not generate a lockfile if RUBY platform is forced and some gem has no RUBY variant available" do + it "does not generate a lockfile if ruby platform is forced and some gem has no ruby variant available" do build_repo4 do build_gem("sorbet-static", "0.5.9889") {|s| s.platform = Gem::Platform.local } end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "sorbet-static", "0.5.9889" G @@ -473,22 +473,22 @@ RSpec.describe "bundle install with specific platforms" do bundle "lock", raise_on_error: false, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "true" } expect(err).to include <<~ERROR.rstrip - Could not find gem 'sorbet-static (= 0.5.9889)' with platform 'ruby' in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally. + Could not find gem 'sorbet-static (= 0.5.9889)' with platform 'ruby' in rubygems repository https://gem.repo4/ or installed locally. The source contains the following gems matching 'sorbet-static (= 0.5.9889)': * sorbet-static-0.5.9889-#{Gem::Platform.local} ERROR end - it "automatically fixes the lockfile if RUBY platform is locked and some gem has no RUBY variant available" do + it "automatically fixes the lockfile if ruby platform is locked and some gem has no ruby variant available" do build_repo4 do build_gem("sorbet-static-and-runtime", "0.5.10160") do |s| - s.add_runtime_dependency "sorbet", "= 0.5.10160" - s.add_runtime_dependency "sorbet-runtime", "= 0.5.10160" + s.add_dependency "sorbet", "= 0.5.10160" + s.add_dependency "sorbet-runtime", "= 0.5.10160" end build_gem("sorbet", "0.5.10160") do |s| - s.add_runtime_dependency "sorbet-static", "= 0.5.10160" + s.add_dependency "sorbet-static", "= 0.5.10160" end build_gem("sorbet-runtime", "0.5.10160") @@ -499,14 +499,14 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "sorbet-static-and-runtime" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet (0.5.10160) sorbet-static (= 0.5.10160) @@ -537,7 +537,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet (0.5.10160) sorbet-static (= 0.5.10160) @@ -558,7 +558,7 @@ RSpec.describe "bundle install with specific platforms" do L end - it "automatically fixes the lockfile if both RUBY platform and a more specific platform are locked, and some gem has no RUBY variant available" do + it "automatically fixes the lockfile if both ruby platform and a more specific platform are locked, and some gem has no ruby variant available" do build_repo4 do build_gem "nokogiri", "1.12.0" build_gem "nokogiri", "1.12.0" do |s| @@ -577,7 +577,7 @@ RSpec.describe "bundle install with specific platforms" do simulate_platform "x86_64-darwin-22" do install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" gem "sorbet-static" @@ -591,7 +591,7 @@ RSpec.describe "bundle install with specific platforms" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.12.0) nokogiri (1.12.0-x86_64-darwin) @@ -615,7 +615,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.13.0-x86_64-darwin) sorbet-static (0.5.10601-x86_64-darwin) @@ -632,15 +632,15 @@ RSpec.describe "bundle install with specific platforms" do L end - it "automatically fixes the lockfile if only RUBY platform is locked and some gem has no RUBY variant available" do + it "automatically fixes the lockfile if only ruby platform is locked and some gem has no ruby variant available" do build_repo4 do build_gem("sorbet-static-and-runtime", "0.5.10160") do |s| - s.add_runtime_dependency "sorbet", "= 0.5.10160" - s.add_runtime_dependency "sorbet-runtime", "= 0.5.10160" + s.add_dependency "sorbet", "= 0.5.10160" + s.add_dependency "sorbet-runtime", "= 0.5.10160" end build_gem("sorbet", "0.5.10160") do |s| - s.add_runtime_dependency "sorbet-static", "= 0.5.10160" + s.add_dependency "sorbet-static", "= 0.5.10160" end build_gem("sorbet-runtime", "0.5.10160") @@ -651,14 +651,14 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "sorbet-static-and-runtime" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet (0.5.10160) sorbet-static (= 0.5.10160) @@ -689,7 +689,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet (0.5.10160) sorbet-static (= 0.5.10160) @@ -726,7 +726,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" gem "sorbet-static" @@ -734,7 +734,7 @@ RSpec.describe "bundle install with specific platforms" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0-arm-linux) nokogiri (1.14.0-x86_64-linux) @@ -762,7 +762,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0-x86_64-linux) sorbet-static (0.5.10696-x86_64-linux) @@ -794,7 +794,7 @@ RSpec.describe "bundle install with specific platforms" do # Make sure sorbet-static-0.5.10549-universal-darwin-21 is installed install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "sorbet-static", "= 0.5.10549" G @@ -807,7 +807,7 @@ RSpec.describe "bundle install with specific platforms" do # Make sure the lockfile is missing sorbet-static-0.5.10549-universal-darwin-21 lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet-static (0.5.10549-universal-darwin-20) @@ -827,7 +827,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet-static (0.5.10549-universal-darwin-20) sorbet-static (0.5.10549-universal-darwin-21) @@ -844,6 +844,63 @@ RSpec.describe "bundle install with specific platforms" do end end + it "automatically fixes the lockfile if locked only to ruby, and some locked specs don't meed locked dependencies" do + simulate_platform "x86_64-linux" do + build_repo4 do + build_gem("ibandit", "0.7.0") do |s| + s.add_dependency "i18n", "~> 0.7.0" + end + + build_gem("i18n", "0.7.0.beta1") + build_gem("i18n", "0.7.0") + end + + gemfile <<~G + source "https://gem.repo4" + + gem "ibandit", "~> 0.7.0" + G + + lockfile <<~L + GEM + remote: https://gem.repo4/ + specs: + i18n (0.7.0.beta1) + ibandit (0.7.0) + i18n (~> 0.7.0) + + PLATFORMS + ruby + + DEPENDENCIES + ibandit (~> 0.7.0) + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "lock --update i18n" + + expect(lockfile).to eq <<~L + GEM + remote: https://gem.repo4/ + specs: + i18n (0.7.0) + ibandit (0.7.0) + i18n (~> 0.7.0) + + PLATFORMS + ruby + + DEPENDENCIES + ibandit (~> 0.7.0) + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + it "does not remove ruby if gems for other platforms, and not present in the lockfile, exist in the Gemfile" do build_repo4 do build_gem "nokogiri", "1.13.8" @@ -853,16 +910,21 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" gem "tzinfo", "~> 1.2", platform: :#{not_local_tag} G + checksums = checksums_section_when_existing do |c| + c.checksum gem_repo4, "nokogiri", "1.13.8" + c.checksum gem_repo4, "nokogiri", "1.13.8", Gem::Platform.local + end + original_lockfile = <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.13.8) nokogiri (1.13.8-#{Gem::Platform.local}) @@ -873,9 +935,7 @@ RSpec.describe "bundle install with specific platforms" do DEPENDENCIES nokogiri tzinfo (~> 1.2) - - CHECKSUMS - + #{checksums} BUNDLED WITH #{Bundler::VERSION} L @@ -884,20 +944,38 @@ RSpec.describe "bundle install with specific platforms" do bundle "lock --update" + expect(lockfile).to eq(original_lockfile) + end + + it "does not remove ruby if gems for other platforms, and not present in the lockfile, exist in the Gemfile, and the lockfile only has ruby" do + build_repo4 do + build_gem "nokogiri", "1.13.8" + build_gem "nokogiri", "1.13.8" do |s| + s.platform = "arm64-darwin" + end + end + + gemfile <<~G + source "https://gem.repo4" + + gem "nokogiri" + + gem "tzinfo", "~> 1.2", platforms: %i[mingw mswin x64_mingw jruby] + G + checksums = checksums_section_when_existing do |c| - c.no_checksum "nokogiri", "1.13.8" - c.no_checksum "nokogiri", "1.13.8", Gem::Platform.local + c.checksum gem_repo4, "nokogiri", "1.13.8" + c.checksum gem_repo4, "nokogiri", "1.13.8", "arm64-darwin" end - updated_lockfile = <<~L + original_lockfile = <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.13.8) - nokogiri (1.13.8-#{Gem::Platform.local}) PLATFORMS - #{lockfile_platforms("ruby")} + ruby DEPENDENCIES nokogiri @@ -907,30 +985,36 @@ RSpec.describe "bundle install with specific platforms" do #{Bundler::VERSION} L - expect(lockfile).to eq(updated_lockfile) + lockfile original_lockfile + + simulate_platform "arm64-darwin-23" do + bundle "lock --update" + end + + expect(lockfile).to eq(original_lockfile) end it "does not remove ruby when adding a new gem to the Gemfile" do build_repo4 do build_gem "concurrent-ruby", "1.2.2" - build_gem "rack", "3.0.7" + build_gem "myrack", "3.0.7" end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "concurrent-ruby" - gem "rack" + gem "myrack" G checksums = checksums_section_when_existing do |c| c.no_checksum "concurrent-ruby", "1.2.2" - c.no_checksum "rack", "3.0.7" + c.no_checksum "myrack", "3.0.7" end lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: concurrent-ruby (1.2.2) @@ -948,17 +1032,17 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: concurrent-ruby (1.2.2) - rack (3.0.7) + myrack (3.0.7) PLATFORMS #{lockfile_platforms("ruby", generic_local_platform, defaults: [])} DEPENDENCIES concurrent-ruby - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -968,10 +1052,8 @@ RSpec.describe "bundle install with specific platforms" do it "can fallback to a source gem when platform gems are incompatible with current ruby version" do setup_multiplatform_gem_with_source_gem - source = file_uri_for(gem_repo2) - gemfile <<~G - source "#{source}" + source "https://gem.repo2" gem "my-precompiled-gem" G @@ -981,7 +1063,7 @@ RSpec.describe "bundle install with specific platforms" do # - A source gem with compatible ruby version lockfile <<-L GEM - remote: #{source}/ + remote: https://gem.repo2/ specs: my-precompiled-gem (3.0.0) my-precompiled-gem (3.0.0-#{Bundler.local_platform}) @@ -1017,7 +1099,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri", "1.14.0" G @@ -1028,7 +1110,7 @@ RSpec.describe "bundle install with specific platforms" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0-x86_64-linux) @@ -1050,7 +1132,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0) @@ -1066,6 +1148,60 @@ RSpec.describe "bundle install with specific platforms" do end end + it "automatically fixes the lockfile when only ruby platform locked, and adding a dependency with subdependencies not valid for ruby" do + simulate_platform "x86_64-linux" do + build_repo4 do + build_gem("sorbet", "0.5.10160") do |s| + s.add_dependency "sorbet-static", "= 0.5.10160" + end + + build_gem("sorbet-static", "0.5.10160") do |s| + s.platform = "x86_64-linux" + end + end + + gemfile <<~G + source "https://gem.repo4" + + gem "sorbet" + G + + lockfile <<~L + GEM + remote: https://gem.repo4/ + specs: + + PLATFORMS + ruby + + DEPENDENCIES + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "lock" + + expect(lockfile).to eq <<~L + GEM + remote: https://gem.repo4/ + specs: + sorbet (0.5.10160) + sorbet-static (= 0.5.10160) + sorbet-static (0.5.10160-x86_64-linux) + + PLATFORMS + x86_64-linux + + DEPENDENCIES + sorbet + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + it "locks specific platforms automatically" do simulate_platform "x86_64-linux" do build_repo4 do @@ -1092,7 +1228,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" G @@ -1108,7 +1244,7 @@ RSpec.describe "bundle install with specific platforms" do # locks all compatible platforms, excluding Java and Windows expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0) nokogiri (1.14.0-arm-linux) @@ -1127,7 +1263,7 @@ RSpec.describe "bundle install with specific platforms" do L gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" gem "sorbet-static" @@ -1144,7 +1280,7 @@ RSpec.describe "bundle install with specific platforms" do # locks only platforms compatible with all gems in the bundle expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0) nokogiri (1.14.0-x86_64-linux) @@ -1182,7 +1318,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" gem "sass-embedded" @@ -1200,7 +1336,7 @@ RSpec.describe "bundle install with specific platforms" do # locks all compatible platforms, excluding Java and Windows expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.15.5) sass-embedded (1.69.5) @@ -1232,7 +1368,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" G @@ -1246,7 +1382,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.15.5-x86_64-linux) @@ -1276,7 +1412,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rcee_precompiled", "0.5.0" G @@ -1286,7 +1422,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: rcee_precompiled (0.5.0-x86_64-linux) rcee_precompiled (0.5.0-x86_64-linux-musl) @@ -1318,7 +1454,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rcee_precompiled", "0.5.0" G @@ -1328,7 +1464,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: rcee_precompiled (0.5.0-x86_64-linux-gnu) rcee_precompiled (0.5.0-x86_64-linux-musl) @@ -1354,7 +1490,7 @@ RSpec.describe "bundle install with specific platforms" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "rcee_precompiled", "0.5.0" G @@ -1364,7 +1500,7 @@ RSpec.describe "bundle install with specific platforms" do expect(lockfile).to eq(<<~L) GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: rcee_precompiled (0.5.0-universal-darwin) @@ -1380,6 +1516,136 @@ RSpec.describe "bundle install with specific platforms" do end end + it "does not re-resolve when a specific platform, but less specific than the current platform, is locked" do + build_repo4 do + build_gem "nokogiri" + end + + gemfile <<~G + source "https://gem.repo4" + + gem "nokogiri" + G + + lockfile <<~L + GEM + remote: https://gem.repo4/ + specs: + nokogiri (1.0) + + PLATFORMS + arm64-darwin + + DEPENDENCIES + nokogiri! + + BUNDLED WITH + #{Bundler::VERSION} + L + + simulate_platform "arm64-darwin-23" do + bundle "install --verbose" + + expect(out).to include("Found no changes, using resolution from the lockfile") + end + end + + it "does not remove generic platform gems locked for a specific platform from lockfile when unlocking an unrelated gem" do + build_repo4 do + build_gem "ffi" + + build_gem "ffi" do |s| + s.platform = "x86_64-linux" + end + + build_gem "nokogiri" + end + + gemfile <<~G + source "https://gem.repo4" + + gem "ffi" + gem "nokogiri" + G + + original_lockfile = <<~L + GEM + remote: https://gem.repo4/ + specs: + ffi (1.0) + nokogiri (1.0) + + PLATFORMS + x86_64-linux + + DEPENDENCIES + ffi + nokogiri + + BUNDLED WITH + #{Bundler::VERSION} + L + + lockfile original_lockfile + + simulate_platform "x86_64-linux" do + bundle "lock --update nokogiri" + + expect(lockfile).to eq(original_lockfile) + end + end + + it "does not remove generic platform gems locked for a specific platform from lockfile when unlocking an unrelated gem, and variants for other platform also locked" do + build_repo4 do + build_gem "ffi" + + build_gem "ffi" do |s| + s.platform = "x86_64-linux" + end + + build_gem "ffi" do |s| + s.platform = "java" + end + + build_gem "nokogiri" + end + + gemfile <<~G + source "https://gem.repo4" + + gem "ffi" + gem "nokogiri" + G + + original_lockfile = <<~L + GEM + remote: https://gem.repo4/ + specs: + ffi (1.0) + ffi (1.0-java) + nokogiri (1.0) + + PLATFORMS + java + x86_64-linux + + DEPENDENCIES + ffi + nokogiri + + BUNDLED WITH + #{Bundler::VERSION} + L + + lockfile original_lockfile + + simulate_platform "x86_64-linux" do + bundle "lock --update nokogiri" + + expect(lockfile).to eq(original_lockfile) + end + end + private def setup_multiplatform_gem @@ -1405,7 +1671,7 @@ RSpec.describe "bundle install with specific platforms" do build_gem("facter", "2.4.6") build_gem("facter", "2.4.6") do |s| s.platform = "universal-darwin" - s.add_runtime_dependency "CFPropertyList" + s.add_dependency "CFPropertyList" end build_gem("CFPropertyList") end diff --git a/spec/bundler/install/gemfile_spec.rb b/spec/bundler/install/gemfile_spec.rb index 158645d3eb..0539733d5d 100644 --- a/spec/bundler/install/gemfile_spec.rb +++ b/spec/bundler/install/gemfile_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle install" do context "with duplicated gems" do it "will display a warning" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'rails', '~> 4.0.0' gem 'rails', '~> 4.0.0' @@ -16,8 +16,8 @@ RSpec.describe "bundle install" do context "with --gemfile" do it "finds the gemfile" do gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle :install, gemfile: bundled_app("NotGemfile") @@ -25,15 +25,15 @@ RSpec.describe "bundle install" do # Specify BUNDLE_GEMFILE for `the_bundle` # to retrieve the proper Gemfile ENV["BUNDLE_GEMFILE"] = "NotGemfile" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end context "with gemfile set via config" do before do gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle "config set --local gemfile #{bundled_app("NotGemfile")}" @@ -42,34 +42,34 @@ RSpec.describe "bundle install" do bundle "install" bundle "list" - expect(out).to include("rack (1.0.0)") + expect(out).to include("myrack (1.0.0)") end it "uses the gemfile while in a subdirectory" do bundled_app("subdir").mkpath bundle "install", dir: bundled_app("subdir") bundle "list", dir: bundled_app("subdir") - expect(out).to include("rack (1.0.0)") + expect(out).to include("myrack (1.0.0)") end end context "with deprecated features" do it "reports that lib is an invalid option" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack", :lib => "rack" + gem "myrack", :lib => "myrack" G bundle :install, raise_on_error: false - expect(err).to match(/You passed :lib as an option for gem 'rack', but it is invalid/) + expect(err).to match(/You passed :lib as an option for gem 'myrack', but it is invalid/) end end context "with engine specified in symbol", :jruby_only do it "does not raise any error parsing Gemfile" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "#{RUBY_VERSION}", :engine => :jruby, :engine_version => "#{RUBY_ENGINE_VERSION}" G @@ -78,19 +78,19 @@ RSpec.describe "bundle install" do it "installation succeeds" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" ruby "#{RUBY_VERSION}", :engine => :jruby, :engine_version => "#{RUBY_ENGINE_VERSION}" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end context "with a Gemfile containing non-US-ASCII characters" do it "reads the Gemfile with the UTF-8 encoding by default" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" str = "Il était une fois ..." puts "The source encoding is: " + str.encoding.name @@ -105,7 +105,7 @@ RSpec.describe "bundle install" do # NOTE: This works thanks to #eval interpreting the magic encoding comment install_gemfile <<-G # encoding: iso-8859-1 - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" str = "Il #{"\xE9".dup.force_encoding("binary")}tait une fois ..." puts "The source encoding is: " + str.encoding.name diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index 50add8743b..39064e3b80 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -7,12 +7,27 @@ RSpec.describe "compact index api" do it "should use the API" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" + end + + it "has a debug mode" do + gemfile <<-G + source "#{source_uri}" + gem "myrack" + G + + bundle :install, artifice: "compact_index", env: { "DEBUG_COMPACT_INDEX" => "true" } + expect(out).to include("Fetching gem metadata from #{source_uri}") + expect(err).to include("[Bundler::CompactIndexClient] available?") + expect(err).to include("[Bundler::CompactIndexClient] fetching versions") + expect(err).to include("[Bundler::CompactIndexClient] info(myrack)") + expect(err).to include("[Bundler::CompactIndexClient] fetching info/myrack") + expect(the_bundle).to include_gems "myrack 1.0.0" end it "should URI encode gem names" do @@ -45,22 +60,22 @@ RSpec.describe "compact index api" do it "should handle case sensitivity conflicts" do build_repo4(build_compact_index: false) do - build_gem "rack", "1.0" do |s| - s.add_runtime_dependency("Rack", "0.1") + build_gem "myrack", "1.0" do |s| + s.add_dependency("Myrack", "0.1") end - build_gem "Rack", "0.1" + build_gem "Myrack", "0.1" end install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem "rack", "1.0" - gem "Rack", "0.1" + gem "myrack", "1.0" + gem "Myrack", "0.1" G # can't use `include_gems` here since the `require` will conflict on a # case-insensitive FS - run "Bundler.require; puts Gem.loaded_specs.values_at('rack', 'Rack').map(&:full_name)" - expect(out).to eq("rack-1.0\nRack-0.1") + run "Bundler.require; puts Gem.loaded_specs.values_at('myrack', 'Myrack').map(&:full_name)" + expect(out).to eq("myrack-1.0\nMyrack-0.1") end it "should handle multiple gem dependencies on the same gem" do @@ -76,7 +91,7 @@ RSpec.describe "compact index api" do it "should use the endpoint when using deployment mode" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index" @@ -84,7 +99,7 @@ RSpec.describe "compact index api" do bundle "config set --local path vendor/bundle" bundle :install, artifice: "compact_index" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "handles git dependencies that are in rubygems" do @@ -95,7 +110,7 @@ RSpec.describe "compact index api" do gemfile <<-G source "#{source_uri}" - git "#{file_uri_for(lib_path("foo-1.0"))}" do + git "#{lib_path("foo-1.0")}" do gem 'foo' end G @@ -113,7 +128,7 @@ RSpec.describe "compact index api" do gemfile <<-G source "#{source_uri}" - gem 'foo', :git => "#{file_uri_for(lib_path("foo-1.0"))}" + gem 'foo', :git => "#{lib_path("foo-1.0")}" G bundle :install, artifice: "compact_index" @@ -128,7 +143,7 @@ RSpec.describe "compact index api" do build_git "foo" gemfile <<-G source "#{source_uri}" - gem 'foo', :git => "#{file_uri_for(lib_path("foo-1.0"))}" + gem 'foo', :git => "#{lib_path("foo-1.0")}" G bundle "install", artifice: "compact_index" @@ -141,31 +156,31 @@ RSpec.describe "compact index api" do it "falls back when the API URL returns 403 Forbidden" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, verbose: true, artifice: "compact_index_forbidden" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "falls back when the versions endpoint has a checksum mismatch" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, verbose: true, artifice: "compact_index_checksum_mismatch" expect(out).to include("Fetching gem metadata from #{source_uri}") expect(out).to include("The checksum of /versions does not match the checksum provided by the server!") expect(out).to include('Calculated checksums {"sha-256"=>"8KfZiM/fszVkqhP/m5s9lvE6M9xKu4I1bU4Izddp5Ms="} did not match expected {"sha-256"=>"ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="}') - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "shows proper path when permission errors happen", :permissions do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G versions = Pathname.new(Bundler.rubygems.user_home).join( @@ -188,28 +203,28 @@ RSpec.describe "compact index api" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "handles host redirects" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index_host_redirect" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "handles host redirects without Gem::Net::HTTP::Persistent" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G FileUtils.mkdir_p lib_path @@ -227,13 +242,13 @@ RSpec.describe "compact index api" do bundle :install, artifice: "compact_index_host_redirect", requires: [lib_path("disable_net_http_persistent.rb")] expect(out).to_not match(/Too many redirects/) - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "times out when Bundler::Fetcher redirects too much" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index_redirects", raise_on_error: false @@ -244,23 +259,23 @@ RSpec.describe "compact index api" do it "should use the modern index for install" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --full-index", artifice: "compact_index" expect(out).to include("Fetching source index from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "should use the modern index for update" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "update --full-index", artifice: "compact_index", all: true expect(out).to include("Fetching source index from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end @@ -288,16 +303,16 @@ RSpec.describe "compact index api" do end end - system_gems %w[rack-1.0.0 thin-1.0 net_a-1.0], gem_repo: gem_repo2 + system_gems %w[myrack-1.0.0 thin-1.0 net_a-1.0], gem_repo: gem_repo2 bundle "config set --local path.system true" ENV["BUNDLER_SPEC_ALL_REQUESTS"] = <<~EOS.strip #{source_uri}/versions - #{source_uri}/info/rack + #{source_uri}/info/myrack EOS install_gemfile <<-G, artifice: "compact_index", verbose: true, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } source "#{source_uri}" - gem "rack" + gem "myrack" G expect(last_command.stdboth).not_to include "Double checking" @@ -342,24 +357,24 @@ RSpec.describe "compact index api" do it "fetches gem versions even when those gems are already installed" do gemfile <<-G source "#{source_uri}" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G bundle :install, artifice: "compact_index_extra_api" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" build_repo4 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end gemfile <<-G source "#{source_uri}" do; end source "#{source_uri}/extra" - gem "rack", "1.2" + gem "myrack", "1.2" G bundle :install, artifice: "compact_index_extra_api" - expect(the_bundle).to include_gems "rack 1.2" + expect(the_bundle).to include_gems "myrack 1.2" end it "considers all possible versions of dependencies from all api gem sources", bundler: "< 3" do @@ -519,56 +534,56 @@ RSpec.describe "compact index api" do it "installs the binstubs", bundler: "< 3" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --binstubs", artifice: "compact_index" - gembin "rackup" + gembin "myrackup" expect(out).to eq("1.0.0") end it "installs the bins when using --path and uses autoclean", bundler: "< 3" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --path vendor/bundle", artifice: "compact_index" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "installs the bins when using --path and uses bundle clean", bundler: "< 3" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --path vendor/bundle --no-clean", artifice: "compact_index" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "prints post_install_messages" do gemfile <<-G source "#{source_uri}" - gem 'rack-obama' + gem 'myrack-obama' G bundle :install, artifice: "compact_index" - expect(out).to include("Post-install message from rack:") + expect(out).to include("Post-install message from myrack:") end it "should display the post install message for a dependency" do gemfile <<-G source "#{source_uri}" - gem 'rack_middleware' + gem 'myrack_middleware' G bundle :install, artifice: "compact_index" - expect(out).to include("Post-install message from rack:") - expect(out).to include("Rack's post install message") + expect(out).to include("Post-install message from myrack:") + expect(out).to include("Myrack's post install message") end context "when using basic authentication" do @@ -585,53 +600,53 @@ RSpec.describe "compact index api" do it "passes basic authentication details and strips out creds" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index_basic_authentication" expect(out).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "passes basic authentication details and strips out creds also in verbose mode" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, verbose: true, artifice: "compact_index_basic_authentication" expect(out).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "strips http basic auth creds when warning about ambiguous sources", bundler: "< 3" do gemfile <<-G source "#{basic_auth_source_uri}" source "#{file_uri_for(gem_repo1)}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index_basic_authentication" - expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include("Warning: the gem 'myrack' was found in multiple sources.") expect(err).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does not pass the user / password to different hosts on redirect" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index_creds_diff_host" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end describe "with authentication details in bundle config" do before do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G end @@ -641,7 +656,7 @@ RSpec.describe "compact index api" do bundle :install, artifice: "compact_index_strict_basic_authentication" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "reads authentication details by full url from bundle config" do @@ -651,26 +666,26 @@ RSpec.describe "compact index api" do bundle :install, artifice: "compact_index_strict_basic_authentication" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "should use the API" do bundle "config set #{source_hostname} #{user}:#{password}" bundle :install, artifice: "compact_index_strict_basic_authentication" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "prefers auth supplied in the source uri" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle "config set #{source_hostname} otheruser:wrong" bundle :install, artifice: "compact_index_strict_basic_authentication" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "shows instructions if auth is not provided for the source" do @@ -701,11 +716,11 @@ RSpec.describe "compact index api" do it "passes basic authentication details" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index_basic_authentication" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end end @@ -726,10 +741,10 @@ RSpec.describe "compact index api" do it "explains what to do to get it" do gemfile <<-G source "#{source_uri.gsub(/http/, "https")}" - gem "rack" + gem "myrack" G - bundle :install, env: { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) }, raise_on_error: false + bundle :install, env: { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) }, raise_on_error: false, artifice: nil expect(err).to include("OpenSSL") end end @@ -746,7 +761,7 @@ RSpec.describe "compact index api" do end source "#{source_uri.gsub(/http/, "https")}" - gem "rack" + gem "myrack" G bundle :install, raise_on_error: false @@ -763,7 +778,7 @@ RSpec.describe "compact index api" do begin gemfile <<-G source "#{source_uri}" - gem 'rack' + gem 'myrack' G bundle :install, artifice: "compact_index_forbidden" @@ -782,7 +797,7 @@ RSpec.describe "compact index api" do gemfile <<-G source "#{source_uri}" - gem 'rack', '0.9.1' + gem 'myrack', '0.9.1' G # Initial install creates the cached versions file and etag file @@ -794,20 +809,20 @@ RSpec.describe "compact index api" do # Update the Gemfile so we can check subsequent install was successful gemfile <<-G source "#{source_uri}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G # Second install should match etag bundle :install, artifice: "compact_index_etag_match" expect(versions_etag.binread).to eq(previous_content) - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "performs full update when range is ignored" do gemfile <<-G source "#{source_uri}" - gem 'rack', '0.9.1' + gem 'myrack', '0.9.1' G # Initial install creates the cached versions file and etag file @@ -815,7 +830,7 @@ RSpec.describe "compact index api" do gemfile <<-G source "#{source_uri}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G versions = Pathname.new(Bundler.rubygems.user_home).join( @@ -828,36 +843,36 @@ RSpec.describe "compact index api" do bundle :install, artifice: "compact_index_range_ignored" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "performs partial update with a non-empty range" do build_repo4 do - build_gem "rack", "0.9.1" + build_gem "myrack", "0.9.1" end # Initial install creates the cached versions file install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem 'rack', '0.9.1' + gem 'myrack', '0.9.1' G update_repo4 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end install_gemfile <<-G, artifice: "compact_index_partial_update", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "performs partial update while local cache is updated by another process" do gemfile <<-G source "#{source_uri}" - gem 'rack' + gem 'myrack' G # Create a partial cache versions file @@ -871,92 +886,92 @@ RSpec.describe "compact index api" do bundle :install, artifice: "compact_index_concurrent_download" expect(versions.read).to start_with("created_at") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "performs a partial update that fails digest check, then a full update" do build_repo4 do - build_gem "rack", "0.9.1" + build_gem "myrack", "0.9.1" end install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem 'rack', '0.9.1' + gem 'myrack', '0.9.1' G update_repo4 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end install_gemfile <<-G, artifice: "compact_index_partial_update_bad_digest", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "performs full update if server endpoints serve partial content responses but don't have incremental content and provide no digest" do build_repo4 do - build_gem "rack", "0.9.1" + build_gem "myrack", "0.9.1" end install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem 'rack', '0.9.1' + gem 'myrack', '0.9.1' G update_repo4 do - build_gem "rack", "1.0.0" + build_gem "myrack", "1.0.0" end install_gemfile <<-G, artifice: "compact_index_partial_update_no_digest_not_incremental", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } source "#{source_uri}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "performs full update of compact index info cache if range is not satisfiable" do gemfile <<-G source "#{source_uri}" - gem 'rack', '0.9.1' + gem 'myrack', '0.9.1' G bundle :install, artifice: "compact_index" + cache_path = File.join(Bundler.rubygems.user_home, ".bundle", "cache", "compact_index", "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5") + # We must remove the etag so that we don't ignore the range and get a 304 Not Modified. - rake_info_etag_path = File.join(Bundler.rubygems.user_home, ".bundle", "cache", "compact_index", - "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "info-etags", "rack-11690b09f16021ff06a6857d784a1870") - File.unlink(rake_info_etag_path) if File.exist?(rake_info_etag_path) + myrack_info_etag_path = File.join(cache_path, "info-etags", "myrack-92f3313ce5721296f14445c3a6b9c073") + File.unlink(myrack_info_etag_path) if File.exist?(myrack_info_etag_path) - rake_info_path = File.join(Bundler.rubygems.user_home, ".bundle", "cache", "compact_index", - "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "info", "rack") - expected_rack_info_content = File.read(rake_info_path) + myrack_info_path = File.join(cache_path, "info", "myrack") + expected_myrack_info_content = File.read(myrack_info_path) # Modify the cache files to make the range not satisfiable - File.open(rake_info_path, "a") {|f| f << "0.9.2 |checksum:c55b525b421fd833a93171ad3d7f04528ca8e87d99ac273f8933038942a5888c" } + File.open(myrack_info_path, "a") {|f| f << "0.9.2 |checksum:c55b525b421fd833a93171ad3d7f04528ca8e87d99ac273f8933038942a5888c" } # Update the Gemfile so the next install does its normal things gemfile <<-G source "#{source_uri}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G # The cache files now being longer means the requested range is going to be not satisfiable # Bundler must end up requesting the whole file to fix things up. bundle :install, artifice: "compact_index_range_not_satisfiable" - resulting_rack_info_content = File.read(rake_info_path) + resulting_myrack_info_content = File.read(myrack_info_path) - expect(resulting_rack_info_content).to eq(expected_rack_info_content) + expect(resulting_myrack_info_content).to eq(expected_myrack_info_content) end it "fails gracefully when the source URI has an invalid scheme" do install_gemfile <<-G, raise_on_error: false source "htps://rubygems.org" - gem "rack" + gem "myrack" G expect(exitstatus).to eq(15) expect(err).to end_with(<<-E.strip) @@ -970,7 +985,7 @@ RSpec.describe "compact index api" do GEM remote: #{source_uri} specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS ruby @@ -983,35 +998,35 @@ RSpec.describe "compact index api" do end it "handles checksums from the server in base64" do - api_checksum = checksum_digest(gem_repo1, "rack", "1.0.0") - rack_checksum = [[api_checksum].pack("H*")].pack("m0") - install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_RACK_CHECKSUM" => rack_checksum } + api_checksum = checksum_digest(gem_repo1, "myrack", "1.0.0") + myrack_checksum = [[api_checksum].pack("H*")].pack("m0") + install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_MYRACK_CHECKSUM" => myrack_checksum } source "#{source_uri}" - gem "rack" + gem "myrack" G expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") end it "raises when the checksum does not match" do install_gemfile <<-G, artifice: "compact_index_wrong_gem_checksum", raise_on_error: false source "#{source_uri}" - gem "rack" + gem "myrack" G gem_path = if Bundler.feature_flag.global_gem_cache? - default_cache_path.dirname.join("cache", "gems", "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "rack-1.0.0.gem") + default_cache_path.dirname.join("cache", "gems", "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "myrack-1.0.0.gem") else - default_cache_path.dirname.join("rack-1.0.0.gem") + default_cache_path.dirname.join("myrack-1.0.0.gem") end expect(exitstatus).to eq(37) expect(err).to eq <<~E.strip Bundler found mismatched checksums. This is a potential security risk. - rack (1.0.0) sha256=2222222222222222222222222222222222222222222222222222222222222222 + myrack (1.0.0) sha256=2222222222222222222222222222222222222222222222222222222222222222 from the API at http://localgemserver.test/ - #{checksum_to_lock(gem_repo1, "rack", "1.0.0")} + #{checksum_to_lock(gem_repo1, "myrack", "1.0.0")} from the gem at #{gem_path} If you trust the API at http://localgemserver.test/, to resolve this issue you can: @@ -1024,19 +1039,19 @@ RSpec.describe "compact index api" do end it "raises when the checksum is the wrong length" do - install_gemfile <<-G, artifice: "compact_index_wrong_gem_checksum", env: { "BUNDLER_SPEC_RACK_CHECKSUM" => "checksum!", "DEBUG" => "1" }, verbose: true, raise_on_error: false + install_gemfile <<-G, artifice: "compact_index_wrong_gem_checksum", env: { "BUNDLER_SPEC_MYRACK_CHECKSUM" => "checksum!", "DEBUG" => "1" }, verbose: true, raise_on_error: false source "#{source_uri}" - gem "rack" + gem "myrack" G expect(exitstatus).to eq(14) - expect(err).to include('Invalid checksum for rack-0.9.1: "checksum!" is not a valid SHA256 hex or base64 digest') + expect(err).to include('Invalid checksum for myrack-0.9.1: "checksum!" is not a valid SHA256 hex or base64 digest') end it "does not raise when disable_checksum_validation is set" do bundle "config set disable_checksum_validation true" install_gemfile <<-G, artifice: "compact_index_wrong_gem_checksum" source "#{source_uri}" - gem "rack" + gem "myrack" G end end @@ -1045,7 +1060,7 @@ RSpec.describe "compact index api" do install_gemfile <<-G, artifice: "compact_index" File.umask(0000) source "#{source_uri}" - gem "rack" + gem "myrack" G end @@ -1068,7 +1083,7 @@ Running `bundle update rails` should fix the problem. it "does not duplicate specs in the lockfile when updating and a dependency is not installed" do install_gemfile <<-G, artifice: "compact_index" - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" source "#{source_uri}" do gem "rails" gem "activemerchant" diff --git a/spec/bundler/realworld/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_fallback_spec.rb index ee5c0e3d0a..56a71f252b 100644 --- a/spec/bundler/realworld/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_fallback_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative "../support/silent_logger" +require_relative "../../support/silent_logger" -RSpec.describe "gemcutter's dependency API", realworld: true do +RSpec.describe "gemcutter's dependency API" do context "when Gemcutter API takes too long to respond" do before do require_rack @@ -10,7 +10,7 @@ RSpec.describe "gemcutter's dependency API", realworld: true do port = find_unused_port @server_uri = "http://127.0.0.1:#{port}" - require_relative "../support/artifice/endpoint_timeout" + require_relative "../../support/artifice/endpoint_timeout" @t = Thread.new do server = Rack::Server.start(app: EndpointTimeout, @@ -34,13 +34,13 @@ RSpec.describe "gemcutter's dependency API", realworld: true do end it "times out and falls back on the modern index" do - install_gemfile <<-G, artifice: nil + install_gemfile <<-G, artifice: nil, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } source "#{@server_uri}" - gem "rack" + gem "myrack" G expect(out).to include("Fetching source index from #{@server_uri}/") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end end diff --git a/spec/bundler/install/gems/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_spec.rb index 35468b3a1c..f3c1d9dc60 100644 --- a/spec/bundler/install/gems/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_spec.rb @@ -7,12 +7,12 @@ RSpec.describe "gemcutter's dependency API" do it "should use the API" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "should URI encode gem names" do @@ -56,7 +56,7 @@ RSpec.describe "gemcutter's dependency API" do it "should use the endpoint when using deployment mode" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint" @@ -64,7 +64,7 @@ RSpec.describe "gemcutter's dependency API" do bundle "config set --local path vendor/bundle" bundle :install, artifice: "endpoint" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "handles git dependencies that are in rubygems" do @@ -75,7 +75,7 @@ RSpec.describe "gemcutter's dependency API" do gemfile <<-G source "#{source_uri}" - git "#{file_uri_for(lib_path("foo-1.0"))}" do + git "#{lib_path("foo-1.0")}" do gem 'foo' end G @@ -93,7 +93,7 @@ RSpec.describe "gemcutter's dependency API" do gemfile <<-G source "#{source_uri}" - gem 'foo', :git => "#{file_uri_for(lib_path("foo-1.0"))}" + gem 'foo', :git => "#{lib_path("foo-1.0")}" G bundle :install, artifice: "endpoint" @@ -108,7 +108,7 @@ RSpec.describe "gemcutter's dependency API" do build_git "foo" gemfile <<-G source "#{source_uri}" - gem 'foo', :git => "#{file_uri_for(lib_path("foo-1.0"))}" + gem 'foo', :git => "#{lib_path("foo-1.0")}" G bundle "install", artifice: "endpoint" @@ -147,7 +147,7 @@ RSpec.describe "gemcutter's dependency API" do gem "actionmailer" gem "activeresource" gem "thin" - gem "rack" + gem "myrack" gem "rails" G bundle :install, artifice: "endpoint_fallback" @@ -160,7 +160,7 @@ RSpec.describe "gemcutter's dependency API" do "activeresource 2.3.2", "activesupport 2.3.2", "thin 1.0.0", - "rack 1.0.0", + "myrack 1.0.0", "rails 2.3.2" ) end @@ -168,39 +168,39 @@ RSpec.describe "gemcutter's dependency API" do it "falls back when Gemcutter API doesn't return proper Marshal format" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, verbose: true, artifice: "endpoint_marshal_fail" expect(out).to include("could not fetch from the dependency API, trying the full index") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "falls back when the API URL returns 403 Forbidden" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, verbose: true, artifice: "endpoint_api_forbidden" expect(out).to include("Fetching source index from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "handles host redirects" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_host_redirect" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "handles host redirects without Gem::Net::HTTP::Persistent" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G FileUtils.mkdir_p lib_path @@ -218,13 +218,13 @@ RSpec.describe "gemcutter's dependency API" do bundle :install, artifice: "endpoint_host_redirect", requires: [lib_path("disable_net_http_persistent.rb")] expect(out).to_not match(/Too many redirects/) - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "timeouts when Bundler::Fetcher redirects too much" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_redirect", raise_on_error: false @@ -235,23 +235,23 @@ RSpec.describe "gemcutter's dependency API" do it "should use the modern index for install" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --full-index", artifice: "endpoint" expect(out).to include("Fetching source index from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "should use the modern index for update" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "update --full-index", artifice: "endpoint", all: true expect(out).to include("Fetching source index from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end @@ -295,23 +295,23 @@ RSpec.describe "gemcutter's dependency API" do it "fetches gem versions even when those gems are already installed" do gemfile <<-G source "#{source_uri}" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G bundle :install, artifice: "endpoint_extra_api" build_repo4 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end gemfile <<-G source "#{source_uri}" do; end source "#{source_uri}/extra" - gem "rack", "1.2" + gem "myrack", "1.2" G bundle :install, artifice: "endpoint_extra_api" - expect(the_bundle).to include_gems "rack 1.2" + expect(the_bundle).to include_gems "myrack 1.2" end it "considers all possible versions of dependencies from all api gem sources", bundler: "< 3" do @@ -475,56 +475,56 @@ RSpec.describe "gemcutter's dependency API" do it "installs the binstubs", bundler: "< 3" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --binstubs", artifice: "endpoint" - gembin "rackup" + gembin "myrackup" expect(out).to eq("1.0.0") end it "installs the bins when using --path and uses autoclean", bundler: "< 3" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --path vendor/bundle", artifice: "endpoint" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "installs the bins when using --path and uses bundle clean", bundler: "< 3" do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G bundle "install --path vendor/bundle --no-clean", artifice: "endpoint" - expect(vendored_gems("bin/rackup")).to exist + expect(vendored_gems("bin/myrackup")).to exist end it "prints post_install_messages" do gemfile <<-G source "#{source_uri}" - gem 'rack-obama' + gem 'myrack-obama' G bundle :install, artifice: "endpoint" - expect(out).to include("Post-install message from rack:") + expect(out).to include("Post-install message from myrack:") end it "should display the post install message for a dependency" do gemfile <<-G source "#{source_uri}" - gem 'rack_middleware' + gem 'myrack_middleware' G bundle :install, artifice: "endpoint" - expect(out).to include("Post-install message from rack:") - expect(out).to include("Rack's post install message") + expect(out).to include("Post-install message from myrack:") + expect(out).to include("Myrack's post install message") end context "when using basic authentication" do @@ -541,40 +541,40 @@ RSpec.describe "gemcutter's dependency API" do it "passes basic authentication details and strips out creds" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_basic_authentication" expect(out).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "passes basic authentication details and strips out creds also in verbose mode" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, verbose: true, artifice: "endpoint_basic_authentication" expect(out).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "strips http basic authentication creds for modern index" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_marshal_fail_basic_authentication" expect(out).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "strips http basic auth creds when it can't reach the server" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_500", raise_on_error: false @@ -585,30 +585,30 @@ RSpec.describe "gemcutter's dependency API" do gemfile <<-G source "#{basic_auth_source_uri}" source "#{file_uri_for(gem_repo1)}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_basic_authentication" - expect(err).to include("Warning: the gem 'rack' was found in multiple sources.") + expect(err).to include("Warning: the gem 'myrack' was found in multiple sources.") expect(err).not_to include("#{user}:#{password}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does not pass the user / password to different hosts on redirect" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_creds_diff_host" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end describe "with host including dashes" do before do gemfile <<-G source "http://local-gemserver.test" - gem "rack" + gem "myrack" G end @@ -616,7 +616,7 @@ RSpec.describe "gemcutter's dependency API" do bundle :install, artifice: "endpoint_strict_basic_authentication", env: { "BUNDLE_LOCAL___GEMSERVER__TEST" => "#{user}:#{password}" } expect(out).to include("Fetching gem metadata from http://local-gemserver.test") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end @@ -624,7 +624,7 @@ RSpec.describe "gemcutter's dependency API" do before do gemfile <<-G source "#{source_uri}" - gem "rack" + gem "myrack" G end @@ -634,7 +634,7 @@ RSpec.describe "gemcutter's dependency API" do bundle :install, artifice: "endpoint_strict_basic_authentication" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "reads authentication details by full url from bundle config" do @@ -644,26 +644,26 @@ RSpec.describe "gemcutter's dependency API" do bundle :install, artifice: "endpoint_strict_basic_authentication" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "should use the API" do bundle "config set #{source_hostname} #{user}:#{password}" bundle :install, artifice: "endpoint_strict_basic_authentication" expect(out).to include("Fetching gem metadata from #{source_uri}") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "prefers auth supplied in the source uri" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle "config set #{source_hostname} otheruser:wrong" bundle :install, artifice: "endpoint_strict_basic_authentication" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "shows instructions if auth is not provided for the source" do @@ -685,11 +685,11 @@ RSpec.describe "gemcutter's dependency API" do it "passes basic authentication details" do gemfile <<-G source "#{basic_auth_source_uri}" - gem "rack" + gem "myrack" G bundle :install, artifice: "endpoint_basic_authentication" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end end @@ -710,10 +710,10 @@ RSpec.describe "gemcutter's dependency API" do it "explains what to do to get it" do gemfile <<-G source "#{source_uri.gsub(/http/, "https")}" - gem "rack" + gem "myrack" G - bundle :install, env: { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) }, raise_on_error: false + bundle :install, artifice: "fail", env: { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) }, raise_on_error: false expect(err).to include("OpenSSL") end end @@ -730,7 +730,7 @@ RSpec.describe "gemcutter's dependency API" do end source "#{source_uri.gsub(/http/, "https")}" - gem "rack" + gem "myrack" G bundle :install, raise_on_error: false @@ -747,7 +747,7 @@ RSpec.describe "gemcutter's dependency API" do begin gemfile <<-G source "#{source_uri}" - gem 'rack' + gem 'myrack' G bundle "install", artifice: "endpoint_marshal_fail" diff --git a/spec/bundler/install/gems/env_spec.rb b/spec/bundler/install/gems/env_spec.rb index a6dfadcfc8..6d5aa456fe 100644 --- a/spec/bundler/install/gems/env_spec.rb +++ b/spec/bundler/install/gems/env_spec.rb @@ -4,104 +4,104 @@ RSpec.describe "bundle install with ENV conditionals" do describe "when just setting an ENV key as a string" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" env "BUNDLER_TEST" do - gem "rack" + gem "myrack" end G end it "excludes the gems when the ENV variable is not set" do bundle :install - expect(the_bundle).not_to include_gems "rack" + expect(the_bundle).not_to include_gems "myrack" end it "includes the gems when the ENV variable is set" do ENV["BUNDLER_TEST"] = "1" bundle :install - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end describe "when just setting an ENV key as a symbol" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" env :BUNDLER_TEST do - gem "rack" + gem "myrack" end G end it "excludes the gems when the ENV variable is not set" do bundle :install - expect(the_bundle).not_to include_gems "rack" + expect(the_bundle).not_to include_gems "myrack" end it "includes the gems when the ENV variable is set" do ENV["BUNDLER_TEST"] = "1" bundle :install - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end describe "when setting a string to match the env" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" env "BUNDLER_TEST" => "foo" do - gem "rack" + gem "myrack" end G end it "excludes the gems when the ENV variable is not set" do bundle :install - expect(the_bundle).not_to include_gems "rack" + expect(the_bundle).not_to include_gems "myrack" end it "excludes the gems when the ENV variable is set but does not match the condition" do ENV["BUNDLER_TEST"] = "1" bundle :install - expect(the_bundle).not_to include_gems "rack" + expect(the_bundle).not_to include_gems "myrack" end it "includes the gems when the ENV variable is set and matches the condition" do ENV["BUNDLER_TEST"] = "foo" bundle :install - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end describe "when setting a regex to match the env" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" env "BUNDLER_TEST" => /foo/ do - gem "rack" + gem "myrack" end G end it "excludes the gems when the ENV variable is not set" do bundle :install - expect(the_bundle).not_to include_gems "rack" + expect(the_bundle).not_to include_gems "myrack" end it "excludes the gems when the ENV variable is set but does not match the condition" do ENV["BUNDLER_TEST"] = "fo" bundle :install - expect(the_bundle).not_to include_gems "rack" + expect(the_bundle).not_to include_gems "myrack" end it "includes the gems when the ENV variable is set and matches the condition" do ENV["BUNDLER_TEST"] = "foobar" bundle :install - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end end diff --git a/spec/bundler/install/gems/flex_spec.rb b/spec/bundler/install/gems/flex_spec.rb index 5e0c88fc95..cddf84d831 100644 --- a/spec/bundler/install/gems/flex_spec.rb +++ b/spec/bundler/install/gems/flex_spec.rb @@ -3,30 +3,30 @@ RSpec.describe "bundle flex_install" do it "installs the gems as expected" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).to be_locked end it "installs even when the lockfile is invalid" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).to be_locked gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', '1.0' + source "https://gem.repo1" + gem 'myrack', '1.0' G bundle :install - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).to be_locked end @@ -34,19 +34,19 @@ RSpec.describe "bundle flex_install" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack-obama" + source "https://gem.repo2" + gem "myrack-obama" G - expect(the_bundle).to include_gems "rack 1.0.0", "rack-obama 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0", "myrack-obama 1.0.0" update_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack-obama", "1.0" + source "https://gem.repo2" + gem "myrack-obama", "1.0" G - expect(the_bundle).to include_gems "rack 1.0.0", "rack-obama 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0", "myrack-obama 1.0.0" end describe "adding new gems" do @@ -54,38 +54,38 @@ RSpec.describe "bundle flex_install" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' G update_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' gem 'activesupport', '2.3.5' G - expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.5" + expect(the_bundle).to include_gems "myrack 1.0.0", "activesupport 2.3.5" end it "keeps child dependencies pinned" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack-obama" + source "https://gem.repo2" + gem "myrack-obama" G update_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack-obama" + source "https://gem.repo2" + gem "myrack-obama" gem "thin" G - expect(the_bundle).to include_gems "rack 1.0.0", "rack-obama 1.0", "thin 1.0" + expect(the_bundle).to include_gems "myrack 1.0.0", "myrack-obama 1.0", "thin 1.0" end end @@ -93,43 +93,43 @@ RSpec.describe "bundle flex_install" do it "removes gems without changing the versions of remaining gems" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' gem 'activesupport', '2.3.5' G update_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).not_to include_gems "activesupport 2.3.5" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' gem 'activesupport', '2.3.2' G - expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.2" + expect(the_bundle).to include_gems "myrack 1.0.0", "activesupport 2.3.2" end it "removes top level dependencies when removed from the Gemfile while leaving other dependencies intact" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' gem 'activesupport', '2.3.5' G update_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack' + source "https://gem.repo2" + gem 'myrack' G expect(the_bundle).not_to include_gems "activesupport 2.3.5" @@ -138,21 +138,21 @@ RSpec.describe "bundle flex_install" do it "removes child dependencies" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem 'rack-obama' + source "https://gem.repo2" + gem 'myrack-obama' gem 'activesupport' G - expect(the_bundle).to include_gems "rack 1.0.0", "rack-obama 1.0.0", "activesupport 2.3.5" + expect(the_bundle).to include_gems "myrack 1.0.0", "myrack-obama 1.0.0", "activesupport 2.3.5" update_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'activesupport' G expect(the_bundle).to include_gems "activesupport 2.3.5" - expect(the_bundle).not_to include_gems "rack-obama", "rack" + expect(the_bundle).not_to include_gems "myrack-obama", "myrack" end end @@ -160,25 +160,25 @@ RSpec.describe "bundle flex_install" do before(:each) do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack_middleware" + source "https://gem.repo2" + gem "myrack_middleware" G - expect(the_bundle).to include_gems "rack_middleware 1.0", "rack 0.9.1" + expect(the_bundle).to include_gems "myrack_middleware 1.0", "myrack 0.9.1" build_repo2 do - build_gem "rack-obama", "2.0" do |s| - s.add_dependency "rack", "=1.2" + build_gem "myrack-obama", "2.0" do |s| + s.add_dependency "myrack", "=1.2" end - build_gem "rack_middleware", "2.0" do |s| - s.add_dependency "rack", ">=1.0" + build_gem "myrack_middleware", "2.0" do |s| + s.add_dependency "myrack", ">=1.0" end end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack-obama", "2.0" - gem "rack_middleware" + source "https://gem.repo2" + gem "myrack-obama", "2.0" + gem "myrack_middleware" G end @@ -187,7 +187,7 @@ RSpec.describe "bundle flex_install" do ruby <<-RUBY, raise_on_error: false require 'bundler/setup' RUBY - expect(err).to match(/could not find gem 'rack-obama/i) + expect(err).to match(/could not find gem 'myrack-obama/i) end it "discards the locked gems when the Gemfile requires different versions than the lock" do @@ -196,10 +196,10 @@ RSpec.describe "bundle flex_install" do nice_error = <<~E.strip Could not find compatible versions - Because rack-obama >= 2.0 depends on rack = 1.2 - and rack = 1.2 could not be found in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally, - rack-obama >= 2.0 cannot be used. - So, because Gemfile depends on rack-obama = 2.0, + Because myrack-obama >= 2.0 depends on myrack = 1.2 + and myrack = 1.2 could not be found in rubygems repository https://gem.repo2/ or installed locally, + myrack-obama >= 2.0 cannot be used. + So, because Gemfile depends on myrack-obama = 2.0, version solving has failed. E @@ -211,12 +211,12 @@ RSpec.describe "bundle flex_install" do bundle "config set force_ruby_platform true" bad_error = <<~E.strip - Bundler could not find compatible versions for gem "rack-obama": + Bundler could not find compatible versions for gem "myrack-obama": In Gemfile: - rack-obama (= 2.0) + myrack-obama (= 2.0) E - bundle "update rack_middleware", retry: 0, raise_on_error: false + bundle "update myrack_middleware", retry: 0, raise_on_error: false expect(err).not_to end_with(bad_error) end end @@ -233,12 +233,12 @@ RSpec.describe "bundle flex_install" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "jekyll-feed", "~> 0.12" G gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "github-pages", "~> 226" gem "jekyll-feed", "~> 0.12" G @@ -253,15 +253,15 @@ RSpec.describe "bundle flex_install" do describe "subtler cases" do before :each do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack" + gem "myrack-obama" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" - gem "rack-obama" + source "https://gem.repo1" + gem "myrack", "0.9.1" + gem "myrack-obama" G end @@ -269,24 +269,24 @@ RSpec.describe "bundle flex_install" do bundle "install" checksums = checksums_section_when_existing do |c| - c.checksum gem_repo1, "rack", "0.9.1" - c.checksum gem_repo1, "rack-obama", "1.0" + c.checksum gem_repo1, "myrack", "0.9.1" + c.checksum gem_repo1, "myrack-obama", "1.0" end expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (0.9.1) - rack-obama (1.0) - rack + myrack (0.9.1) + myrack-obama (1.0) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (= 0.9.1) - rack-obama + myrack (= 0.9.1) + myrack-obama #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -294,7 +294,7 @@ RSpec.describe "bundle flex_install" do end it "should work when you update" do - bundle "update rack" + bundle "update myrack" end end @@ -302,36 +302,36 @@ RSpec.describe "bundle flex_install" do it "updates the lockfile" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - source "#{file_uri_for(gem_repo2)}" do + source "https://gem.repo1" + source "https://gem.repo2" do end - gem "rack" + gem "myrack" G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo1, "rack", "1.0.0" + c.checksum gem_repo1, "myrack", "1.0.0" end expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -344,17 +344,17 @@ RSpec.describe "bundle flex_install" do before(:each) do build_repo2 do build_gem "capybara", "0.3.9" do |s| - s.add_dependency "rack", ">= 1.0.0" + s.add_dependency "myrack", ">= 1.0.0" end - build_gem "rack", "1.1.0" + build_gem "myrack", "1.1.0" build_gem "rails", "3.0.0.rc4" do |s| - s.add_dependency "rack", "~> 1.1.0" + s.add_dependency "myrack", "~> 1.1.0" end - build_gem "rack", "1.2.1" + build_gem "myrack", "1.2.1" build_gem "rails", "3.0.0" do |s| - s.add_dependency "rack", "~> 1.2.1" + s.add_dependency "myrack", "~> 1.2.1" end end end @@ -362,14 +362,14 @@ RSpec.describe "bundle flex_install" do it "resolves them" do # install Rails 3.0.0.rc install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0.0.rc4" gem "capybara", "0.3.9" G # upgrade Rails to 3.0.0 and then install again install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "rails", "3.0.0" gem "capybara", "0.3.9" G diff --git a/spec/bundler/install/gems/fund_spec.rb b/spec/bundler/install/gems/fund_spec.rb index 9aadc9ed25..0855a62b86 100644 --- a/spec/bundler/install/gems/fund_spec.rb +++ b/spec/bundler/install/gems/fund_spec.rb @@ -32,10 +32,10 @@ RSpec.describe "bundle install" do context "when gems include a fund URI" do it "displays the plural fund message after installing" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding_and_other_metadata' gem 'has_funding' - gem 'rack-obama' + gem 'myrack-obama' G expect(out).to include("2 installed gems you directly depend on are looking for funding.") @@ -43,9 +43,9 @@ RSpec.describe "bundle install" do it "displays the singular fund message after installing" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding' - gem 'rack-obama' + gem 'myrack-obama' G expect(out).to include("1 installed gem you directly depend on is looking for funding.") @@ -59,10 +59,10 @@ RSpec.describe "bundle install" do it "does not display the plural fund message after installing" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding_and_other_metadata' gem 'has_funding' - gem 'rack-obama' + gem 'myrack-obama' G expect(out).not_to include("2 installed gems you directly depend on are looking for funding.") @@ -70,9 +70,9 @@ RSpec.describe "bundle install" do it "does not display the singular fund message after installing" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding' - gem 'rack-obama' + gem 'myrack-obama' G expect(out).not_to include("1 installed gem you directly depend on is looking for funding.") @@ -82,7 +82,7 @@ RSpec.describe "bundle install" do context "when gems do not include fund messages" do it "does not display any fund messages" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "activesupport" G @@ -93,7 +93,7 @@ RSpec.describe "bundle install" do context "when a dependency includes a fund message" do it "does not display the fund message" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'gem_with_dependent_funding' G @@ -111,7 +111,7 @@ RSpec.describe "bundle install" do } end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' G @@ -125,7 +125,7 @@ RSpec.describe "bundle install" do } end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' G @@ -135,7 +135,7 @@ RSpec.describe "bundle install" do } end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.1")}' G @@ -149,7 +149,7 @@ RSpec.describe "bundle install" do } end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' G diff --git a/spec/bundler/install/gems/mirror_spec.rb b/spec/bundler/install/gems/mirror_spec.rb index 9611973701..70c0da50ef 100644 --- a/spec/bundler/install/gems/mirror_spec.rb +++ b/spec/bundler/install/gems/mirror_spec.rb @@ -4,17 +4,17 @@ RSpec.describe "bundle install with a mirror configured" do describe "when the mirror does not match the gem source" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G bundle "config set --local mirror.http://gems.example.org http://gem-mirror.example.org" end it "installs from the normal location" do bundle :install - expect(out).to include("Fetching source index from #{file_uri_for(gem_repo1)}") - expect(the_bundle).to include_gems "rack 1.0" + expect(out).to include("Fetching gem metadata from https://gem.repo1") + expect(the_bundle).to include_gems "myrack 1.0" end end @@ -22,18 +22,18 @@ RSpec.describe "bundle install with a mirror configured" do before :each do gemfile <<-G # This source is bogus and doesn't have the gem we're looking for - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack" + gem "myrack" G - bundle "config set --local mirror.#{file_uri_for(gem_repo2)} #{file_uri_for(gem_repo1)}" + bundle "config set --local mirror.https://gem.repo2 https://gem.repo1" end it "installs the gem from the mirror" do - bundle :install - expect(out).to include("Fetching source index from #{file_uri_for(gem_repo1)}") - expect(out).not_to include("Fetching source index from #{file_uri_for(gem_repo2)}") - expect(the_bundle).to include_gems "rack 1.0" + bundle :install, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } + expect(out).to include("Fetching gem metadata from https://gem.repo1") + expect(out).not_to include("Fetching gem metadata from https://gem.repo2") + expect(the_bundle).to include_gems "myrack 1.0" end end end diff --git a/spec/bundler/install/gems/native_extensions_spec.rb b/spec/bundler/install/gems/native_extensions_spec.rb index 907778a384..874818fa87 100644 --- a/spec/bundler/install/gems/native_extensions_spec.rb +++ b/spec/bundler/install/gems/native_extensions_spec.rb @@ -33,7 +33,7 @@ RSpec.describe "installing a gem with native extensions" do end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "c_extension" G @@ -78,7 +78,7 @@ RSpec.describe "installing a gem with native extensions" do bundle "config set build.c_extension --with-c_extension=hello" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "c_extension", :git => #{lib_path("c_extension-1.0").to_s.dump} G @@ -127,13 +127,13 @@ RSpec.describe "installing a gem with native extensions" do # 1st time, require only one gem -- only one of the extensions gets built. install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "c_extension_one", :git => #{lib_path("gems").to_s.dump} G # 2nd time, require both gems -- we need both extensions to be built now. install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "c_extension_one", :git => #{lib_path("gems").to_s.dump} gem "c_extension_two", :git => #{lib_path("gems").to_s.dump} G @@ -174,7 +174,7 @@ RSpec.describe "installing a gem with native extensions" do bundle "config set build.c_extension --with-c_extension=hello --with-c_extension_bundle-dir=hola" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "c_extension", :git => #{lib_path("c_extension-1.0").to_s.dump} G diff --git a/spec/bundler/install/gems/post_install_spec.rb b/spec/bundler/install/gems/post_install_spec.rb index 7426f54877..af753dba3e 100644 --- a/spec/bundler/install/gems/post_install_spec.rb +++ b/spec/bundler/install/gems/post_install_spec.rb @@ -5,26 +5,26 @@ RSpec.describe "bundle install" do context "when gems include post install messages" do it "should display the post-install messages after installing" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gem 'thin' - gem 'rack-obama' + gem 'myrack-obama' G bundle :install - expect(out).to include("Post-install message from rack:") - expect(out).to include("Rack's post install message") + expect(out).to include("Post-install message from myrack:") + expect(out).to include("Myrack's post install message") expect(out).to include("Post-install message from thin:") expect(out).to include("Thin's post install message") - expect(out).to include("Post-install message from rack-obama:") - expect(out).to include("Rack-obama's post install message") + expect(out).to include("Post-install message from myrack-obama:") + expect(out).to include("Myrack-obama's post install message") end end context "when gems do not include post install messages" do it "should not display any post-install messages" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" G @@ -36,13 +36,13 @@ RSpec.describe "bundle install" do context "when a dependency includes a post install message" do it "should display the post install message" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack_middleware' + source "https://gem.repo1" + gem 'myrack_middleware' G bundle :install - expect(out).to include("Post-install message from rack:") - expect(out).to include("Rack's post install message") + expect(out).to include("Post-install message from myrack:") + expect(out).to include("Myrack's post install message") end end end @@ -54,7 +54,7 @@ RSpec.describe "bundle install" do s.post_install_message = "Foo's post install message" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => '#{lib_path("foo-1.0")}' G @@ -68,7 +68,7 @@ RSpec.describe "bundle install" do s.post_install_message = "Foo's post install message" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => '#{lib_path("foo-1.0")}' G bundle :install @@ -77,7 +77,7 @@ RSpec.describe "bundle install" do s.post_install_message = "Foo's 1.1 post install message" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => '#{lib_path("foo-1.1")}' G bundle :install @@ -91,7 +91,7 @@ RSpec.describe "bundle install" do s.post_install_message = "Foo's post install message" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => '#{lib_path("foo-1.0")}' G @@ -110,7 +110,7 @@ RSpec.describe "bundle install" do s.post_install_message = nil end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => '#{lib_path("foo-1.0")}' G @@ -123,11 +123,11 @@ RSpec.describe "bundle install" do context "when ignore post-install messages for gem is set" do it "doesn't display any post-install messages" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - bundle "config set ignore_messages.rack true" + bundle "config set ignore_messages.myrack true" bundle :install expect(out).not_to include("Post-install message") @@ -137,8 +137,8 @@ RSpec.describe "bundle install" do context "when ignore post-install messages for all gems" do it "doesn't display any post-install messages" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set ignore_messages true" diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index b54674898d..589415a983 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -66,7 +66,7 @@ RSpec.describe "bundle install with install-time dependencies" do it "installs gems with implicit rake dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "with_implicit_rake_dep" gem "another_implicit_rake_dep" gem "rake" @@ -84,7 +84,7 @@ RSpec.describe "bundle install with install-time dependencies" do it "installs gems with implicit rake dependencies without rake previously installed" do with_path_as("") do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "with_implicit_rake_dep" gem "another_implicit_rake_dep" gem "rake" @@ -100,7 +100,7 @@ RSpec.describe "bundle install with install-time dependencies" do expect(out).to eq("YES\nYES") end - it "installs gems with a dependency with no type" do + it "does not install gems with a dependency with no type" do build_repo2 path = "#{gem_repo2}/#{Gem::MARSHAL_SPEC_DIR}/actionpack-2.3.2.gemspec.rz" @@ -112,18 +112,20 @@ RSpec.describe "bundle install with install-time dependencies" do f.write Gem.deflate(Marshal.dump(spec)) end - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + install_gemfile <<-G, raise_on_error: false + source "https://gem.repo2" gem "actionpack", "2.3.2" G - expect(the_bundle).to include_gems "actionpack 2.3.2", "activesupport 2.3.2" + expect(err).to include("Downloading actionpack-2.3.2 revealed dependencies not in the API or the lockfile (activesupport (= 2.3.2)).") + + expect(the_bundle).not_to include_gems "actionpack 2.3.2", "activesupport 2.3.2" end describe "with crazy rubygem plugin stuff" do it "installs plugins" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "net_b" G @@ -132,7 +134,7 @@ RSpec.describe "bundle install with install-time dependencies" do it "installs plugins depended on by other plugins" do install_gemfile <<-G, env: { "DEBUG" => "1" } - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "net_a" G @@ -141,7 +143,7 @@ RSpec.describe "bundle install with install-time dependencies" do it "installs multiple levels of dependencies" do install_gemfile <<-G, env: { "DEBUG" => "1" } - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "net_c" gem "net_e" G @@ -152,7 +154,7 @@ RSpec.describe "bundle install with install-time dependencies" do context "with ENV['BUNDLER_DEBUG_RESOLVER'] set" do it "produces debug output" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "net_c" gem "net_e" G @@ -166,7 +168,7 @@ RSpec.describe "bundle install with install-time dependencies" do context "with ENV['DEBUG_RESOLVER'] set" do it "produces debug output" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "net_c" gem "net_e" G @@ -180,7 +182,7 @@ RSpec.describe "bundle install with install-time dependencies" do context "with ENV['DEBUG_RESOLVER_TREE'] set" do it "produces debug output" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "net_c" gem "net_e" G @@ -199,11 +201,11 @@ RSpec.describe "bundle install with install-time dependencies" do context "allows only an older version" do it "installs the older version" do build_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end - build_gem "rack", "9001.0.0" do |s| + build_gem "myrack", "9001.0.0" do |s| s.required_ruby_version = "> 9000" end end @@ -211,20 +213,20 @@ RSpec.describe "bundle install with install-time dependencies" do install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" - gem 'rack' + gem 'myrack' G - expect(err).to_not include("rack-9001.0.0 requires ruby version > 9000") - expect(the_bundle).to include_gems("rack 1.2") + expect(err).to_not include("myrack-9001.0.0 requires ruby version > 9000") + expect(the_bundle).to include_gems("myrack 1.2") end it "installs the older version when using servers not implementing the compact index API" do build_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end - build_gem "rack", "9001.0.0" do |s| + build_gem "myrack", "9001.0.0" do |s| s.required_ruby_version = "> 9000" end end @@ -232,11 +234,11 @@ RSpec.describe "bundle install with install-time dependencies" do install_gemfile <<-G, artifice: "endpoint", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" - gem 'rack' + gem 'myrack' G - expect(err).to_not include("rack-9001.0.0 requires ruby version > 9000") - expect(the_bundle).to include_gems("rack 1.2") + expect(err).to_not include("myrack-9001.0.0 requires ruby version > 9000") + expect(the_bundle).to include_gems("myrack 1.2") end context "when there is a lockfile using the newer incompatible version" do @@ -405,13 +407,13 @@ RSpec.describe "bundle install with install-time dependencies" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem 'sorbet', '= 0.5.10554' G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: sorbet (0.5.10554) sorbet-static (= 0.5.10554) @@ -434,7 +436,7 @@ RSpec.describe "bundle install with install-time dependencies" do end nice_error = <<~E.strip - Could not find gems matching 'sorbet-static (= 0.5.10554)' valid for all resolution platforms (arm64-darwin-21, aarch64-linux) in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally. + Could not find gems matching 'sorbet-static (= 0.5.10554)' valid for all resolution platforms (arm64-darwin-21, aarch64-linux) in rubygems repository https://gem.repo4/ or installed locally. The source contains the following gems matching 'sorbet-static (= 0.5.10554)': * sorbet-static-0.5.10554-universal-darwin-21 @@ -461,7 +463,7 @@ RSpec.describe "bundle install with install-time dependencies" do lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: nokogiri (1.14.0-arm-linux) nokogiri (1.14.0-x86_64-linux) @@ -478,7 +480,7 @@ RSpec.describe "bundle install with install-time dependencies" do L gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri" gem "sorbet-static" @@ -490,7 +492,7 @@ RSpec.describe "bundle install with install-time dependencies" do it "raises a proper error" do nice_error = <<~E.strip - Could not find gems matching 'sorbet-static' valid for all resolution platforms (arm-linux, x86_64-linux) in rubygems repository #{file_uri_for(gem_repo4)}/ or installed locally. + Could not find gems matching 'sorbet-static' valid for all resolution platforms (arm-linux, x86_64-linux) in rubygems repository https://gem.repo4/ or installed locally. The source contains the following gems matching 'sorbet-static': * sorbet-static-0.5.10696-x86_64-linux @@ -513,7 +515,7 @@ RSpec.describe "bundle install with install-time dependencies" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gemspec G @@ -531,47 +533,47 @@ RSpec.describe "bundle install with install-time dependencies" do it "installs the older version under rate limiting conditions" do build_repo4 do - build_gem "rack", "9001.0.0" do |s| + build_gem "myrack", "9001.0.0" do |s| s.required_ruby_version = "> 9000" end - build_gem "rack", "1.2" + build_gem "myrack", "1.2" build_gem "foo1", "1.0" end install_gemfile <<-G, artifice: "compact_index_rate_limited", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" - gem 'rack' + gem 'myrack' gem 'foo1' G - expect(err).to_not include("rack-9001.0.0 requires ruby version > 9000") - expect(the_bundle).to include_gems("rack 1.2") + expect(err).to_not include("myrack-9001.0.0 requires ruby version > 9000") + expect(the_bundle).to include_gems("myrack 1.2") end it "installs the older not platform specific version" do build_repo4 do - build_gem "rack", "9001.0.0" do |s| + build_gem "myrack", "9001.0.0" do |s| s.required_ruby_version = "> 9000" end - build_gem "rack", "1.2" do |s| + build_gem "myrack", "1.2" do |s| s.platform = x86_mingw32 s.required_ruby_version = "> 9000" end - build_gem "rack", "1.2" + build_gem "myrack", "1.2" end simulate_platform x86_mingw32 do install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } ruby "#{Gem.ruby_version}" source "http://localgemserver.test/" - gem 'rack' + gem 'myrack' G end - expect(err).to_not include("rack-9001.0.0 requires ruby version > 9000") - expect(err).to_not include("rack-1.2-#{Bundler.local_platform} requires ruby version > 9000") - expect(the_bundle).to include_gems("rack 1.2") + expect(err).to_not include("myrack-9001.0.0 requires ruby version > 9000") + expect(err).to_not include("myrack-1.2-#{Bundler.local_platform} requires ruby version > 9000") + expect(the_bundle).to include_gems("myrack 1.2") end end @@ -656,7 +658,7 @@ RSpec.describe "bundle install with install-time dependencies" do end install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'require_rubygems' G diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index 46cab2dfeb..ee8d9c6d3a 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -8,9 +8,9 @@ RSpec.shared_examples "bundle install --standalone" do end it "still makes system gems unavailable to normal bundler" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" - expect(the_bundle).to_not include_gems("rack") + expect(the_bundle).to_not include_gems("myrack") end it "generates a bundle/bundler/setup.rb" do @@ -63,14 +63,14 @@ RSpec.shared_examples "bundle install --standalone" do end it "makes system gems unavailable without bundler" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" testrb = String.new <<-RUBY $:.unshift File.expand_path("bundle") require "bundler/setup" begin - require "rack" + require "myrack" rescue LoadError puts "LoadError" end @@ -122,7 +122,7 @@ RSpec.shared_examples "bundle install --standalone" do describe "with simple gems" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G bundle "config set --local path #{bundled_app("bundle")}" @@ -141,12 +141,18 @@ RSpec.shared_examples "bundle install --standalone" do describe "with default gems and a lockfile", :ruby_repo do before do - realworld_system_gems "tsort --version 0.1.0" + skip "Does not work on old Windows Rubies" if Gem.ruby_version < Gem::Version.new("3.2") && Gem.win_platform? - necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "logger --version 1.4.3", "etc --version 1.2.0", "stringio --version 3.1.0"] - necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.a") - necessary_system_gems += ["yaml --version 0.1.1"] if Gem.rubygems_version < Gem::Version.new("3.4.a") - realworld_system_gems(*necessary_system_gems, path: scoped_gem_path(bundled_app("bundle"))) + necessary_system_gems = ["tsort --version 0.1.0"] + necessary_system_gems += ["etc --version 1.4.3"] if Gem.ruby_version >= Gem::Version.new("3.3.2") && Gem.win_platform? + realworld_system_gems(*necessary_system_gems) + end + + it "works and points to the vendored copies, not to the default copies" do + necessary_gems_in_bundle_path = ["optparse --version 0.1.1", "psych --version 3.3.2", "logger --version 1.4.3", "etc --version 1.4.3", "stringio --version 3.1.0"] + necessary_gems_in_bundle_path += ["shellwords --version 0.2.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.a") + necessary_gems_in_bundle_path += ["yaml --version 0.1.1"] if Gem.rubygems_version < Gem::Version.new("3.4.a") + realworld_system_gems(*necessary_gems_in_bundle_path, path: scoped_gem_path(bundled_app("bundle"))) build_gem "foo", "1.0.0", to_system: true, default: true do |s| s.add_dependency "bar" @@ -167,12 +173,10 @@ RSpec.shared_examples "bundle install --standalone" do gem "foo" G - bundle "lock", dir: cwd, artifice: "compact_index" - end + bundle "lock", dir: cwd - it "works and points to the vendored copies, not to the default copies", :realworld do bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, standalone: true, dir: cwd, artifice: "compact_index", env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + bundle :install, standalone: true, dir: cwd, env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } load_path_lines = bundled_app("bundle/bundler/setup.rb").read.split("\n").select {|line| line.start_with?("$:.unshift") } @@ -181,6 +185,39 @@ RSpec.shared_examples "bundle install --standalone" do '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/foo-1.0.0/lib")', ] end + + it "works for gems with extensions and points to the vendored copies, not to the default copies" do + necessary_gems_in_bundle_path = ["optparse --version 0.1.1", "psych --version 3.3.2", "logger --version 1.4.3", "etc --version 1.4.3", "stringio --version 3.1.0", "shellwords --version 0.2.0", "open3 --version 0.2.1"] + necessary_gems_in_bundle_path += ["base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.a") + necessary_gems_in_bundle_path += ["yaml --version 0.1.1"] if Gem.rubygems_version < Gem::Version.new("3.4.a") + realworld_system_gems(*necessary_gems_in_bundle_path, path: scoped_gem_path(bundled_app("bundle"))) + + build_gem "baz", "1.0.0", to_system: true, default: true, &:add_c_extension + + build_repo4 do + build_gem "baz", "1.0.0", &:add_c_extension + end + + gemfile <<-G + source "https://gem.repo4" + gem "baz" + G + + bundle "config set --local path #{bundled_app("bundle")}" + + simulate_platform "arm64-darwin-23" do + bundle "lock", dir: cwd + + bundle :install, standalone: true, dir: cwd, env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + end + + load_path_lines = bundled_app("bundle/bundler/setup.rb").read.split("\n").select {|line| line.start_with?("$:.unshift") } + + expect(load_path_lines).to eq [ + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/arm64-darwin-23/#{Gem.extension_api_version}/baz-1.0.0")', + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/baz-1.0.0/lib")', + ] + end end describe "with Gemfiles using absolute path sources and resulting bundle moved to a folder hierarchy with different nesting" do @@ -190,7 +227,7 @@ RSpec.shared_examples "bundle install --standalone" do Dir.mkdir bundled_app("app") gemfile bundled_app("app/Gemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "minitest", :path => "#{lib_path("minitest")}" G @@ -220,7 +257,7 @@ RSpec.shared_examples "bundle install --standalone" do build_lib "minitest", "1.0.0", path: bundled_app("app/vendor/minitest") gemfile bundled_app("app/Gemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "minitest", :path => "vendor/minitest" G @@ -246,7 +283,7 @@ RSpec.shared_examples "bundle install --standalone" do before do bundle "config set --local path #{bundled_app("bundle")}" install_gemfile <<-G, standalone: true, dir: cwd - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "very_simple_binary" G end @@ -284,14 +321,14 @@ RSpec.shared_examples "bundle install --standalone" do end bundle "config set --local path #{bundled_app("bundle")}" install_gemfile <<-G, standalone: true, dir: cwd, raise_on_error: false - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :git => "#{lib_path("bar-1.0")}" G end it "outputs a helpful error message" do expect(err).to include("You have one or more invalid gemspecs that need to be fixed.") - expect(err).to include("bar 1.0 has an invalid gemspec") + expect(err).to include("bar.gemspec is not valid") end end @@ -300,7 +337,7 @@ RSpec.shared_examples "bundle install --standalone" do build_git "devise", "1.0" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" gem "devise", :git => "#{lib_path("devise-1.0")}" G @@ -324,12 +361,12 @@ RSpec.shared_examples "bundle install --standalone" do build_git "devise", "1.0" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" group :test do gem "rspec" - gem "rack-test" + gem "myrack-test" end G bundle "config set --local path #{bundled_app("bundle")}" @@ -442,7 +479,7 @@ RSpec.shared_examples "bundle install --standalone" do describe "with --binstubs", bundler: "< 3" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G bundle "config set --local path #{bundled_app("bundle")}" @@ -502,23 +539,23 @@ end RSpec.describe "bundle install --standalone --local" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path end it "generates script pointing to system gems" do bundle "install --standalone --local --verbose" - expect(out).to include("Using rack 1.0.0") + expect(out).to include("Using myrack 1.0.0") load_error_ruby <<-RUBY, "spec" require "./bundler/setup" - require "rack" - puts RACK + require "myrack" + puts MYRACK require "spec" RUBY diff --git a/spec/bundler/install/gems/win32_spec.rb b/spec/bundler/install/gems/win32_spec.rb index 419b14ff0f..be37673aa1 100644 --- a/spec/bundler/install/gems/win32_spec.rb +++ b/spec/bundler/install/gems/win32_spec.rb @@ -4,22 +4,22 @@ RSpec.describe "bundle install with win32-generated lockfile" do it "should read lockfile" do File.open(bundled_app_lock, "wb") do |f| f << "GEM\r\n" - f << " remote: #{file_uri_for(gem_repo1)}/\r\n" + f << " remote: https://gem.repo1/\r\n" f << " specs:\r\n" f << "\r\n" - f << " rack (1.0.0)\r\n" + f << " myrack (1.0.0)\r\n" f << "\r\n" f << "PLATFORMS\r\n" f << " ruby\r\n" f << "\r\n" f << "DEPENDENCIES\r\n" - f << " rack\r\n" + f << " myrack\r\n" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - gem "rack" + gem "myrack" G end end diff --git a/spec/bundler/install/gemspecs_spec.rb b/spec/bundler/install/gemspecs_spec.rb index 51aa0ed14f..7629870db2 100644 --- a/spec/bundler/install/gemspecs_spec.rb +++ b/spec/bundler/install/gemspecs_spec.rb @@ -10,7 +10,7 @@ RSpec.describe "bundle install" do it "still installs correctly" do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "yaml_spec" G bundle :install @@ -21,7 +21,7 @@ RSpec.describe "bundle install" do build_lib "yaml_spec", gemspec: :yaml install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'yaml_spec', :path => "#{lib_path("yaml_spec-1.0")}" G expect(err).to be_empty @@ -31,22 +31,22 @@ RSpec.describe "bundle install" do it "should use gemspecs in the system cache when available" do gemfile <<-G source "http://localtestserver.gem" - gem 'rack' + gem 'myrack' G - system_gems "rack-1.0.0", path: default_bundle_path + system_gems "myrack-1.0.0", path: default_bundle_path FileUtils.mkdir_p "#{default_bundle_path}/specifications" - File.open("#{default_bundle_path}/specifications/rack-1.0.0.gemspec", "w+") do |f| + File.open("#{default_bundle_path}/specifications/myrack-1.0.0.gemspec", "w+") do |f| spec = Gem::Specification.new do |s| - s.name = "rack" + s.name = "myrack" s.version = "1.0.0" - s.add_runtime_dependency "activesupport", "2.3.2" + s.add_dependency "activesupport", "2.3.2" end f.write spec.to_ruby end bundle :install, artifice: "endpoint_marshal_fail" # force gemspec load - expect(the_bundle).to include_gems "rack 1.0.0", "activesupport 2.3.2" + expect(the_bundle).to include_gems "myrack 1.0.0", "activesupport 2.3.2" end it "does not hang when gemspec has incompatible encoding" do @@ -60,7 +60,7 @@ RSpec.describe "bundle install" do G install_gemfile <<-G, env: { "LANG" => "C" } - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G @@ -86,7 +86,7 @@ RSpec.describe "bundle install" do G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G @@ -102,7 +102,7 @@ RSpec.describe "bundle install" do install_gemfile <<-G ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G expect(the_bundle).to include_gems "foo 1.0" @@ -116,7 +116,7 @@ RSpec.describe "bundle install" do install_gemfile <<-G, raise_on_error: false ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{RUBY_PATCHLEVEL}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G expect(the_bundle).to include_gems "foo 1.0" @@ -131,7 +131,7 @@ RSpec.describe "bundle install" do install_gemfile <<-G, raise_on_error: false ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{patchlevel}' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G @@ -149,7 +149,7 @@ RSpec.describe "bundle install" do install_gemfile <<-G, raise_on_error: false ruby '#{version}', :engine_version => '#{version}', :engine => 'ruby' - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G @@ -157,5 +157,25 @@ RSpec.describe "bundle install" do expect(err).to include("but your Gemfile specified") expect(exitstatus).to eq(18) end + + it "validates gemspecs just once when everything installed and lockfile up to date" do + build_lib "foo" + + install_gemfile <<-G + source "https://gem.repo1" + gemspec path: "#{lib_path("foo-1.0")}" + + module Monkey + def validate(spec) + puts "Validate called on \#{spec.full_name}" + end + end + Bundler.rubygems.extend(Monkey) + G + + bundle "install" + + expect(out).to include("Validate called on foo-1.0").once + end end end diff --git a/spec/bundler/install/git_spec.rb b/spec/bundler/install/git_spec.rb index c8d574baf3..179e6df4b4 100644 --- a/spec/bundler/install/git_spec.rb +++ b/spec/bundler/install/git_spec.rb @@ -6,11 +6,11 @@ RSpec.describe "bundle install" do build_git "foo", "1.0", path: lib_path("foo") install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo"))}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo")}" G - expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at main@#{revision_for(lib_path("foo"))[0..6]})") + expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at main@#{revision_for(lib_path("foo"))[0..6]})") expect(the_bundle).to include_gems "foo 1.0", source: "git@#{lib_path("foo")}" end @@ -18,11 +18,11 @@ RSpec.describe "bundle install" do build_git "foo", "1.0", path: lib_path("foo"), default_branch: "main" install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo"))}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo")}" G - expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at main@#{revision_for(lib_path("foo"))[0..6]})") + expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at main@#{revision_for(lib_path("foo"))[0..6]})") expect(the_bundle).to include_gems "foo 1.0", source: "git@#{lib_path("foo")}" end @@ -36,17 +36,17 @@ RSpec.describe "bundle install" do update_git "foo", "3.0", path: lib_path("foo"), gemspec: true install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo"))}", :ref => "main~2" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo")}", :ref => "main~2" G - expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at main~2@#{rev})") + expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at main~2@#{rev})") expect(the_bundle).to include_gems "foo 1.0", source: "git@#{lib_path("foo")}" update_git "foo", "4.0", path: lib_path("foo"), gemspec: true bundle :update, all: true, verbose: true - expect(out).to include("Using foo 2.0 (was 1.0) from #{file_uri_for(lib_path("foo"))} (at main~2@#{rev2})") + expect(out).to include("Using foo 2.0 (was 1.0) from #{lib_path("foo")} (at main~2@#{rev2})") expect(the_bundle).to include_gems "foo 2.0", source: "git@#{lib_path("foo")}" end @@ -54,13 +54,13 @@ RSpec.describe "bundle install" do revision = build_git("foo").ref_for("HEAD") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :group => :development + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}", :group => :development G lockfile <<-L GIT - remote: #{file_uri_for(lib_path("foo-1.0"))} + remote: #{lib_path("foo-1.0")} revision: #{revision} specs: foo (1.0) @@ -87,9 +87,9 @@ RSpec.describe "bundle install" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "foo", :git => "#{file_uri_for(lib_path("gems"))}", :glob => "foo/*.gemspec" - gem "zebra", :git => "#{file_uri_for(lib_path("gems"))}", :glob => "zebra/*.gemspec" + source "https://gem.repo2" + gem "foo", :git => "#{lib_path("gems")}", :glob => "foo/*.gemspec" + gem "zebra", :git => "#{lib_path("gems")}", :glob => "zebra/*.gemspec" G bundle "info foo" @@ -112,7 +112,7 @@ RSpec.describe "bundle install" do other_ref = other.ref_for("HEAD") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "test", git: #{test.path.to_s.inspect} gem "other", ref: #{other_ref.inspect}, git: #{other.path.to_s.inspect} @@ -133,7 +133,7 @@ RSpec.describe "bundle install" do other (1.0.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -178,11 +178,11 @@ RSpec.describe "bundle install" do bundle "config set path vendor/bundle" bundle "config set clean true" install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo"))}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo")}" G - expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at main@#{rev[0..6]})") + expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at main@#{rev[0..6]})") expect(the_bundle).to include_gems "foo 1.0", source: "git@#{lib_path("foo")}" old_lockfile = lockfile @@ -191,14 +191,14 @@ RSpec.describe "bundle install" do rev2 = revision_for(lib_path("foo")) bundle :update, all: true, verbose: true - expect(out).to include("Using foo 2.0 (was 1.0) from #{file_uri_for(lib_path("foo"))} (at main@#{rev2[0..6]})") + expect(out).to include("Using foo 2.0 (was 1.0) from #{lib_path("foo")} (at main@#{rev2[0..6]})") expect(out).to include("Removing foo (#{rev[0..11]})") expect(the_bundle).to include_gems "foo 2.0", source: "git@#{lib_path("foo")}" lockfile(old_lockfile) bundle :install, verbose: true - expect(out).to include("Using foo 1.0 from #{file_uri_for(lib_path("foo"))} (at main@#{rev[0..6]})") + expect(out).to include("Using foo 1.0 from #{lib_path("foo")} (at main@#{rev[0..6]})") expect(the_bundle).to include_gems "foo 1.0", source: "git@#{lib_path("foo")}" end end diff --git a/spec/bundler/install/global_cache_spec.rb b/spec/bundler/install/global_cache_spec.rb index 0da4de05b2..df4559c42e 100644 --- a/spec/bundler/install/global_cache_spec.rb +++ b/spec/bundler/install/global_cache_spec.rb @@ -18,133 +18,133 @@ RSpec.describe "global gem caching" do it "caches gems into the global cache on download" do install_gemfile <<-G, artifice: "compact_index" source "#{source}" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" - expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(the_bundle).to include_gems "myrack 1.0.0" + expect(source_global_cache("myrack-1.0.0.gem")).to exist end it "uses globally cached gems if they exist" do source_global_cache.mkpath - FileUtils.cp(gem_repo1("gems/rack-1.0.0.gem"), source_global_cache("rack-1.0.0.gem")) + FileUtils.cp(gem_repo1("gems/myrack-1.0.0.gem"), source_global_cache("myrack-1.0.0.gem")) install_gemfile <<-G, artifice: "compact_index_no_gem" source "#{source}" - gem "rack" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "shows a proper error message if a cached gem is corrupted" do source_global_cache.mkpath - FileUtils.touch(source_global_cache("rack-1.0.0.gem")) + FileUtils.touch(source_global_cache("myrack-1.0.0.gem")) install_gemfile <<-G, artifice: "compact_index_no_gem", raise_on_error: false source "#{source}" - gem "rack" + gem "myrack" G - expect(err).to include("Gem::Package::FormatError: package metadata is missing in #{source_global_cache("rack-1.0.0.gem")}") + expect(err).to include("Gem::Package::FormatError: package metadata is missing in #{source_global_cache("myrack-1.0.0.gem")}") end describe "when the same gem from different sources is installed" do it "should use the appropriate one from the global cache" do install_gemfile <<-G, artifice: "compact_index" source "#{source}" - gem "rack" + gem "myrack" G simulate_new_machine - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(source_global_cache("rack-1.0.0.gem")).to exist - # rack 1.0.0 is not installed and it is in the global cache + expect(the_bundle).not_to include_gems "myrack 1.0.0" + expect(source_global_cache("myrack-1.0.0.gem")).to exist + # myrack 1.0.0 is not installed and it is in the global cache install_gemfile <<-G, artifice: "compact_index" source "#{source2}" - gem "rack", "0.9.1" + gem "myrack", "0.9.1" G simulate_new_machine - expect(the_bundle).not_to include_gems "rack 0.9.1" - expect(source2_global_cache("rack-0.9.1.gem")).to exist - # rack 0.9.1 is not installed and it is in the global cache + expect(the_bundle).not_to include_gems "myrack 0.9.1" + expect(source2_global_cache("myrack-0.9.1.gem")).to exist + # myrack 0.9.1 is not installed and it is in the global cache gemfile <<-G source "#{source}" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G bundle :install, artifice: "compact_index_no_gem" - # rack 1.0.0 is installed and rack 0.9.1 is not - expect(the_bundle).to include_gems "rack 1.0.0" - expect(the_bundle).not_to include_gems "rack 0.9.1" + # myrack 1.0.0 is installed and myrack 0.9.1 is not + expect(the_bundle).to include_gems "myrack 1.0.0" + expect(the_bundle).not_to include_gems "myrack 0.9.1" simulate_new_machine gemfile <<-G source "#{source2}" - gem "rack", "0.9.1" + gem "myrack", "0.9.1" G bundle :install, artifice: "compact_index_no_gem" - # rack 0.9.1 is installed and rack 1.0.0 is not - expect(the_bundle).to include_gems "rack 0.9.1" - expect(the_bundle).not_to include_gems "rack 1.0.0" + # myrack 0.9.1 is installed and myrack 1.0.0 is not + expect(the_bundle).to include_gems "myrack 0.9.1" + expect(the_bundle).not_to include_gems "myrack 1.0.0" end it "should not install if the wrong source is provided" do gemfile <<-G source "#{source}" - gem "rack" + gem "myrack" G bundle :install, artifice: "compact_index" simulate_new_machine - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(source_global_cache("rack-1.0.0.gem")).to exist - # rack 1.0.0 is not installed and it is in the global cache + expect(the_bundle).not_to include_gems "myrack 1.0.0" + expect(source_global_cache("myrack-1.0.0.gem")).to exist + # myrack 1.0.0 is not installed and it is in the global cache gemfile <<-G source "#{source2}" - gem "rack", "0.9.1" + gem "myrack", "0.9.1" G bundle :install, artifice: "compact_index" simulate_new_machine - expect(the_bundle).not_to include_gems "rack 0.9.1" - expect(source2_global_cache("rack-0.9.1.gem")).to exist - # rack 0.9.1 is not installed and it is in the global cache + expect(the_bundle).not_to include_gems "myrack 0.9.1" + expect(source2_global_cache("myrack-0.9.1.gem")).to exist + # myrack 0.9.1 is not installed and it is in the global cache gemfile <<-G source "#{source2}" - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source2_global_cache("rack-0.9.1.gem")).to exist + expect(source_global_cache("myrack-1.0.0.gem")).to exist + expect(source2_global_cache("myrack-0.9.1.gem")).to exist bundle :install, artifice: "compact_index_no_gem", raise_on_error: false expect(err).to include("Internal Server Error 500") expect(err).not_to include("ERROR REPORT TEMPLATE") - # rack 1.0.0 is not installed and rack 0.9.1 is not - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(the_bundle).not_to include_gems "rack 0.9.1" + # myrack 1.0.0 is not installed and myrack 0.9.1 is not + expect(the_bundle).not_to include_gems "myrack 1.0.0" + expect(the_bundle).not_to include_gems "myrack 0.9.1" gemfile <<-G source "#{source}" - gem "rack", "0.9.1" + gem "myrack", "0.9.1" G - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source2_global_cache("rack-0.9.1.gem")).to exist + expect(source_global_cache("myrack-1.0.0.gem")).to exist + expect(source2_global_cache("myrack-0.9.1.gem")).to exist bundle :install, artifice: "compact_index_no_gem", raise_on_error: false expect(err).to include("Internal Server Error 500") expect(err).not_to include("ERROR REPORT TEMPLATE") - # rack 0.9.1 is not installed and rack 1.0.0 is not - expect(the_bundle).not_to include_gems "rack 0.9.1" - expect(the_bundle).not_to include_gems "rack 1.0.0" + # myrack 0.9.1 is not installed and myrack 1.0.0 is not + expect(the_bundle).not_to include_gems "myrack 0.9.1" + expect(the_bundle).not_to include_gems "myrack 1.0.0" end end @@ -152,29 +152,29 @@ RSpec.describe "global gem caching" do it "uses the global cache as a source" do install_gemfile <<-G, artifice: "compact_index" source "#{source}" - gem "rack" + gem "myrack" gem "activesupport" G # Both gems are installed and in the global cache - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("myrack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist simulate_new_machine # Both gems are now only in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(the_bundle).not_to include_gems "myrack 1.0.0" expect(the_bundle).not_to include_gems "activesupport 2.3.5" install_gemfile <<-G, artifice: "compact_index_no_gem" source "#{source}" - gem "rack" + gem "myrack" G - # rack is installed and both are in the global cache - expect(the_bundle).to include_gems "rack 1.0.0" + # myrack is installed and both are in the global cache + expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).not_to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("myrack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist create_file bundled_app2("gems.rb"), <<-G @@ -183,9 +183,9 @@ RSpec.describe "global gem caching" do G # Neither gem is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0", dir: bundled_app2 + expect(the_bundle).not_to include_gems "myrack 1.0.0", dir: bundled_app2 expect(the_bundle).not_to include_gems "activesupport 2.3.5", dir: bundled_app2 - expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("myrack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist # Install using the global cache instead of by downloading the .gem @@ -193,10 +193,10 @@ RSpec.describe "global gem caching" do bundle :install, artifice: "compact_index_no_gem", dir: bundled_app2 # activesupport is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0", dir: bundled_app2 + expect(the_bundle).not_to include_gems "myrack 1.0.0", dir: bundled_app2 expect(the_bundle).to include_gems "activesupport 2.3.5", dir: bundled_app2 - expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("myrack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist end end @@ -211,7 +211,7 @@ RSpec.describe "global gem caching" do revision = revision_for(lib_path("very_simple_git_binary-1.0"))[0, 12] install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "very_simple_binary" gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}" @@ -219,7 +219,7 @@ RSpec.describe "global gem caching" do G gem_binary_cache = home(".bundle", "cache", "extensions", local_platform.to_s, Bundler.ruby_scope, - Digest(:MD5).hexdigest("#{gem_repo1}/"), "very_simple_binary-1.0") + "gem.repo1.443.#{Digest(:MD5).hexdigest("gem.repo1.443./")}", "very_simple_binary-1.0") git_binary_cache = home(".bundle", "cache", "extensions", local_platform.to_s, Bundler.ruby_scope, "very_simple_git_binary-1.0-#{revision}", "very_simple_git_binary-1.0") diff --git a/spec/bundler/install/path_spec.rb b/spec/bundler/install/path_spec.rb index 0a30e402b7..8d32e033d6 100644 --- a/spec/bundler/install/path_spec.rb +++ b/spec/bundler/install/path_spec.rb @@ -3,27 +3,27 @@ RSpec.describe "bundle install" do describe "with path configured" do before :each do - build_gem "rack", "1.0.0", to_system: true do |s| - s.write "lib/rack.rb", "puts 'FAIL'" + build_gem "myrack", "1.0.0", to_system: true do |s| + s.write "lib/myrack.rb", "puts 'FAIL'" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end it "does not use available system gems with `vendor/bundle" do bundle "config set --local path vendor/bundle" bundle :install - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "uses system gems with `path.system` configured with more priority than `path`" do bundle "config set --local path.system true" bundle "config set --global path vendor/bundle" bundle :install - run "require 'rack'", raise_on_error: false + run "require 'myrack'", raise_on_error: false expect(out).to include("FAIL") end @@ -55,8 +55,8 @@ RSpec.describe "bundle install" do FileUtils.rm_rf bundled_app("vendor") bundle "install" - expect(vendored_gems("gems/rack-1.0.0")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(vendored_gems("gems/myrack-1.0.0")).to be_directory + expect(the_bundle).to include_gems "myrack 1.0.0" end context "with path_relative_to_cwd set to true" do @@ -66,7 +66,7 @@ RSpec.describe "bundle install" do bundle "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle", dir: bundled_app.parent expect(out).to include("installed into `./vendor/bundle`") expect(bundled_app("../vendor/bundle")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs the standalone bundle relative to the cwd" do @@ -87,13 +87,13 @@ RSpec.describe "bundle install" do describe "when BUNDLE_PATH or the global path config is set" do before :each do - build_lib "rack", "1.0.0", to_system: true do |s| - s.write "lib/rack.rb", "raise 'FAIL'" + build_lib "myrack", "1.0.0", to_system: true do |s| + s.write "lib/myrack.rb", "raise 'FAIL'" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -112,9 +112,9 @@ RSpec.describe "bundle install" do bundle "config set --local path vendor/bundle" bundle :install - expect(vendored_gems("gems/rack-1.0.0")).to be_directory + expect(vendored_gems("gems/myrack-1.0.0")).to be_directory expect(bundled_app("vendor2")).not_to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs gems to ." do @@ -123,9 +123,9 @@ RSpec.describe "bundle install" do bundle :install - paths_to_exist = %w[cache/rack-1.0.0.gem gems/rack-1.0.0 specifications/rack-1.0.0.gemspec].map {|path| bundled_app(Bundler.ruby_scope, path) } + paths_to_exist = %w[cache/myrack-1.0.0.gem gems/myrack-1.0.0 specifications/myrack-1.0.0.gemspec].map {|path| bundled_app(Bundler.ruby_scope, path) } expect(paths_to_exist).to all exist - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs gems to the path" do @@ -133,8 +133,8 @@ RSpec.describe "bundle install" do bundle :install - expect(bundled_app("vendor", Bundler.ruby_scope, "gems/rack-1.0.0")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(bundled_app("vendor", Bundler.ruby_scope, "gems/myrack-1.0.0")).to be_directory + expect(the_bundle).to include_gems "myrack 1.0.0" end it "installs gems to the path relative to root when relative" do @@ -143,8 +143,8 @@ RSpec.describe "bundle install" do FileUtils.mkdir_p bundled_app("lol") bundle :install, dir: bundled_app("lol") - expect(bundled_app("vendor", Bundler.ruby_scope, "gems/rack-1.0.0")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(bundled_app("vendor", Bundler.ruby_scope, "gems/myrack-1.0.0")).to be_directory + expect(the_bundle).to include_gems "myrack 1.0.0" end end end @@ -154,26 +154,26 @@ RSpec.describe "bundle install" do bundle :install - expect(vendored_gems("gems/rack-1.0.0")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(vendored_gems("gems/myrack-1.0.0")).to be_directory + expect(the_bundle).to include_gems "myrack 1.0.0" end it "sets BUNDLE_PATH as the first argument to bundle install" do bundle "config set --local path ./vendor/bundle" bundle :install - expect(vendored_gems("gems/rack-1.0.0")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(vendored_gems("gems/myrack-1.0.0")).to be_directory + expect(the_bundle).to include_gems "myrack 1.0.0" end it "disables system gems when passing a path to install" do # This is so that vendored gems can be distributed to others - build_gem "rack", "1.1.0", to_system: true + build_gem "myrack", "1.1.0", to_system: true bundle "config set --local path ./vendor/bundle" bundle :install - expect(vendored_gems("gems/rack-1.0.0")).to be_directory - expect(the_bundle).to include_gems "rack 1.0.0" + expect(vendored_gems("gems/myrack-1.0.0")).to be_directory + expect(the_bundle).to include_gems "myrack 1.0.0" end it "re-installs gems whose extensions have been deleted" do @@ -182,7 +182,7 @@ RSpec.describe "bundle install" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "very_simple_binary" G @@ -214,8 +214,8 @@ RSpec.describe "bundle install" do it "reports the file exists" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "config set --local path bundle" diff --git a/spec/bundler/install/prereleases_spec.rb b/spec/bundler/install/prereleases_spec.rb index 629eb89dac..cde27c14fc 100644 --- a/spec/bundler/install/prereleases_spec.rb +++ b/spec/bundler/install/prereleases_spec.rb @@ -13,7 +13,7 @@ RSpec.describe "bundle install" do describe "when prerelease gems are available" do it "finds prereleases" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "not_released" G expect(the_bundle).to include_gems "not_released 1.0.pre" @@ -21,7 +21,7 @@ RSpec.describe "bundle install" do it "uses regular releases if available" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "has_prerelease" G expect(the_bundle).to include_gems "has_prerelease 1.0" @@ -29,7 +29,7 @@ RSpec.describe "bundle install" do it "uses prereleases if requested" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "has_prerelease", "1.1.pre" G expect(the_bundle).to include_gems "has_prerelease 1.1.pre" @@ -39,16 +39,16 @@ RSpec.describe "bundle install" do describe "when prerelease gems are not available" do it "still works" do build_repo gem_repo3 do - build_gem "rack" + build_gem "myrack" end FileUtils.rm_rf Dir[gem_repo3("prerelease*")] install_gemfile <<-G - source "#{file_uri_for(gem_repo3)}" - gem "rack" + source "https://gem.repo3" + gem "myrack" G - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end end diff --git a/spec/bundler/install/process_lock_spec.rb b/spec/bundler/install/process_lock_spec.rb index 1f8c62f26e..8082ec40fa 100644 --- a/spec/bundler/install/process_lock_spec.rb +++ b/spec/bundler/install/process_lock_spec.rb @@ -8,17 +8,17 @@ RSpec.describe "process lock spec" do thread = Thread.new do Bundler::ProcessLock.lock(default_bundle_path) do sleep 1 # ignore quality_spec - expect(the_bundle).not_to include_gems "rack 1.0" + expect(the_bundle).not_to include_gems "myrack 1.0" end end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G thread.join - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end context "when creating a lock raises Errno::ENOTSUP" do diff --git a/spec/bundler/install/redownload_spec.rb b/spec/bundler/install/redownload_spec.rb index 3a72c356d9..b522e22bd5 100644 --- a/spec/bundler/install/redownload_spec.rb +++ b/spec/bundler/install/redownload_spec.rb @@ -3,29 +3,29 @@ RSpec.describe "bundle install" do before :each do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end shared_examples_for "an option to force redownloading gems" do it "re-installs installed gems" do - rack_lib = default_bundle_path("gems/rack-1.0.0/lib/rack.rb") + myrack_lib = default_bundle_path("gems/myrack-1.0.0/lib/myrack.rb") bundle :install - rack_lib.open("w") {|f| f.write("blah blah blah") } + myrack_lib.open("w") {|f| f.write("blah blah blah") } bundle :install, flag => true - expect(out).to include "Installing rack 1.0.0" - expect(rack_lib.open(&:read)).to eq("RACK = '1.0.0'\n") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(out).to include "Installing myrack 1.0.0" + expect(myrack_lib.open(&:read)).to eq("MYRACK = '1.0.0'\n") + expect(the_bundle).to include_gems "myrack 1.0.0" end it "works on first bundle install" do bundle :install, flag => true - expect(out).to include "Installing rack 1.0.0" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(out).to include "Installing myrack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end context "with a git gem" do @@ -33,7 +33,7 @@ RSpec.describe "bundle install" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G end diff --git a/spec/bundler/install/security_policy_spec.rb b/spec/bundler/install/security_policy_spec.rb index befeb81da5..e7f64dc227 100644 --- a/spec/bundler/install/security_policy_spec.rb +++ b/spec/bundler/install/security_policy_spec.rb @@ -9,8 +9,8 @@ RSpec.describe "policies with unsigned gems" do before do build_security_repo gemfile <<-G - source "#{file_uri_for(security_repo)}" - gem "rack" + source "https://gems.security" + gem "myrack" gem "signed_gem" G end @@ -18,7 +18,7 @@ RSpec.describe "policies with unsigned gems" do it "will work after you try to deploy without a lock" do bundle "install --deployment", raise_on_error: false bundle :install - expect(the_bundle).to include_gems "rack 1.0", "signed_gem 1.0" + expect(the_bundle).to include_gems "myrack 1.0", "signed_gem 1.0" end it "will fail when given invalid security policy" do @@ -45,7 +45,7 @@ RSpec.describe "policies with signed gems and no CA" do before do build_security_repo gemfile <<-G - source "#{file_uri_for(security_repo)}" + source "https://gems.security" gem "signed_gem" G end diff --git a/spec/bundler/install/yanked_spec.rb b/spec/bundler/install/yanked_spec.rb index 5aeabd2f23..b2edd11acd 100644 --- a/spec/bundler/install/yanked_spec.rb +++ b/spec/bundler/install/yanked_spec.rb @@ -10,7 +10,7 @@ RSpec.context "when installing a bundle that includes yanked gems" do it "throws an error when the original gem version is yanked" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: foo (10.0.0) @@ -23,7 +23,7 @@ RSpec.context "when installing a bundle that includes yanked gems" do L install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "foo", "10.0.0" G @@ -35,7 +35,8 @@ RSpec.context "when installing a bundle that includes yanked gems" do skip "Materialization on Windows is not yet strict, so the example does not detect the gem has been yanked" if Gem.win_platform? build_repo4 do - build_gem "foo", "1.0.0", "1.0.1" + build_gem "foo", "1.0.0" + build_gem "foo", "1.0.1" build_gem "actiontext", "6.1.7" do |s| s.add_dependency "nokogiri", ">= 1.8" end @@ -76,10 +77,10 @@ RSpec.context "when installing a bundle that includes yanked gems" do end context "and the old index is used" do - let(:source_uri) { file_uri_for(gem_repo4) } + let(:source_uri) { "https://gem.repo4" } it "reports the yanked gem properly" do - bundle "install", raise_on_error: false + bundle "install", artifice: "endpoint", raise_on_error: false, verbose: true expect(err).to include("Your bundle is locked to nokogiri (1.13.8-#{Bundler.local_platform})") end @@ -100,7 +101,7 @@ RSpec.context "when installing a bundle that includes yanked gems" do bundle "config set force_ruby_platform true" install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "foo", "10.0.0" G @@ -120,7 +121,7 @@ RSpec.context "when resolving a bundle that includes yanked gems, but unlocking lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)} + remote: https://gem.repo4 specs: foo (9.0.0) bar (1.0.0) @@ -137,7 +138,7 @@ RSpec.context "when resolving a bundle that includes yanked gems, but unlocking L gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "foo" gem "bar" G @@ -148,7 +149,7 @@ RSpec.context "when resolving a bundle that includes yanked gems, but unlocking expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: bar (2.0.0) foo (9.0.0) @@ -169,65 +170,65 @@ end RSpec.context "when using gem before installing" do it "does not suggest the author has yanked the gem" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)} + remote: https://gem.repo1 specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (= 0.9.1) + myrack (= 0.9.1) L bundle :list, raise_on_error: false - expect(err).to include("Could not find rack-0.9.1 in locally installed gems") - expect(err).to_not include("Your bundle is locked to rack (0.9.1) from") - expect(err).to_not include("If you haven't changed sources, that means the author of rack (0.9.1) has removed it.") - expect(err).to_not include("You'll need to update your bundle to a different version of rack (0.9.1) that hasn't been removed in order to install.") + expect(err).to include("Could not find myrack-0.9.1 in locally installed gems") + expect(err).to_not include("Your bundle is locked to myrack (0.9.1) from") + expect(err).to_not include("If you haven't changed sources, that means the author of myrack (0.9.1) has removed it.") + expect(err).to_not include("You'll need to update your bundle to a different version of myrack (0.9.1) that hasn't been removed in order to install.") # Check error message is still correct when multiple platforms are locked lockfile lockfile.gsub(/PLATFORMS\n #{lockfile_platforms}/m, "PLATFORMS\n #{lockfile_platforms("ruby")}") bundle :list, raise_on_error: false - expect(err).to include("Could not find rack-0.9.1 in locally installed gems") + expect(err).to include("Could not find myrack-0.9.1 in locally installed gems") end it "does not suggest the author has yanked the gem when using more than one gem, but shows all gems that couldn't be found in the source" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" - gem "rack_middleware", "1.0" + source "https://gem.repo1" + gem "myrack", "0.9.1" + gem "myrack_middleware", "1.0" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)} + remote: https://gem.repo1 specs: - rack (0.9.1) - rack_middleware (1.0) + myrack (0.9.1) + myrack_middleware (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (= 0.9.1) - rack_middleware (1.0) + myrack (= 0.9.1) + myrack_middleware (1.0) L bundle :list, raise_on_error: false - expect(err).to include("Could not find rack-0.9.1, rack_middleware-1.0 in locally installed gems") + expect(err).to include("Could not find myrack-0.9.1, myrack_middleware-1.0 in locally installed gems") expect(err).to include("Install missing gems with `bundle install`.") - expect(err).to_not include("Your bundle is locked to rack (0.9.1) from") - expect(err).to_not include("If you haven't changed sources, that means the author of rack (0.9.1) has removed it.") - expect(err).to_not include("You'll need to update your bundle to a different version of rack (0.9.1) that hasn't been removed in order to install.") + expect(err).to_not include("Your bundle is locked to myrack (0.9.1) from") + expect(err).to_not include("If you haven't changed sources, that means the author of myrack (0.9.1) has removed it.") + expect(err).to_not include("You'll need to update your bundle to a different version of myrack (0.9.1) that hasn't been removed in order to install.") end end diff --git a/spec/bundler/lock/git_spec.rb b/spec/bundler/lock/git_spec.rb index ad13e8ffc6..13c661ae14 100644 --- a/spec/bundler/lock/git_spec.rb +++ b/spec/bundler/lock/git_spec.rb @@ -5,7 +5,7 @@ RSpec.describe "bundle lock with git gems" do build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{lib_path("foo-1.0")}" G end @@ -24,7 +24,7 @@ RSpec.describe "bundle lock with git gems" do it "prints a proper error when changing a locked Gemfile to point to a bad branch" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{lib_path("foo-1.0")}", :branch => "bad" G @@ -42,7 +42,7 @@ RSpec.describe "bundle lock with git gems" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -87,7 +87,7 @@ RSpec.describe "bundle lock with git gems" do git "branch -D foo ", lib_path("foo-1.0") gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{lib_path("foo-1.0")}" G @@ -99,7 +99,7 @@ RSpec.describe "bundle lock with git gems" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -123,7 +123,7 @@ RSpec.describe "bundle lock with git gems" do annotated_tag = git("rev-parse v1.0", lib_path("foo-1.0")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{lib_path("foo-1.0")}" G @@ -135,7 +135,7 @@ RSpec.describe "bundle lock with git gems" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index 4fd081e7d0..1f7faecd61 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -7,26 +7,26 @@ RSpec.describe "the lockfile format" do it "generates a simple lockfile for a single source, gem" do checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo2, "rack", "1.0.0") + c.checksum(gem_repo2, "myrack", "1.0.0") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack" + gem "myrack" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -43,25 +43,25 @@ RSpec.describe "the lockfile format" do specs: GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES omg! - rack + myrack BUNDLED WITH 1.8.2 L install_gemfile <<-G, verbose: true, env: { "BUNDLER_VERSION" => Bundler::VERSION } - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack" + gem "myrack" G expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with 1.8.2.") @@ -69,44 +69,50 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{Bundler::VERSION} G end - it "does not update the lockfile's bundler version if nothing changed during bundle install, but uses the locked version", rubygems: ">= 3.3.0.a", realworld: true do + it "does not update the lockfile's bundler version if nothing changed during bundle install, but uses the locked version", rubygems: ">= 3.3.0.a" do version = "2.3.0" + build_repo4 do + build_gem "myrack", "1.0.0" + + build_bundler version + end + lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo4/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{version} L - install_gemfile <<-G, verbose: true, artifice: "vcr" - source "#{file_uri_for(gem_repo2)}" + install_gemfile <<-G, verbose: true, preserve_ruby_flags: true + source "https://gem.repo4" - gem "rack" + gem "myrack" G expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{version}.") @@ -114,15 +120,15 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo4/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{version} @@ -132,30 +138,36 @@ RSpec.describe "the lockfile format" do it "does not update the lockfile's bundler version if nothing changed during bundle install, and uses the latest version", rubygems: "< 3.3.0.a" do version = "#{Bundler::VERSION.split(".").first}.0.0.a" + build_repo4 do + build_gem "myrack", "1.0.0" + + build_bundler version + end + checksums = checksums_section do |c| - c.checksum(gem_repo2, "rack", "1.0.0") + c.checksum(gem_repo4, "myrack", "1.0.0") end lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo4/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{version} L install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo4" - gem "rack" + gem "myrack" G expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{version}.") @@ -163,15 +175,15 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo4/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{version} @@ -181,34 +193,34 @@ RSpec.describe "the lockfile format" do it "adds the BUNDLED WITH section if not present" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack L install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" - gem "rack", "> 0" + gem "myrack", "> 0" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (> 0) + myrack (> 0) BUNDLED WITH #{Bundler::VERSION} @@ -223,39 +235,39 @@ RSpec.describe "the lockfile format" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{older_major} L install_gemfile <<-G, env: { "BUNDLER_VERSION" => Bundler::VERSION } - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack" + gem "myrack" G expect(err).to be_empty expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{current_version} @@ -264,29 +276,29 @@ RSpec.describe "the lockfile format" do it "generates a simple lockfile for a single source, gem with dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack-obama" + gem "myrack-obama" G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo2, "rack", "1.0.0" - c.checksum gem_repo2, "rack-obama", "1.0" + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack-obama + myrack-obama #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -295,29 +307,29 @@ RSpec.describe "the lockfile format" do it "generates a simple lockfile for a single source, gem with a version requirement" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack-obama", ">= 1.0" + gem "myrack-obama", ">= 1.0" G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo2, "rack", "1.0.0" - c.checksum gem_repo2, "rack-obama", "1.0" + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack-obama (>= 1.0) + myrack-obama (>= 1.0) #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -325,55 +337,169 @@ RSpec.describe "the lockfile format" do end it "generates a lockfile without credentials" do - bundle "config set http://localgemserver.test/ user:pass" + bundle "config set https://localgemserver.test/ user:pass" install_gemfile(<<-G, artifice: "endpoint_strict_basic_authentication", quiet: true) - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" - source "http://localgemserver.test/" do + source "https://localgemserver.test/" do end - source "http://user:[email protected]/" do - gem "rack-obama", ">= 1.0" + source "https://user:[email protected]/" do + gem "myrack-obama", ">= 1.0" end G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo2, "rack", "1.0.0" - c.checksum gem_repo2, "rack-obama", "1.0" + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: GEM + remote: https://localgemserver.test/ + specs: + + GEM + remote: https://othergemserver.test/ + specs: + myrack (1.0.0) + myrack-obama (1.0) + myrack + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + myrack-obama (>= 1.0)! + #{checksums} + BUNDLED WITH + #{Bundler::VERSION} + G + end + + it "does not add credentials to lockfile when it does not have them already" do + bundle "config set http://localgemserver.test/ user:pass" + + gemfile <<~G + source "https://gem.repo1" + + source "http://localgemserver.test/" do + + end + + source "http://user:[email protected]/" do + gem "myrack-obama", ">= 1.0" + end + G + + checksums = checksums_section_when_existing do |c| + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" + end + + lockfile_without_credentials = <<~L + GEM remote: http://localgemserver.test/ specs: GEM remote: http://othergemserver.test/ specs: - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack + + GEM + remote: https://gem.repo1/ + specs: PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack-obama (>= 1.0)! + myrack-obama (>= 1.0)! #{checksums} BUNDLED WITH #{Bundler::VERSION} + L + + lockfile lockfile_without_credentials + + # when not re-resolving + bundle "install", artifice: "endpoint_strict_basic_authentication", quiet: true + expect(lockfile).to eq lockfile_without_credentials + + # when re-resolving with full unlock + bundle "update", artifice: "endpoint_strict_basic_authentication" + expect(lockfile).to eq lockfile_without_credentials + + # when re-resolving without ful unlocking + bundle "update myrack-obama", artifice: "endpoint_strict_basic_authentication" + expect(lockfile).to eq lockfile_without_credentials + end + + it "keeps credentials in lockfile if already there" do + bundle "config set http://localgemserver.test/ user:pass" + + gemfile <<~G + source "https://gem.repo1" + + source "http://localgemserver.test/" do + + end + + source "http://user:[email protected]/" do + gem "myrack-obama", ">= 1.0" + end G + + checksums = checksums_section_when_existing do |c| + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" + end + + lockfile_with_credentials = <<~L + GEM + remote: http://localgemserver.test/ + specs: + + GEM + remote: http://user:[email protected]/ + specs: + myrack (1.0.0) + myrack-obama (1.0) + myrack + + GEM + remote: https://gem.repo1/ + specs: + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + myrack-obama (>= 1.0)! + #{checksums} + BUNDLED WITH + #{Bundler::VERSION} + L + + lockfile lockfile_with_credentials + + bundle "install", artifice: "endpoint_strict_basic_authentication", quiet: true + + expect(lockfile).to eq lockfile_with_credentials end it "generates lockfiles with multiple requirements" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" gem "net-sftp" G @@ -384,7 +510,7 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: net-sftp (1.1.1) net-ssh (>= 1.0.0, < 1.99.0) @@ -407,7 +533,7 @@ RSpec.describe "the lockfile format" do git = build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -423,7 +549,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -441,13 +567,13 @@ RSpec.describe "the lockfile format" do build_lib "omg", path: lib_path("omg") gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" platforms :#{not_local_tag} do gem "omg", :path => "#{lib_path("omg")}" end - gem "rack" + gem "myrack" G lockfile <<-L @@ -457,23 +583,23 @@ RSpec.describe "the lockfile format" do specs: GEM - remote: #{file_uri_for(gem_repo2)}// + remote: https://gem.repo2// specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{not_local} DEPENDENCIES omg! - rack + myrack BUNDLED WITH #{Bundler::VERSION} L bundle "install" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "serializes global git sources" do @@ -484,7 +610,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}" do gem "foo" end @@ -498,7 +624,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -521,7 +647,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "omg" G @@ -534,7 +660,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -557,7 +683,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}", :tag => "omg" G @@ -570,7 +696,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -600,7 +726,7 @@ RSpec.describe "the lockfile format" do s.add_dependency "orm_adapter" end - update_git "ckeditor", path: lib_path("ckeditor"), remote: file_uri_for(@remote.path) + update_git "ckeditor", path: lib_path("ckeditor"), remote: @remote.path update_git "ckeditor", path: lib_path("ckeditor"), tag: "v4.0.7" old_git = update_git "ckeditor", path: lib_path("ckeditor"), push: "v4.0.7" @@ -614,7 +740,7 @@ RSpec.describe "the lockfile format" do new_git = update_git "ckeditor", path: lib_path("ckeditor"), push: "v4.0.8" gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "ckeditor", :git => "#{@remote.path}", :tag => "v4.0.8" G @@ -628,7 +754,7 @@ RSpec.describe "the lockfile format" do orm_adapter GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: orm_adapter (0.4.1) @@ -655,7 +781,7 @@ RSpec.describe "the lockfile format" do orm_adapter GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: orm_adapter (0.4.1) @@ -678,7 +804,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" G @@ -689,7 +815,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -711,7 +837,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :path => "#{lib_path("foo-1.0")}" G @@ -726,7 +852,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -747,13 +873,13 @@ RSpec.describe "the lockfile format" do checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" c.no_checksum "bar", "1.0" - c.checksum gem_repo2, "rack", "1.0.0" + c.checksum gem_repo2, "myrack", "1.0.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack" + gem "myrack" gem "foo", :path => "#{lib_path("foo-1.0")}" gem "bar", :git => "#{lib_path("bar-1.0")}" G @@ -771,9 +897,9 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} @@ -781,7 +907,7 @@ RSpec.describe "the lockfile format" do DEPENDENCIES bar! foo! - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -790,26 +916,26 @@ RSpec.describe "the lockfile format" do it "removes redundant sources" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack", :source => "#{file_uri_for(gem_repo2)}/" + gem "myrack", :source => "https://gem.repo2/" G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo2, "rack", "1.0.0" + c.checksum gem_repo2, "myrack", "1.0.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack! + myrack! #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -818,40 +944,40 @@ RSpec.describe "the lockfile format" do it "lists gems alphabetically" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" gem "thin" gem "actionpack" - gem "rack-obama" + gem "myrack-obama" G checksums = checksums_section_when_existing do |c| c.checksum gem_repo2, "actionpack", "2.3.2" c.checksum gem_repo2, "activesupport", "2.3.2" - c.checksum gem_repo2, "rack", "1.0.0" - c.checksum gem_repo2, "rack-obama", "1.0" + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" c.checksum gem_repo2, "thin", "1.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: actionpack (2.3.2) activesupport (= 2.3.2) activesupport (2.3.2) - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack thin (1.0) - rack + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES actionpack - rack-obama + myrack-obama thin #{checksums} BUNDLED WITH @@ -861,7 +987,7 @@ RSpec.describe "the lockfile format" do it "orders dependencies' dependencies in alphabetical order" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" gem "rails" G @@ -878,7 +1004,7 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: actionmailer (2.3.2) activesupport (= 2.3.2) @@ -920,7 +1046,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2" gem 'double_deps' G @@ -931,7 +1057,7 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: double_deps (1.0) net-ssh @@ -951,29 +1077,29 @@ RSpec.describe "the lockfile format" do it "does not add the :require option to the lockfile" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack-obama", ">= 1.0", :require => "rack/obama" + gem "myrack-obama", ">= 1.0", :require => "myrack/obama" G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo2, "rack", "1.0.0" - c.checksum gem_repo2, "rack-obama", "1.0" + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack-obama (>= 1.0) + myrack-obama (>= 1.0) #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -982,29 +1108,29 @@ RSpec.describe "the lockfile format" do it "does not add the :group option to the lockfile" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack-obama", ">= 1.0", :group => :test + gem "myrack-obama", ">= 1.0", :group => :test G checksums = checksums_section_when_existing do |c| - c.checksum gem_repo2, "rack", "1.0.0" - c.checksum gem_repo2, "rack-obama", "1.0" + c.checksum gem_repo2, "myrack", "1.0.0" + c.checksum gem_repo2, "myrack-obama", "1.0" end expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) - rack-obama (1.0) - rack + myrack (1.0.0) + myrack-obama (1.0) + myrack PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack-obama (>= 1.0) + myrack-obama (>= 1.0) #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -1019,7 +1145,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "foo" do gem "foo" end @@ -1032,7 +1158,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1054,7 +1180,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "../foo" do gem "foo" end @@ -1067,7 +1193,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1089,7 +1215,7 @@ RSpec.describe "the lockfile format" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path File.expand_path("foo", __dir__) do gem "foo" end @@ -1102,7 +1228,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1117,14 +1243,14 @@ RSpec.describe "the lockfile format" do end it "stores relative paths when the path is provided for gemspec" do - build_lib("foo", path: tmp.join("foo")) + build_lib("foo", path: tmp("foo")) checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "1.0" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec :path => "../foo" G @@ -1135,7 +1261,7 @@ RSpec.describe "the lockfile format" do foo (1.0) GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: PLATFORMS @@ -1151,51 +1277,51 @@ RSpec.describe "the lockfile format" do it "keeps existing platforms in the lockfile" do checksums = checksums_section_when_existing do |c| - c.no_checksum "rack", "1.0.0" + c.no_checksum "myrack", "1.0.0" end lockfile <<-G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS java DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} G install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" - gem "rack" + gem "myrack" G - checksums.checksum(gem_repo2, "rack", "1.0.0") + checksums.checksum(gem_repo2, "myrack", "1.0.0") expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms("java", local_platform, defaults: [])} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} G end - it "adds compatible platform specific variants to the lockfile, even if resolution fallback to RUBY due to some other incompatible platform specific variant" do + it "adds compatible platform specific variants to the lockfile, even if resolution fallback to ruby due to some other incompatible platform specific variant" do simulate_platform "arm64-darwin-23" do build_repo4 do build_gem "google-protobuf", "3.25.1" @@ -1209,14 +1335,14 @@ RSpec.describe "the lockfile format" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "google-protobuf" G bundle "lock --add-platform x64-mingw-ucrt" expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: google-protobuf (3.25.1) google-protobuf (3.25.1-arm64-darwin-23) @@ -1245,7 +1371,7 @@ RSpec.describe "the lockfile format" do simulate_platform "universal-java-16" install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "platform_specific" G @@ -1255,7 +1381,7 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: platform_specific (1.0-universal-java-16) @@ -1273,33 +1399,33 @@ RSpec.describe "the lockfile format" do it "does not add duplicate gems" do checksums = checksums_section_when_existing do |c| c.checksum(gem_repo2, "activesupport", "2.3.5") - c.checksum(gem_repo2, "rack", "1.0.0") + c.checksum(gem_repo2, "myrack", "1.0.0") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - gem "rack" + source "https://gem.repo2/" + gem "myrack" G install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - gem "rack" + source "https://gem.repo2/" + gem "myrack" gem "activesupport" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: activesupport (2.3.5) - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES activesupport - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -1308,26 +1434,26 @@ RSpec.describe "the lockfile format" do it "does not add duplicate dependencies" do checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo2, "rack", "1.0.0") + c.checksum(gem_repo2, "myrack", "1.0.0") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - gem "rack" - gem "rack" + source "https://gem.repo2/" + gem "myrack" + gem "myrack" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -1336,26 +1462,26 @@ RSpec.describe "the lockfile format" do it "does not add duplicate dependencies with versions" do checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo2, "rack", "1.0.0") + c.checksum(gem_repo2, "myrack", "1.0.0") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - gem "rack", "1.0" - gem "rack", "1.0" + source "https://gem.repo2/" + gem "myrack", "1.0" + gem "myrack", "1.0" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (= 1.0) + myrack (= 1.0) #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -1364,26 +1490,26 @@ RSpec.describe "the lockfile format" do it "does not add duplicate dependencies in different groups" do checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo2, "rack", "1.0.0") + c.checksum(gem_repo2, "myrack", "1.0.0") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - gem "rack", "1.0", :group => :one - gem "rack", "1.0", :group => :two + source "https://gem.repo2/" + gem "myrack", "1.0", :group => :one + gem "myrack", "1.0", :group => :two G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (= 1.0) + myrack (= 1.0) #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -1392,47 +1518,47 @@ RSpec.describe "the lockfile format" do it "raises if two different versions are used" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}/" - gem "rack", "1.0" - gem "rack", "1.1" + source "https://gem.repo2/" + gem "myrack", "1.0" + gem "myrack", "1.1" G expect(bundled_app_lock).not_to exist - expect(err).to include "rack (= 1.0) and rack (= 1.1)" + expect(err).to include "myrack (= 1.0) and myrack (= 1.1)" end it "raises if two different sources are used" do install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}/" - gem "rack" - gem "rack", :git => "git://hubz.com" + source "https://gem.repo2/" + gem "myrack" + gem "myrack", :git => "git://hubz.com" G expect(bundled_app_lock).not_to exist - expect(err).to include "rack (>= 0) should come from an unspecified source and git://hubz.com" + expect(err).to include "myrack (>= 0) should come from an unspecified source and git://hubz.com" end it "works correctly with multiple version dependencies" do checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo2, "rack", "0.9.1") + c.checksum(gem_repo2, "myrack", "0.9.1") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - gem "rack", "> 0.9", "< 1.0" + source "https://gem.repo2/" + gem "myrack", "> 0.9", "< 1.0" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (> 0.9, < 1.0) + myrack (> 0.9, < 1.0) #{checksums} BUNDLED WITH #{Bundler::VERSION} @@ -1441,26 +1567,26 @@ RSpec.describe "the lockfile format" do it "captures the Ruby version in the lockfile" do checksums = checksums_section_when_existing do |c| - c.checksum(gem_repo2, "rack", "0.9.1") + c.checksum(gem_repo2, "myrack", "0.9.1") end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" + source "https://gem.repo2/" ruby '#{Gem.ruby_version}' - gem "rack", "> 0.9", "< 1.0" + gem "myrack", "> 0.9", "< 1.0" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack (> 0.9, < 1.0) + myrack (> 0.9, < 1.0) #{checksums} RUBY VERSION #{Bundler::RubyVersion.system} @@ -1473,24 +1599,24 @@ RSpec.describe "the lockfile format" do it "raises a helpful error message when the lockfile is missing deps" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack_middleware (1.0) + myrack_middleware (1.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack_middleware + myrack_middleware L install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}" - gem "rack_middleware" + source "https://gem.repo2" + gem "myrack_middleware" G - expect(err).to include("Downloading rack_middleware-1.0 revealed dependencies not in the API or the lockfile (#{Gem::Dependency.new("rack", "= 0.9.1")})."). - and include("Running `bundle update rack_middleware` should fix the problem.") + expect(err).to include("Downloading myrack_middleware-1.0 revealed dependencies not in the API or the lockfile (#{Gem::Dependency.new("myrack", "= 0.9.1")})."). + and include("Running `bundle update myrack_middleware` should fix the problem.") end it "regenerates a lockfile with no specs" do @@ -1506,7 +1632,7 @@ RSpec.describe "the lockfile format" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: PLATFORMS @@ -1520,14 +1646,14 @@ RSpec.describe "the lockfile format" do G install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "direct_dependency" G expect(lockfile).to eq <<~G GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: direct_dependency (4.5.6) indirect_dependency @@ -1555,14 +1681,14 @@ RSpec.describe "the lockfile format" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "minitest-bisect" G # Corrupt lockfile (completely missing path_expander) lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: minitest-bisect (1.6.0) @@ -1581,7 +1707,7 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: minitest-bisect (1.6.0) path_expander (~> 1.1) @@ -1621,13 +1747,13 @@ RSpec.describe "the lockfile format" do end gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "minitest-bisect" G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: minitest-bisect (1.6.0) path_expander (~> 1.1) @@ -1647,7 +1773,7 @@ RSpec.describe "the lockfile format" do expect(lockfile).to eq <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: minitest-bisect (1.6.0) path_expander (~> 1.1) @@ -1673,36 +1799,36 @@ RSpec.describe "the lockfile format" do build_repo2 install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" + source "https://gem.repo2" + gem "myrack" G set_lockfile_mtime_to_known_value end it "generates Gemfile.lock with \\n line endings" do expect(File.read(bundled_app_lock)).not_to match("\r\n") - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end context "during updates" do it "preserves Gemfile.lock \\n line endings" do update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end expect { bundle "update", all: true }.to change { File.mtime(bundled_app_lock) } expect(File.read(bundled_app_lock)).not_to match("\r\n") - expect(the_bundle).to include_gems "rack 1.2" + expect(the_bundle).to include_gems "myrack 1.2" end it "preserves Gemfile.lock \\n\\r line endings" do skip "needs to be adapted" if Gem.win_platform? update_repo2 do - build_gem "rack", "1.2" do |s| - s.executables = "rackup" + build_gem "myrack", "1.2" do |s| + s.executables = "myrackup" end end @@ -1713,7 +1839,7 @@ RSpec.describe "the lockfile format" do expect { bundle "update", all: true }.to change { File.mtime(bundled_app_lock) } expect(File.read(bundled_app_lock)).to match("\r\n") - expect(the_bundle).to include_gems "rack 1.2" + expect(the_bundle).to include_gems "myrack 1.2" end end @@ -1745,27 +1871,27 @@ RSpec.describe "the lockfile format" do it "refuses to install if Gemfile.lock contains conflict markers" do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}// + remote: https://gem.repo2// specs: <<<<<<< - rack (1.0.0) + myrack (1.0.0) ======= - rack (1.0.1) + myrack (1.0.1) >>>>>>> PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{Bundler::VERSION} L install_gemfile <<-G, raise_on_error: false - source "#{file_uri_for(gem_repo2)}/" - gem "rack" + source "https://gem.repo2/" + gem "myrack" G expect(err).to match(/your Gemfile.lock contains merge conflicts/i) diff --git a/spec/bundler/other/ext_spec.rb b/spec/bundler/other/ext_spec.rb index 4d954b474f..9fc0414b4d 100644 --- a/spec/bundler/other/ext_spec.rb +++ b/spec/bundler/other/ext_spec.rb @@ -53,8 +53,8 @@ end RSpec.describe "Gem::SourceIndex#refresh!" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index e7577d38b4..192dc7413e 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -6,8 +6,8 @@ RSpec.describe "major deprecations" do describe "Bundler" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -114,8 +114,8 @@ RSpec.describe "major deprecations" do context "bundle check --path" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "check --path vendor/bundle", raise_on_error: false @@ -136,8 +136,8 @@ RSpec.describe "major deprecations" do context "bundle check --path=" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "check --path=vendor/bundle", raise_on_error: false @@ -158,8 +158,8 @@ RSpec.describe "major deprecations" do context "bundle cache --all" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "cache --all", raise_on_error: false @@ -180,8 +180,8 @@ RSpec.describe "major deprecations" do context "bundle cache --path" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "cache --path foo", raise_on_error: false @@ -300,8 +300,8 @@ RSpec.describe "major deprecations" do describe "bundle update" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -321,8 +321,8 @@ RSpec.describe "major deprecations" do describe "bundle install --binstubs" do before do install_gemfile <<-G, binstubs: true - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -335,9 +335,9 @@ RSpec.describe "major deprecations" do context "bundle install with both gems.rb and Gemfile present" do it "should not warn about gems.rb" do - create_file "gems.rb", <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + gemfile "gems.rb", <<-G + source "https://gem.repo1" + gem "myrack" G bundle :install @@ -345,17 +345,17 @@ RSpec.describe "major deprecations" do end it "should print a proper warning, and use gems.rb" do - create_file "gems.rb", "source \"#{file_uri_for(gem_repo1)}\"" + gemfile "gems.rb", "source 'https://gem.repo1'" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G expect(warnings).to include( "Multiple gemfiles (gems.rb and Gemfile) detected. Make sure you remove Gemfile and Gemfile.lock since bundler is ignoring them in favor of gems.rb and gems.locked." ) - expect(the_bundle).not_to include_gem "rack 1.0" + expect(the_bundle).not_to include_gem "myrack 1.0" end end @@ -364,8 +364,8 @@ RSpec.describe "major deprecations" do bundle "config set --local path vendor/bundle" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -407,8 +407,8 @@ RSpec.describe "major deprecations" do context "bundle install with multiple sources" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo3)}" - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo3" + source "https://gem.repo1" G end @@ -455,28 +455,28 @@ RSpec.describe "major deprecations" do context "bundle install in frozen mode with a lockfile with a single rubygems section with multiple remotes" do before do build_repo gem_repo3 do - build_gem "rack", "0.9.1" + build_gem "myrack", "0.9.1" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - source "#{file_uri_for(gem_repo3)}" do - gem 'rack' + source "https://gem.repo1" + source "https://gem.repo3" do + gem 'myrack' end G lockfile <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ - remote: #{file_uri_for(gem_repo3)}/ + remote: https://gem.repo1/ + remote: https://gem.repo3/ specs: - rack (0.9.1) + myrack (0.9.1) PLATFORMS ruby DEPENDENCIES - rack! + myrack! BUNDLED WITH #{Bundler::VERSION} @@ -496,10 +496,10 @@ RSpec.describe "major deprecations" do context "when Bundler.setup is run in a ruby script" do before do - create_file "gems.rb", "source \"#{file_uri_for(gem_repo1)}\"" + create_file "gems.rb", "source 'https://gem.repo1'" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :group => :test + source "https://gem.repo1" + gem "myrack", :group => :test G ruby <<-RUBY @@ -537,8 +537,8 @@ RSpec.describe "major deprecations" do context "bundle show" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -558,14 +558,14 @@ RSpec.describe "major deprecations" do context "bundle remove" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end context "with --install" do it "shows a deprecation warning", bundler: "< 3" do - bundle "remove rack --install" + bundle "remove myrack --install" expect(err).to include "[DEPRECATED] The `--install` flag has been deprecated. `bundle install` is triggered by default." end @@ -590,7 +590,7 @@ RSpec.describe "major deprecations" do context "bundle viz", :realworld do before do realworld_system_gems "ruby-graphviz --version 1.2.5" - create_file "gems.rb", "source \"#{file_uri_for(gem_repo1)}\"" + create_file "gems.rb", "source 'https://gem.repo1'" bundle "viz" end diff --git a/spec/bundler/plugins/command_spec.rb b/spec/bundler/plugins/command_spec.rb index af132d6550..f8dacb0e51 100644 --- a/spec/bundler/plugins/command_spec.rb +++ b/spec/bundler/plugins/command_spec.rb @@ -18,7 +18,7 @@ RSpec.describe "command plugins" do end end - bundle "plugin install command-mah --source #{file_uri_for(gem_repo2)}" + bundle "plugin install command-mah --source https://gem.repo2" end it "executes without arguments" do @@ -29,7 +29,7 @@ RSpec.describe "command plugins" do end it "accepts the arguments" do - build_repo2 do + update_repo2 do build_plugin "the-echoer" do |s| s.write "plugins.rb", <<-RUBY module Resonance @@ -46,7 +46,7 @@ RSpec.describe "command plugins" do end end - bundle "plugin install the-echoer --source #{file_uri_for(gem_repo2)}" + bundle "plugin install the-echoer --source https://gem.repo2" expect(out).to include("Installed plugin the-echoer") bundle "echo tacos tofu lasange" @@ -54,7 +54,7 @@ RSpec.describe "command plugins" do end it "raises error on redeclaration of command" do - build_repo2 do + update_repo2 do build_plugin "copycat" do |s| s.write "plugins.rb", <<-RUBY module CopyCat @@ -69,7 +69,7 @@ RSpec.describe "command plugins" do end end - bundle "plugin install copycat --source #{file_uri_for(gem_repo2)}", raise_on_error: false + bundle "plugin install copycat --source https://gem.repo2", raise_on_error: false expect(out).not_to include("Installed plugin copycat") diff --git a/spec/bundler/plugins/hook_spec.rb b/spec/bundler/plugins/hook_spec.rb index 72feb14d84..c351377253 100644 --- a/spec/bundler/plugins/hook_spec.rb +++ b/spec/bundler/plugins/hook_spec.rb @@ -13,17 +13,17 @@ RSpec.describe "hook plugins" do end end - bundle "plugin install before-install-all-plugin --source #{file_uri_for(gem_repo2)}" + bundle "plugin install before-install-all-plugin --source https://gem.repo2" end it "runs before all rubygems are installed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" - gem "rack" + gem "myrack" G - expect(out).to include "gems to be installed rake, rack" + expect(out).to include "gems to be installed rake, myrack" end end @@ -39,18 +39,18 @@ RSpec.describe "hook plugins" do end end - bundle "plugin install before-install-plugin --source #{file_uri_for(gem_repo2)}" + bundle "plugin install before-install-plugin --source https://gem.repo2" end it "runs before each rubygem is installed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" - gem "rack" + gem "myrack" G expect(out).to include "installing gem rake" - expect(out).to include "installing gem rack" + expect(out).to include "installing gem myrack" end end @@ -66,17 +66,17 @@ RSpec.describe "hook plugins" do end end - bundle "plugin install after-install-all-plugin --source #{file_uri_for(gem_repo2)}" + bundle "plugin install after-install-all-plugin --source https://gem.repo2" end - it "runs after each rubygem is installed" do + it "runs after each all rubygems are installed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" - gem "rack" + gem "myrack" G - expect(out).to include "installed gems rake, rack" + expect(out).to include "installed gems rake, myrack" end end @@ -92,18 +92,18 @@ RSpec.describe "hook plugins" do end end - bundle "plugin install after-install-plugin --source #{file_uri_for(gem_repo2)}" + bundle "plugin install after-install-plugin --source https://gem.repo2" end it "runs after each rubygem is installed" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" - gem "rack" + gem "myrack" G expect(out).to include "installed gem rake : installed" - expect(out).to include "installed gem rack : installed" + expect(out).to include "installed gem myrack : installed" end end end diff --git a/spec/bundler/plugins/install_spec.rb b/spec/bundler/plugins/install_spec.rb index 20c2f1fd26..d0de607e6c 100644 --- a/spec/bundler/plugins/install_spec.rb +++ b/spec/bundler/plugins/install_spec.rb @@ -9,28 +9,28 @@ RSpec.describe "bundler plugin install" do end it "shows proper message when gem in not found in the source" do - bundle "plugin install no-foo --source #{file_uri_for(gem_repo1)}", raise_on_error: false + bundle "plugin install no-foo --source https://gem.repo1", raise_on_error: false expect(err).to include("Could not find") plugin_should_not_be_installed("no-foo") end it "installs from rubygems source" do - bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo --source https://gem.repo2" expect(out).to include("Installed plugin foo") plugin_should_be_installed("foo") end it "installs from rubygems source in frozen mode" do - bundle "plugin install foo --source #{file_uri_for(gem_repo2)}", env: { "BUNDLE_DEPLOYMENT" => "true" } + bundle "plugin install foo --source https://gem.repo2", env: { "BUNDLE_DEPLOYMENT" => "true" } expect(out).to include("Installed plugin foo") plugin_should_be_installed("foo") end it "installs from sources configured as Gem.sources without any flags" do - bundle "plugin install foo", env: { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } + bundle "plugin install foo", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_SOURCES" => "https://gem.repo2" } expect(out).to include("Installed plugin foo") plugin_should_be_installed("foo") @@ -45,18 +45,18 @@ RSpec.describe "bundler plugin install" do context "plugin is already installed" do before do - bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo --source https://gem.repo2" end it "doesn't install plugin again" do - bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo --source https://gem.repo2" expect(out).not_to include("Installing plugin foo") expect(out).not_to include("Installed plugin foo") end end it "installs multiple plugins" do - bundle "plugin install foo kung-foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo kung-foo --source https://gem.repo2" expect(out).to include("Installed plugin foo") expect(out).to include("Installed plugin kung-foo") @@ -70,7 +70,7 @@ RSpec.describe "bundler plugin install" do build_plugin "kung-foo", "1.1" end - bundle "plugin install foo kung-foo --version '1.0' --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo kung-foo --version '1.0' --source https://gem.repo2" expect(out).to include("Installing foo 1.0") expect(out).to include("Installing kung-foo 1.0") @@ -82,18 +82,18 @@ RSpec.describe "bundler plugin install" do build_plugin "foo", "1.1" end - bundle "plugin install foo --version 1.0 --source #{file_uri_for(gem_repo2)} --verbose" + bundle "plugin install foo --version 1.0 --source https://gem.repo2 --verbose" expect(out).to include("Installing foo 1.0") - bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --verbose" + bundle "plugin install foo --source https://gem.repo2 --verbose" expect(out).to include("Installing foo 1.1") - bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --verbose" + bundle "plugin install foo --source https://gem.repo2 --verbose" expect(out).to include("Using foo 1.1") end it "raises an error when when --branch specified" do - bundle "plugin install foo --branch main --source #{file_uri_for(gem_repo2)}", raise_on_error: false + bundle "plugin install foo --branch main --source https://gem.repo2", raise_on_error: false expect(out).not_to include("Installed plugin foo") @@ -101,13 +101,13 @@ RSpec.describe "bundler plugin install" do end it "raises an error when --ref specified" do - bundle "plugin install foo --ref v1.2.3 --source #{file_uri_for(gem_repo2)}", raise_on_error: false + bundle "plugin install foo --ref v1.2.3 --source https://gem.repo2", raise_on_error: false expect(err).to include("--ref can only be used with git sources") end it "raises error when both --branch and --ref options are specified" do - bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --branch main --ref v1.2.3", raise_on_error: false + bundle "plugin install foo --source https://gem.repo2 --branch main --ref v1.2.3", raise_on_error: false expect(out).not_to include("Installed plugin foo") @@ -131,7 +131,7 @@ RSpec.describe "bundler plugin install" do s.write("src/fubar.rb") end end - bundle "plugin install testing --source #{file_uri_for(gem_repo2)}" + bundle "plugin install testing --source https://gem.repo2" bundle "check2", "no-color" => false expect(out).to eq("mate") @@ -144,17 +144,17 @@ RSpec.describe "bundler plugin install" do build_plugin "kung-foo", "1.1" end - bundle "plugin install foo kung-foo --version '1.0' --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo kung-foo --version '1.0' --source https://gem.repo2" expect(out).to include("Installing foo 1.0") expect(out).to include("Installing kung-foo 1.0") plugin_should_be_installed("foo", "kung-foo") - build_repo2 do + update_repo2 do build_gem "charlie" end - bundle "plugin install charlie --source #{file_uri_for(gem_repo2)}", raise_on_error: false + bundle "plugin install charlie --source https://gem.repo2", raise_on_error: false expect(err).to include("Failed to install plugin `charlie`, due to Bundler::Plugin::MalformattedPlugin (plugins.rb was not found in the plugin.)") @@ -173,7 +173,7 @@ RSpec.describe "bundler plugin install" do end end - bundle "plugin install chaplin --source #{file_uri_for(gem_repo2)}", raise_on_error: false + bundle "plugin install chaplin --source https://gem.repo2", raise_on_error: false expect(global_plugin_gem("chaplin-1.0")).not_to be_directory @@ -187,7 +187,7 @@ RSpec.describe "bundler plugin install" do s.write "plugins.rb" end - bundle "plugin install foo --git #{file_uri_for(lib_path("foo-1.0"))}" + bundle "plugin install foo --git #{lib_path("foo-1.0")}" expect(out).to include("Installed plugin foo") plugin_should_be_installed("foo") @@ -257,9 +257,9 @@ RSpec.describe "bundler plugin install" do it "installs plugins listed in gemfile" do gemfile <<-G - source '#{file_uri_for(gem_repo2)}' + source 'https://gem.repo2' plugin 'foo' - gem 'rack', "1.0.0" + gem 'myrack', "1.0.0" G bundle "install" @@ -268,7 +268,7 @@ RSpec.describe "bundler plugin install" do expect(out).to include("Bundle complete!") - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") plugin_should_be_installed("foo") end @@ -278,7 +278,7 @@ RSpec.describe "bundler plugin install" do end gemfile <<-G - source '#{file_uri_for(gem_repo2)}' + source 'https://gem.repo2' plugin 'foo', "1.0" G @@ -297,7 +297,7 @@ RSpec.describe "bundler plugin install" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" plugin 'ga-plugin', :git => "#{lib_path("ga-plugin-1.0")}" G @@ -311,7 +311,7 @@ RSpec.describe "bundler plugin install" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" plugin 'ga-plugin', :path => "#{lib_path("ga-plugin-1.0")}" G @@ -326,7 +326,7 @@ RSpec.describe "bundler plugin install" do path = lib_path("ga-plugin-1.0").relative_path_from(bundled_app) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" plugin 'ga-plugin', :path => "#{path}" G @@ -337,22 +337,22 @@ RSpec.describe "bundler plugin install" do context "in deployment mode" do it "installs plugins" do install_gemfile <<-G - source '#{file_uri_for(gem_repo2)}' - gem 'rack', "1.0.0" + source 'https://gem.repo2' + gem 'myrack', "1.0.0" G bundle "config set --local deployment true" install_gemfile <<-G - source '#{file_uri_for(gem_repo2)}' + source 'https://gem.repo2' plugin 'foo' - gem 'rack', "1.0.0" + gem 'myrack', "1.0.0" G expect(out).to include("Installed plugin foo") expect(out).to include("Bundle complete!") - expect(the_bundle).to include_gems("rack 1.0.0") + expect(the_bundle).to include_gems("myrack 1.0.0") plugin_should_be_installed("foo") end end @@ -364,12 +364,12 @@ RSpec.describe "bundler plugin install" do require "bundler/inline" gemfile do - source '#{file_uri_for(gem_repo2)}' + source 'https://gem.repo2' plugin 'foo' end RUBY - ruby code, env: { "BUNDLER_VERSION" => Bundler::VERSION } + ruby code, artifice: "compact_index", env: { "BUNDLER_VERSION" => Bundler::VERSION } expect(local_plugin_gem("foo-1.0", "plugins.rb")).to exist end end @@ -378,7 +378,7 @@ RSpec.describe "bundler plugin install" do it "is installed when inside an app" do allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) gemfile "" - bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo --source https://gem.repo2" plugin_should_be_installed("foo") expect(local_plugin_gem("foo-1.0")).to be_directory @@ -401,7 +401,7 @@ RSpec.describe "bundler plugin install" do end # inside the app - gemfile "source '#{file_uri_for(gem_repo2)}'\nplugin 'fubar'" + gemfile "source 'https://gem.repo2'\nplugin 'fubar'" bundle "install" update_repo2 do @@ -419,7 +419,7 @@ RSpec.describe "bundler plugin install" do end # outside the app - bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}", dir: tmp + bundle "plugin install fubar --source https://gem.repo2", dir: tmp end it "inside the app takes precedence over global plugin" do diff --git a/spec/bundler/plugins/list_spec.rb b/spec/bundler/plugins/list_spec.rb index 4a686415ad..30e3f82467 100644 --- a/spec/bundler/plugins/list_spec.rb +++ b/spec/bundler/plugins/list_spec.rb @@ -38,7 +38,7 @@ RSpec.describe "bundler plugin list" do context "single plugin installed" do it "shows plugin name with commands list" do - bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo --source https://gem.repo2" plugin_should_be_installed("foo") bundle "plugin list" @@ -49,7 +49,7 @@ RSpec.describe "bundler plugin list" do context "multiple plugins installed" do it "shows plugin names with commands list" do - bundle "plugin install foo bar --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo bar --source https://gem.repo2" plugin_should_be_installed("foo", "bar") bundle "plugin list" diff --git a/spec/bundler/plugins/source/example_spec.rb b/spec/bundler/plugins/source/example_spec.rb index e569f3e415..17a1f23221 100644 --- a/spec/bundler/plugins/source/example_spec.rb +++ b/spec/bundler/plugins/source/example_spec.rb @@ -52,7 +52,7 @@ RSpec.describe "real source plugins" do build_lib "a-path-gem" gemfile <<-G - source "#{file_uri_for(gem_repo2)}" # plugin source + source "https://gem.repo2" # plugin source source "#{lib_path("a-path-gem-1.0")}", :type => :mpath do gem "a-path-gem" end @@ -82,7 +82,7 @@ RSpec.describe "real source plugins" do a-path-gem (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: PLATFORMS @@ -110,7 +110,7 @@ RSpec.describe "real source plugins" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" # plugin source + source "https://gem.repo2" # plugin source source "#{lib_path("gem_with_bin-1.0")}", :type => :mpath do gem "gem_with_bin" end @@ -170,7 +170,7 @@ RSpec.describe "real source plugins" do a-path-gem (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: PLATFORMS @@ -323,8 +323,8 @@ RSpec.describe "real source plugins" do build_git "ma-gitp-gem" gemfile <<-G - source "#{file_uri_for(gem_repo2)}" # plugin source - source "#{file_uri_for(lib_path("ma-gitp-gem-1.0"))}", :type => :gitp do + source "https://gem.repo2" # plugin source + source "#{lib_path("ma-gitp-gem-1.0")}", :type => :gitp do gem "ma-gitp-gem" end G @@ -346,14 +346,14 @@ RSpec.describe "real source plugins" do expect(lockfile).to eq <<~G PLUGIN SOURCE - remote: #{file_uri_for(lib_path("ma-gitp-gem-1.0"))} + remote: #{lib_path("ma-gitp-gem-1.0")} type: gitp revision: #{revision} specs: ma-gitp-gem (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: PLATFORMS @@ -372,14 +372,14 @@ RSpec.describe "real source plugins" do revision = revision_for(lib_path("ma-gitp-gem-1.0")) lockfile <<-G PLUGIN SOURCE - remote: #{file_uri_for(lib_path("ma-gitp-gem-1.0"))} + remote: #{lib_path("ma-gitp-gem-1.0")} type: gitp revision: #{revision} specs: ma-gitp-gem (1.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: PLATFORMS @@ -423,8 +423,8 @@ RSpec.describe "real source plugins" do it "updates the deps on change in gemfile" do update_git "ma-gitp-gem", "1.1", path: lib_path("ma-gitp-gem-1.0"), gemspec: true gemfile <<-G - source "#{file_uri_for(gem_repo2)}" # plugin source - source "#{file_uri_for(lib_path("ma-gitp-gem-1.0"))}", :type => :gitp do + source "https://gem.repo2" # plugin source + source "#{lib_path("ma-gitp-gem-1.0")}", :type => :gitp do gem "ma-gitp-gem", "1.1" end G @@ -440,7 +440,7 @@ RSpec.describe "real source plugins" do ref = git.ref_for("main", 11) install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" # plugin source + source "https://gem.repo2" # plugin source source '#{lib_path("foo-1.0")}', :type => :gitp do gem "foo" end diff --git a/spec/bundler/plugins/source_spec.rb b/spec/bundler/plugins/source_spec.rb index 14643e5c81..995e50e653 100644 --- a/spec/bundler/plugins/source_spec.rb +++ b/spec/bundler/plugins/source_spec.rb @@ -16,8 +16,8 @@ RSpec.describe "bundler source plugin" do it "installs bundler-source-* gem when no handler for source is present" do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - source "#{file_uri_for(lib_path("gitp"))}", :type => :psource do + source "https://gem.repo2" + source "#{lib_path("gitp")}", :type => :psource do end G @@ -38,8 +38,8 @@ RSpec.describe "bundler source plugin" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - source "#{file_uri_for(lib_path("gitp"))}", :type => :psource do + source "https://gem.repo2" + source "#{lib_path("gitp")}", :type => :psource do end G @@ -62,11 +62,11 @@ RSpec.describe "bundler source plugin" do context "explicit presence in gemfile" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" plugin "another-psource" - source "#{file_uri_for(lib_path("gitp"))}", :type => :psource do + source "#{lib_path("gitp")}", :type => :psource do end G end @@ -88,11 +88,11 @@ RSpec.describe "bundler source plugin" do context "explicit default source" do before do install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" plugin "bundler-source-psource" - source "#{file_uri_for(lib_path("gitp"))}", :type => :psource do + source "#{lib_path("gitp")}", :type => :psource do end G end diff --git a/spec/bundler/plugins/uninstall_spec.rb b/spec/bundler/plugins/uninstall_spec.rb index 555c6a7002..dedcc9f37c 100644 --- a/spec/bundler/plugins/uninstall_spec.rb +++ b/spec/bundler/plugins/uninstall_spec.rb @@ -14,7 +14,7 @@ RSpec.describe "bundler plugin uninstall" do end it "uninstalls specified plugins" do - bundle "plugin install foo kung-foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo kung-foo --source https://gem.repo2" plugin_should_be_installed("foo") plugin_should_be_installed("kung-foo") @@ -40,9 +40,9 @@ RSpec.describe "bundler plugin uninstall" do allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) install_gemfile <<-G - source '#{file_uri_for(gem_repo2)}' + source 'https://gem.repo2' plugin 'path_plugin', :path => "#{path}" - gem 'rack', '1.0.0' + gem 'myrack', '1.0.0' G plugin_should_be_installed("path_plugin") @@ -57,7 +57,7 @@ RSpec.describe "bundler plugin uninstall" do describe "with --all" do it "uninstalls all installed plugins" do - bundle "plugin install foo kung-foo --source #{file_uri_for(gem_repo2)}" + bundle "plugin install foo kung-foo --source https://gem.repo2" plugin_should_be_installed("foo") plugin_should_be_installed("kung-foo") diff --git a/spec/bundler/quality_spec.rb b/spec/bundler/quality_spec.rb index 7cdb993017..c7fce17b62 100644 --- a/spec/bundler/quality_spec.rb +++ b/spec/bundler/quality_spec.rb @@ -236,6 +236,21 @@ RSpec.describe "The library itself" do expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end + # We don't want our artifice code to activate bundler, but it needs to use the + # namespaced implementation of `Net::HTTP`. So we duplicate the file in + # bundler that loads that. + it "keeps vendored_net_http spec code in sync with the lib implementation" do + lib_implementation_path = File.join(source_lib_dir, "bundler", "vendored_net_http.rb") + expect(File.exist?(lib_implementation_path)).to be_truthy + lib_code = File.read(lib_implementation_path) + + spec_implementation_path = File.join(spec_dir, "support", "vendored_net_http.rb") + expect(File.exist?(spec_implementation_path)).to be_truthy + spec_code = File.read(spec_implementation_path) + + expect(lib_code).to eq(spec_code) + end + private def each_line(filename, &block) diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb index 94ca3554b1..dc15c56c79 100644 --- a/spec/bundler/realworld/edgecases_spec.rb +++ b/spec/bundler/realworld/edgecases_spec.rb @@ -198,18 +198,7 @@ RSpec.describe "real world edgecases", realworld: true do expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0")) end - it "outputs a helpful error message when gems have invalid gemspecs", rubygems: "< 3.3.16" do - install_gemfile <<-G, standalone: true, raise_on_error: false, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" } - source 'https://rubygems.org' - gem "resque-scheduler", "2.2.0" - gem "redis-namespace", "1.6.0" # for a consistent resolution including ruby 2.3.0 - gem "ruby2_keywords", "0.0.5" - G - expect(err).to include("You have one or more invalid gemspecs that need to be fixed.") - expect(err).to include("resque-scheduler 2.2.0 has an invalid gemspec") - end - - it "outputs a helpful warning when gems have a gemspec with invalid `require_paths`", rubygems: ">= 3.3.16" do + it "outputs a helpful warning when gems have a gemspec with invalid `require_paths`" do install_gemfile <<-G, standalone: true, env: { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" } source 'https://rubygems.org' gem "resque-scheduler", "2.2.0" diff --git a/spec/bundler/resolver/basic_spec.rb b/spec/bundler/resolver/basic_spec.rb index 4a0dd37bf9..f152907d35 100644 --- a/spec/bundler/resolver/basic_spec.rb +++ b/spec/bundler/resolver/basic_spec.rb @@ -6,15 +6,15 @@ RSpec.describe "Resolving" do end it "resolves a single gem" do - dep "rack" + dep "myrack" - should_resolve_as %w[rack-1.1] + should_resolve_as %w[myrack-1.1] end it "resolves a gem with dependencies" do dep "actionpack" - should_resolve_as %w[actionpack-2.3.5 activesupport-2.3.5 rack-1.0] + should_resolve_as %w[actionpack-2.3.5 activesupport-2.3.5 myrack-1.0] end it "resolves a conflicting index" do @@ -84,7 +84,7 @@ RSpec.describe "Resolving" do dep "activesupport", "= 3.0.0.beta" dep "actionpack" - should_resolve_as %w[activesupport-3.0.0.beta actionpack-3.0.0.beta rack-1.1 rack-mount-0.6] + should_resolve_as %w[activesupport-3.0.0.beta actionpack-3.0.0.beta myrack-1.1 myrack-mount-0.6] end it "prefers non-pre-releases when doing conservative updates" do @@ -313,10 +313,10 @@ RSpec.describe "Resolving" do it "handles versions that redundantly depend on themselves" do @index = build_index do - gem "rack", "3.0.0" + gem "myrack", "3.0.0" gem "standalone_migrations", "7.1.0" do - dep "rack", "~> 2.0" + dep "myrack", "~> 2.0" end gem "standalone_migrations", "2.0.4" do @@ -324,22 +324,22 @@ RSpec.describe "Resolving" do end gem "standalone_migrations", "1.0.13" do - dep "rack", ">= 0" + dep "myrack", ">= 0" end end - dep "rack", "~> 3.0" + dep "myrack", "~> 3.0" dep "standalone_migrations" - should_resolve_as %w[rack-3.0.0 standalone_migrations-2.0.4] + should_resolve_as %w[myrack-3.0.0 standalone_migrations-2.0.4] end it "ignores versions that incorrectly depend on themselves" do @index = build_index do - gem "rack", "3.0.0" + gem "myrack", "3.0.0" gem "standalone_migrations", "7.1.0" do - dep "rack", "~> 2.0" + dep "myrack", "~> 2.0" end gem "standalone_migrations", "2.0.4" do @@ -347,22 +347,22 @@ RSpec.describe "Resolving" do end gem "standalone_migrations", "1.0.13" do - dep "rack", ">= 0" + dep "myrack", ">= 0" end end - dep "rack", "~> 3.0" + dep "myrack", "~> 3.0" dep "standalone_migrations" - should_resolve_as %w[rack-3.0.0 standalone_migrations-1.0.13] + should_resolve_as %w[myrack-3.0.0 standalone_migrations-1.0.13] end it "does not ignore versions that incorrectly depend on themselves when dependency_api is not available" do @index = build_index do - gem "rack", "3.0.0" + gem "myrack", "3.0.0" gem "standalone_migrations", "7.1.0" do - dep "rack", "~> 2.0" + dep "myrack", "~> 2.0" end gem "standalone_migrations", "2.0.4" do @@ -370,13 +370,13 @@ RSpec.describe "Resolving" do end gem "standalone_migrations", "1.0.13" do - dep "rack", ">= 0" + dep "myrack", ">= 0" end end - dep "rack", "~> 3.0" + dep "myrack", "~> 3.0" dep "standalone_migrations" - should_resolve_without_dependency_api %w[rack-3.0.0 standalone_migrations-2.0.4] + should_resolve_without_dependency_api %w[myrack-3.0.0 standalone_migrations-2.0.4] end end diff --git a/spec/bundler/runtime/executable_spec.rb b/spec/bundler/runtime/executable_spec.rb index 36ce6dcf67..b11c48539a 100644 --- a/spec/bundler/runtime/executable_spec.rb +++ b/spec/bundler/runtime/executable_spec.rb @@ -3,83 +3,83 @@ RSpec.describe "Running bin/* commands" do before :each do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end it "runs the bundled command when in the bundle" do - bundle "binstubs rack" + bundle "binstubs myrack" - build_gem "rack", "2.0", to_system: true do |s| - s.executables = "rackup" + build_gem "myrack", "2.0", to_system: true do |s| + s.executables = "myrackup" end - gembin "rackup" + gembin "myrackup" expect(out).to eq("1.0.0") end it "allows the location of the gem stubs to be specified" do - bundle "binstubs rack", path: "gbin" + bundle "binstubs myrack", path: "gbin" expect(bundled_app("bin")).not_to exist - expect(bundled_app("gbin/rackup")).to exist + expect(bundled_app("gbin/myrackup")).to exist - gembin bundled_app("gbin/rackup") + gembin bundled_app("gbin/myrackup") expect(out).to eq("1.0.0") end it "allows absolute paths as a specification of where to install bin stubs" do - bundle "binstubs rack", path: tmp("bin") + bundle "binstubs myrack", path: tmp("bin") - gembin tmp("bin/rackup") + gembin tmp("bin/myrackup") expect(out).to eq("1.0.0") end it "uses the default ruby install name when shebang is not specified" do - bundle "binstubs rack" - expect(File.readlines(bundled_app("bin/rackup")).first).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") + bundle "binstubs myrack" + expect(File.readlines(bundled_app("bin/myrackup")).first).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") end it "allows the name of the shebang executable to be specified" do - bundle "binstubs rack", shebang: "ruby-foo" - expect(File.readlines(bundled_app("bin/rackup")).first).to eq("#!/usr/bin/env ruby-foo\n") + bundle "binstubs myrack", shebang: "ruby-foo" + expect(File.readlines(bundled_app("bin/myrackup")).first).to eq("#!/usr/bin/env ruby-foo\n") end it "runs the bundled command when out of the bundle" do - bundle "binstubs rack" + bundle "binstubs myrack" - build_gem "rack", "2.0", to_system: true do |s| - s.executables = "rackup" + build_gem "myrack", "2.0", to_system: true do |s| + s.executables = "myrackup" end - gembin "rackup", dir: tmp + gembin "myrackup", dir: tmp expect(out).to eq("1.0.0") end it "works with gems in path" do - build_lib "rack", path: lib_path("rack") do |s| - s.executables = "rackup" + build_lib "myrack", path: lib_path("myrack") do |s| + s.executables = "myrackup" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :path => "#{lib_path("rack")}" + source "https://gem.repo1" + gem "myrack", :path => "#{lib_path("myrack")}" G - bundle "binstubs rack" + bundle "binstubs myrack" - build_gem "rack", "2.0", to_system: true do |s| - s.executables = "rackup" + build_gem "myrack", "2.0", to_system: true do |s| + s.executables = "myrackup" end - gembin "rackup" + gembin "myrackup" expect(out).to eq("1.0") end it "creates a bundle binstub" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bundler" G @@ -91,17 +91,17 @@ RSpec.describe "Running bin/* commands" do it "does not generate bin stubs if the option was not specified" do bundle "install" - expect(bundled_app("bin/rackup")).not_to exist + expect(bundled_app("bin/myrackup")).not_to exist end it "allows you to stop installing binstubs", bundler: "< 3" do skip "delete permission error" if Gem.win_platform? bundle "install --binstubs bin/" - bundled_app("bin/rackup").rmtree + bundled_app("bin/myrackup").rmtree bundle "install --binstubs \"\"" - expect(bundled_app("bin/rackup")).not_to exist + expect(bundled_app("bin/myrackup")).not_to exist bundle "config bin" expect(out).to include("You have not configured a value for `bin`") @@ -109,34 +109,34 @@ RSpec.describe "Running bin/* commands" do it "remembers that the option was specified", bundler: "< 3" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" G bundle :install, binstubs: "bin" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" - gem "rack" + gem "myrack" G bundle "install" - expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/myrackup")).to exist end it "rewrites bins on binstubs (to maintain backwards compatibility)" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G - create_file("bin/rackup", "OMG") + create_file("bin/myrackup", "OMG") - bundle "binstubs rack" + bundle "binstubs myrack" - expect(bundled_app("bin/rackup").read).to_not eq("OMG") + expect(bundled_app("bin/myrackup").read).to_not eq("OMG") end it "use BUNDLE_GEMFILE gemfile for binstub" do @@ -148,8 +148,8 @@ RSpec.describe "Running bin/* commands" do build_gem("bindir") {|s| s.executables = "foo" } end - create_file("OtherGemfile", <<-G) - source "#{file_uri_for(gem_repo2)}" + gemfile("OtherGemfile", <<-G) + source "https://gem.repo2" gem 'bindir' G diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index f7afc0eb92..1dffbd5c92 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -20,7 +20,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" G @@ -57,7 +57,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do context "rake build when path has spaces", :ruby_repo do before do - spaced_bundled_app = tmp.join("bundled app") + spaced_bundled_app = tmp("bundled app") FileUtils.cp_r bundled_app, spaced_bundled_app bundle "exec rake build", dir: spaced_bundled_app end @@ -69,7 +69,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do context "rake build when path has brackets", :ruby_repo do before do - bracketed_bundled_app = tmp.join("bundled[app") + bracketed_bundled_app = tmp("bundled[app") FileUtils.cp_r bundled_app, bracketed_bundled_app bundle "exec rake build", dir: bracketed_bundled_app end @@ -86,7 +86,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do it "works", :ruby_repo do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake" G diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 50a5258dc7..f85eaf132d 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -2,10 +2,9 @@ RSpec.describe "bundler/inline#gemfile" do def script(code, options = {}) - requires = ["bundler/inline"] - requires.unshift "#{spec_dir}/support/artifice/" + options.delete(:artifice) if options.key?(:artifice) - requires = requires.map {|r| "require '#{r}'" }.join("\n") - ruby("#{requires}\n\n" + code, options) + options[:artifice] ||= "compact_index" + options[:env] ||= { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } + ruby("require 'bundler/inline'\n\n" + code, options) end before :each do @@ -48,7 +47,7 @@ RSpec.describe "bundler/inline#gemfile" do it "requires the gems" do script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "two" end @@ -59,7 +58,7 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY, raise_on_error: false gemfile do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "eleven" end @@ -73,12 +72,12 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile(true) do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end RUBY - expect(out).to include("Rack's post install message") + expect(out).to include("Myrack's post install message") script <<-RUBY, artifice: "endpoint" gemfile(true) do @@ -143,7 +142,7 @@ RSpec.describe "bundler/inline#gemfile" do require 'bundler' options = { :ui => Bundler::UI::Shell.new } gemfile(false, options) do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "two" end @@ -157,11 +156,11 @@ RSpec.describe "bundler/inline#gemfile" do it "installs quietly if necessary when the install option is not set" do script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end - puts RACK + puts MYRACK RUBY expect(out).to eq("1.0.0") @@ -170,21 +169,21 @@ RSpec.describe "bundler/inline#gemfile" do it "installs subdependencies quietly if necessary when the install option is not set" do build_repo4 do - build_gem "rack" do |s| - s.add_dependency "rackdep" + build_gem "myrack" do |s| + s.add_dependency "myrackdep" end - build_gem "rackdep", "1.0.0" + build_gem "myrackdep", "1.0.0" end - script <<-RUBY + script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } gemfile do - source "#{file_uri_for(gem_repo4)}" - gem "rack" + source "https://gem.repo4" + gem "myrack" end - require "rackdep" - puts RACKDEP + require "myrackdep" + puts MYRACKDEP RUBY expect(out).to eq("1.0.0") @@ -193,23 +192,23 @@ RSpec.describe "bundler/inline#gemfile" do it "installs subdependencies quietly if necessary when the install option is not set, and multiple sources used" do build_repo4 do - build_gem "rack" do |s| - s.add_dependency "rackdep" + build_gem "myrack" do |s| + s.add_dependency "myrackdep" end - build_gem "rackdep", "1.0.0" + build_gem "myrackdep", "1.0.0" end - script <<-RUBY + script <<-RUBY, artifice: "compact_index_extra_api" gemfile do - source "#{file_uri_for(gem_repo1)}" - source "#{file_uri_for(gem_repo4)}" do - gem "rack" + source "https://test.repo" + source "https://test.repo/extra" do + gem "myrack" end end - require "rackdep" - puts RACKDEP + require "myrackdep" + puts MYRACKDEP RUBY expect(out).to eq("1.0.0") @@ -221,7 +220,7 @@ RSpec.describe "bundler/inline#gemfile" do baz_ref = build_git("baz", "2.0.0").ref_for("HEAD") script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => #{lib_path("foo-1.0.0").to_s.dump} gem "baz", :git => #{lib_path("baz-2.0.0").to_s.dump}, :ref => #{baz_ref.dump} end @@ -238,14 +237,14 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile do path "#{lib_path}" do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "two" end end gemfile do path "#{lib_path}" do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "four" end end @@ -256,7 +255,7 @@ RSpec.describe "bundler/inline#gemfile" do end it "doesn't reinstall already installed gems" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" script <<-RUBY require 'bundler' @@ -264,65 +263,65 @@ RSpec.describe "bundler/inline#gemfile" do ui.level = "confirm" gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" - gem "rack" + gem "myrack" end RUBY expect(out).to include("Installing activesupport") - expect(out).not_to include("Installing rack") + expect(out).not_to include("Installing myrack") expect(err).to be_empty end it "installs gems in later gemfile calls" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" script <<-RUBY require 'bundler' ui = Bundler::UI::Shell.new ui.level = "confirm" gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" end RUBY expect(out).to include("Installing activesupport") - expect(out).not_to include("Installing rack") + expect(out).not_to include("Installing myrack") expect(err).to be_empty end it "doesn't reinstall already installed gems in later gemfile calls" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" script <<-RUBY require 'bundler' ui = Bundler::UI::Shell.new ui.level = "confirm" gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" end gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end RUBY expect(out).to include("Installing activesupport") - expect(out).not_to include("Installing rack") + expect(out).not_to include("Installing myrack") expect(err).to be_empty end it "installs gems with native extensions in later gemfile calls" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" build_git "foo" do |s| s.add_dependency "rake" @@ -343,12 +342,12 @@ RSpec.describe "bundler/inline#gemfile" do ui = Bundler::UI::Shell.new ui.level = "confirm" gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end gemfile(true, ui: ui) do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" end @@ -386,11 +385,11 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end - puts RACK + puts MYRACK RUBY expect(err).to be_empty @@ -420,7 +419,7 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile(true) do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rake", "#{rake_version}" end RUBY @@ -431,26 +430,26 @@ RSpec.describe "bundler/inline#gemfile" do end it "installs inline gems when frozen is set" do - script <<-RUBY, env: { "BUNDLE_FROZEN" => "true" } + script <<-RUBY, env: { "BUNDLE_FROZEN" => "true", "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end - puts RACK + puts MYRACK RUBY expect(last_command.stderr).to be_empty end it "installs inline gems when deployment is set" do - script <<-RUBY, env: { "BUNDLE_DEPLOYMENT" => "true" } + script <<-RUBY, env: { "BUNDLE_DEPLOYMENT" => "true", "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end - puts RACK + puts MYRACK RUBY expect(last_command.stderr).to be_empty @@ -461,11 +460,11 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end - puts RACK + puts MYRACK RUBY expect(err).to be_empty @@ -476,11 +475,11 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" # has the rackup executable + source "https://gem.repo1" + gem "myrack" # has the myrackup executable end - puts RACK + puts MYRACK RUBY expect(last_command).to be_success expect(out).to eq "1.0.0" @@ -488,14 +487,14 @@ RSpec.describe "bundler/inline#gemfile" do context "when BUNDLE_PATH is set" do it "installs inline gems to the system path regardless" do - script <<-RUBY, env: { "BUNDLE_PATH" => "./vendor/inline" } + script <<-RUBY, env: { "BUNDLE_PATH" => "./vendor/inline", "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } gemfile(true) do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end RUBY expect(last_command).to be_success - expect(system_gem_path("gems/rack-1.0.0")).to exist + expect(system_gem_path("gems/myrack-1.0.0")).to exist end end @@ -504,8 +503,8 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile(true) do - source "#{file_uri_for(gem_repo1)}" - gem "rack", platform: :jruby + source "https://gem.repo1" + gem "myrack", platform: :jruby end RUBY @@ -517,21 +516,21 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end RUBY expect(last_command).to be_success - expect(system_gem_path("gems/rack-1.0.0")).to exist + expect(system_gem_path("gems/myrack-1.0.0")).to exist end it "preserves previous BUNDLE_GEMFILE value" do ENV["BUNDLE_GEMFILE"] = "" script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end puts "BUNDLE_GEMFILE is empty" if ENV["BUNDLE_GEMFILE"].empty? @@ -547,8 +546,8 @@ RSpec.describe "bundler/inline#gemfile" do ENV["BUNDLE_GEMFILE"] = nil script <<-RUBY gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" end puts "BUNDLE_GEMFILE is empty" if ENV["BUNDLE_GEMFILE"].empty? @@ -576,9 +575,9 @@ RSpec.describe "bundler/inline#gemfile" do s.write "lib/foo.rb", foo_code end - script <<-RUBY, dir: tmp("path_without_gemfile") + script <<-RUBY, dir: tmp("path_without_gemfile"), env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } gemfile do - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" path "#{lib_path}" do gem "foo", require: false end @@ -591,7 +590,7 @@ RSpec.describe "bundler/inline#gemfile" do expect(err).to be_empty end - it "when requiring fileutils after does not show redefinition warnings", :realworld do + it "when requiring fileutils after does not show redefinition warnings" do Dir.mkdir tmp("path_without_gemfile") default_fileutils_version = ruby "gem 'fileutils', '< 999999'; require 'fileutils'; puts FileUtils::VERSION", raise_on_error: false @@ -601,11 +600,11 @@ RSpec.describe "bundler/inline#gemfile" do realworld_system_gems "pathname --version 0.2.0" - script <<-RUBY, dir: tmp("path_without_gemfile"), env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + script <<-RUBY, dir: tmp("path_without_gemfile"), env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s, "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } require "bundler/inline" gemfile(true) do - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" end require "fileutils" @@ -626,11 +625,11 @@ RSpec.describe "bundler/inline#gemfile" do build_gem "timeout", "999" end - script <<-RUBY + script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } require "bundler/inline" gemfile(true) do - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "timeout" end @@ -647,7 +646,7 @@ RSpec.describe "bundler/inline#gemfile" do puts("before: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}") gemfile do - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" end puts("after: \#{ENV.each_key.select { |key| key.match?(/test_variable/i) }}") diff --git a/spec/bundler/runtime/load_spec.rb b/spec/bundler/runtime/load_spec.rb index f28ffd9460..15f3d0eb5b 100644 --- a/spec/bundler/runtime/load_spec.rb +++ b/spec/bundler/runtime/load_spec.rb @@ -4,18 +4,18 @@ RSpec.describe "Bundler.load" do describe "with a gemfile" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "provides a list of the env dependencies" do - expect(Bundler.load.dependencies).to have_dep("rack", ">= 0") + expect(Bundler.load.dependencies).to have_dep("myrack", ">= 0") end it "provides a list of the resolved gems" do - expect(Bundler.load.gems).to have_gem("rack-1.0.0", "bundler-#{Bundler::VERSION}") + expect(Bundler.load.gems).to have_gem("myrack-1.0.0", "bundler-#{Bundler::VERSION}") end it "ignores blank BUNDLE_GEMFILEs" do @@ -28,20 +28,20 @@ RSpec.describe "Bundler.load" do describe "with a gems.rb file" do before(:each) do - create_file "gems.rb", <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + gemfile "gems.rb", <<-G + source "https://gem.repo1" + gem "myrack" G bundle :install allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "provides a list of the env dependencies" do - expect(Bundler.load.dependencies).to have_dep("rack", ">= 0") + expect(Bundler.load.dependencies).to have_dep("myrack", ">= 0") end it "provides a list of the resolved gems" do - expect(Bundler.load.gems).to have_gem("rack-1.0.0", "bundler-#{Bundler::VERSION}") + expect(Bundler.load.gems).to have_gem("myrack-1.0.0", "bundler-#{Bundler::VERSION}") end end @@ -76,8 +76,8 @@ RSpec.describe "Bundler.load" do describe "when called twice" do it "doesn't try to load the runtime twice" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "activesupport", :group => :test G @@ -85,7 +85,7 @@ RSpec.describe "Bundler.load" do require "bundler" Bundler.setup :default Bundler.require :default - puts RACK + puts MYRACK begin require "activesupport" rescue LoadError @@ -100,7 +100,7 @@ RSpec.describe "Bundler.load" do describe "not hurting brittle rubygems" do it "does not inject #source into the generated YAML of the gem specs" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activerecord" G allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb index 1925e9bf2e..93b81cf2fc 100644 --- a/spec/bundler/runtime/platform_spec.rb +++ b/spec/bundler/runtime/platform_spec.rb @@ -3,21 +3,21 @@ RSpec.describe "Bundler.setup with multi platform stuff" do it "raises a friendly error when gems are missing locally" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0) + myrack (1.0) PLATFORMS #{local_tag} DEPENDENCIES - rack + myrack G ruby <<-R @@ -35,7 +35,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do it "will resolve correctly on the current platform when the lockfile was targeted for a different one" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: nokogiri (1.4.2-java) weakling (= 0.0.3) @@ -50,7 +50,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do simulate_platform "x86-darwin-10" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" G @@ -82,7 +82,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do good_lockfile = <<~L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: mini_portile2 (2.5.0) nokogiri (1.11.1) @@ -103,7 +103,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do L gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "nokogiri", "~> 1.11" G @@ -125,13 +125,13 @@ RSpec.describe "Bundler.setup with multi platform stuff" do end gemfile <<-G - source "https://gems.repo4" + source "https://gem.repo4" gem "nokogiri" G lockfile <<~L GEM - remote: https://gems.repo4/ + remote: https://gem.repo4/ specs: nokogiri (1.11.1) @@ -145,7 +145,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do #{Bundler::VERSION} L - bundle "install", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + bundle "install" expect(out).to include("Fetching nokogiri 1.11.1") expect(the_bundle).to include_gems "nokogiri 1.11.1" @@ -154,13 +154,13 @@ RSpec.describe "Bundler.setup with multi platform stuff" do it "will use the java platform if both generic java and generic ruby platforms are locked", :jruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" G lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: nokogiri (1.4.2) nokogiri (1.4.2-java) @@ -181,13 +181,13 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" expect(out).to include("Fetching nokogiri 1.4.2 (java)") - expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA" + expect(the_bundle).to include_gems "nokogiri 1.4.2 java" end it "will add the resolve for the current platform" do lockfile <<-G GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: nokogiri (1.4.2-java) weakling (= 0.0.3) @@ -203,7 +203,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do simulate_platform "x86-darwin-100" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" gem "platform_specific" G @@ -213,7 +213,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do it "allows specifying only-ruby-platform on jruby", :jruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" gem "platform_specific" G @@ -222,12 +222,12 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" - expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 ruby" end it "allows specifying only-ruby-platform" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" gem "platform_specific" G @@ -236,12 +236,12 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" - expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 ruby" end it "allows specifying only-ruby-platform even if the lockfile is locked to a specific compatible platform" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri" gem "platform_specific" G @@ -250,27 +250,27 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" - expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 ruby" end it "doesn't pull platform specific gems on truffleruby", :truffleruby_only do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G - expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" end - it "doesn't pull platform specific gems on truffleruby (except when whitelisted) even if lockfile was generated with an older version that declared RUBY as platform", :truffleruby_only do + it "doesn't pull platform specific gems on truffleruby (except when whitelisted) even if lockfile was generated with an older version that declared ruby as platform", :truffleruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: platform_specific (1.0) @@ -286,7 +286,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" - expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" simulate_platform "x86_64-linux" do build_repo4 do @@ -298,13 +298,13 @@ RSpec.describe "Bundler.setup with multi platform stuff" do end gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "libv8" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo4)}/ + remote: https://gem.repo4/ specs: libv8 (1.0) @@ -326,13 +326,13 @@ RSpec.describe "Bundler.setup with multi platform stuff" do it "doesn't pull platform specific gems on truffleruby, even if lockfile only includes those", :truffleruby_only do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific" G lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: platform_specific (1.0-x86-darwin-100) @@ -348,7 +348,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" - expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" end it "pulls platform specific gems correctly on musl" do @@ -359,8 +359,8 @@ RSpec.describe "Bundler.setup with multi platform stuff" do end simulate_platform "aarch64-linux-musl" do - install_gemfile <<-G, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }, verbose: true - source "https://gems.repo4" + install_gemfile <<-G, verbose: true + source "https://gem.repo4" gem "nokogiri" G end @@ -371,7 +371,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do it "allows specifying only-ruby-platform on windows with dependency platforms" do simulate_windows do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "nokogiri", :platforms => [:windows, :mswin, :mswin64, :mingw, :x64_mingw, :jruby] gem "platform_specific" G @@ -380,18 +380,18 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "install" - expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + expect(the_bundle).to include_gems "platform_specific 1.0 ruby" expect(the_bundle).to not_include_gems "nokogiri" end end it "allows specifying only-ruby-platform on windows with gemspec dependency" do build_lib("foo", "1.0", path: bundled_app) do |s| - s.add_dependency "rack" + s.add_dependency "myrack" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gemspec G bundle :lock @@ -400,7 +400,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do bundle "config set force_ruby_platform true" bundle "install" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end @@ -413,7 +413,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do simulate_windows x64_mingw32 do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: platform_specific (1.0-x86-mingw32) requires_platform_specific (1.0) @@ -428,7 +428,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do L install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "requires_platform_specific" G @@ -444,7 +444,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do simulate_windows platform do lockfile <<-L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: platform_specific (1.0-#{platform}) requires_platform_specific (1.0) @@ -458,7 +458,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do L install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "platform_specific", :platforms => [:windows] G diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index e630e902c9..ff45a3c5e2 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -46,7 +46,7 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "one", :group => :bar, :require => %w[baz qux] gem "two" @@ -113,7 +113,7 @@ RSpec.describe "Bundler.require" do it "raises an exception if a require is specified but the file does not exist" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "two", :require => 'fail' end @@ -132,7 +132,7 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "faulty" end @@ -149,7 +149,7 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "loadfuuu" end @@ -176,7 +176,7 @@ RSpec.describe "Bundler.require" do it "requires gem names that are namespaced" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path '#{lib_path}' do gem 'jquery-rails' end @@ -191,7 +191,7 @@ RSpec.describe "Bundler.require" do s.write "lib/brcrypt.rb", "BCrypt = '1.0.0'" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "bcrypt-ruby" @@ -209,7 +209,7 @@ RSpec.describe "Bundler.require" do it "does not mangle explicitly given requires" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem 'jquery-rails', :require => 'jquery-rails' end @@ -227,7 +227,7 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "load-fuuu" end @@ -251,7 +251,7 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "load-fuuu" end @@ -310,7 +310,7 @@ RSpec.describe "Bundler.require" do it "works when the gems are in the Gemfile in the correct order" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "two" gem "one" @@ -329,7 +329,7 @@ RSpec.describe "Bundler.require" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "multi_gem", :require => "one", :group => :one gem "multi_gem", :require => "two", :group => :two G @@ -353,7 +353,7 @@ RSpec.describe "Bundler.require" do it "fails when the gems are in the Gemfile in the wrong order" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" path "#{lib_path}" do gem "one" gem "two" @@ -371,7 +371,7 @@ RSpec.describe "Bundler.require" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "busted_require" G @@ -385,12 +385,12 @@ RSpec.describe "Bundler.require" do it "does not load rubygems gemspecs that are used" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G run <<-R - path = File.join(Gem.dir, "specifications", "rack-1.0.0.gemspec") + path = File.join(Gem.dir, "specifications", "myrack-1.0.0.gemspec") contents = File.read(path) contents = contents.lines.to_a.insert(-2, "\n raise 'broken gemspec'\n").join File.open(path, "w") do |f| @@ -410,7 +410,7 @@ RSpec.describe "Bundler.require" do build_git "foo" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G @@ -433,13 +433,13 @@ RSpec.describe "Bundler.require" do it "does not extract gemspecs from application cache packages" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle :cache - path = cached_gem("rack-1.0.0") + path = cached_gem("myrack-1.0.0") run <<-R File.open("#{path}", "w") do |f| @@ -459,13 +459,13 @@ end RSpec.describe "Bundler.require with platform specific dependencies" do it "does not require the gems that are pinned to other platforms" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platforms :#{not_local_tag} do gem "platform_specific", :require => "omgomg" end - gem "rack", "1.0.0" + gem "myrack", "1.0.0" G run "Bundler.require" @@ -474,14 +474,14 @@ RSpec.describe "Bundler.require with platform specific dependencies" do it "requires gems pinned to multiple platforms, including the current one" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" platforms :#{not_local_tag}, :#{local_tag} do - gem "rack", :require => "rack" + gem "myrack", :require => "myrack" end G - run "Bundler.require; puts RACK" + run "Bundler.require; puts MYRACK" expect(out).to eq("1.0.0") expect(err).to be_empty diff --git a/spec/bundler/runtime/self_management_spec.rb b/spec/bundler/runtime/self_management_spec.rb index d15ca3189e..d2472dece2 100644 --- a/spec/bundler/runtime/self_management_spec.rb +++ b/spec/bundler/runtime/self_management_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do +RSpec.describe "Self management", rubygems: ">= 3.3.0.dev" do describe "auto switching" do let(:previous_minor) do "2.3.0" @@ -11,12 +11,18 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do end before do - build_repo2 + build_repo4 do + build_bundler previous_minor + + build_bundler current_version + + build_gem "myrack", "1.0.0" + end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo4" - gem "rack" + gem "myrack" G end @@ -24,7 +30,7 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do lockfile_bundled_with(previous_minor) bundle "config set --local path.system true" - bundle "install", artifice: "vcr" + bundle "install", preserve_ruby_flags: true expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") # It uninstalls the older system bundler @@ -35,6 +41,21 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do bundle "-v", artifice: nil expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) + # ruby-core test setup has always "lib" in $LOAD_PATH so `require "bundler/setup"` always activate the local version rather than using RubyGems gem activation stuff + unless ruby_core? + # App now uses locked version, even when not using the CLI directly + file = bundled_app("bin/bundle_version.rb") + create_file file, <<-RUBY + #!#{Gem.ruby} + require 'bundler/setup' + puts Bundler::VERSION + RUBY + file.chmod(0o777) + cmd = Gem.win_platform? ? "#{Gem.ruby} bin/bundle_version.rb" : "bin/bundle_version.rb" + sys_exec cmd, artifice: nil + expect(out).to eq(previous_minor) + end + # Subsequent installs use the locked version without reinstalling bundle "install --verbose", artifice: nil expect(out).to include("Using bundler #{previous_minor}") @@ -45,7 +66,7 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do lockfile_bundled_with(previous_minor) bundle "config set --local path vendor/bundle" - bundle "install", artifice: "vcr" + bundle "install", preserve_ruby_flags: true expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") expect(vendored_gems("gems/bundler-#{previous_minor}")).to exist @@ -57,6 +78,21 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do bundle "-v" expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) + # ruby-core test setup has always "lib" in $LOAD_PATH so `require "bundler/setup"` always activate the local version rather than using RubyGems gem activation stuff + unless ruby_core? + # App now uses locked version, even when not using the CLI directly + file = bundled_app("bin/bundle_version.rb") + create_file file, <<-RUBY + #!#{Gem.ruby} + require 'bundler/setup' + puts Bundler::VERSION + RUBY + file.chmod(0o777) + cmd = Gem.win_platform? ? "#{Gem.ruby} bin/bundle_version.rb" : "bin/bundle_version.rb" + sys_exec cmd, artifice: nil + expect(out).to eq(previous_minor) + end + # Subsequent installs use the locked version without reinstalling bundle "install --verbose" expect(out).to include("Using bundler #{previous_minor}") @@ -67,7 +103,7 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do lockfile_bundled_with(previous_minor) bundle "config set --local deployment true" - bundle "install", artifice: "vcr" + bundle "install", preserve_ruby_flags: true expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") expect(vendored_gems("gems/bundler-#{previous_minor}")).to exist @@ -100,7 +136,7 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do lockfile_bundled_with(missing_minor) - bundle "install", artifice: "vcr" + bundle "install" expect(err).to eq("Your lockfile is locked to a version of bundler (#{missing_minor}) that doesn't exist at https://rubygems.org/. Going on using #{Bundler::VERSION}") bundle "-v" @@ -111,7 +147,7 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do lockfile_bundled_with(current_version) bundle "config set --local version #{previous_minor}" - bundle "install", artifice: "vcr" + bundle "install", preserve_ruby_flags: true expect(out).to include("Bundler #{Bundler::VERSION} is running, but your configuration was #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") bundle "-v" @@ -122,7 +158,7 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do lockfile_bundled_with(previous_minor) bundle "config set version system" - bundle "install", artifice: "vcr" + bundle "install" expect(out).not_to match(/restarting using that version/) bundle "-v" @@ -141,15 +177,15 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do def lockfile_bundled_with(version) lockfile <<~L GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo4/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack BUNDLED WITH #{version} diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 8b8988063c..ededaab410 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -6,16 +6,16 @@ RSpec.describe "Bundler.setup" do describe "with no arguments" do it "makes all groups available" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :group => :test + source "https://gem.repo1" + gem "myrack", :group => :test G ruby <<-RUBY require 'bundler' Bundler.setup - require 'rack' - puts RACK + require 'myrack' + puts MYRACK RUBY expect(err).to be_empty expect(out).to eq("1.0.0") @@ -25,9 +25,9 @@ RSpec.describe "Bundler.setup" do describe "when called with groups" do before(:each) do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack", :group => :test + gem "myrack", :group => :test G end @@ -37,7 +37,7 @@ RSpec.describe "Bundler.setup" do Bundler.setup(:default) begin - require 'rack' + require 'myrack' rescue LoadError puts "WIN" end @@ -51,8 +51,8 @@ RSpec.describe "Bundler.setup" do require 'bundler' Bundler.setup(:default, 'test') - require 'rack' - puts RACK + require 'myrack' + puts MYRACK RUBY expect(err).to be_empty expect(out).to eq("1.0.0") @@ -64,8 +64,8 @@ RSpec.describe "Bundler.setup" do Bundler.setup Bundler.setup(:default) - require 'rack' - puts RACK + require 'myrack' + puts MYRACK RUBY expect(err).to be_empty expect(out).to eq("1.0.0") @@ -93,12 +93,12 @@ RSpec.describe "Bundler.setup" do require 'bundler' Bundler.setup(:default, :test) Bundler.setup(:default) - require 'rack' + require 'myrack' puts "FAIL" RUBY - expect(err).to match("rack") + expect(err).to match("myrack") expect(err).to match("LoadError") expect(out).not_to match("FAIL") end @@ -113,8 +113,8 @@ RSpec.describe "Bundler.setup" do it "puts loaded gems after -I and RUBYLIB", :ruby_repo do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -Idash_i_dir" @@ -127,18 +127,18 @@ RSpec.describe "Bundler.setup" do RUBY load_path = out.split("\n") - rack_load_order = load_path.index {|path| path.include?("rack") } + myrack_load_order = load_path.index {|path| path.include?("myrack") } expect(err).to be_empty expect(load_path).to include(a_string_ending_with("dash_i_dir"), "rubylib_dir") - expect(rack_load_order).to be > 0 + expect(myrack_load_order).to be > 0 end it "orders the load path correctly when there are dependencies" do bundle "config set path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "rails" G @@ -166,7 +166,7 @@ RSpec.describe "Bundler.setup" do bundle "config set path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "weakling" gem "duradura" gem "terranova" @@ -189,8 +189,8 @@ RSpec.describe "Bundler.setup" do it "raises if the Gemfile was not yet installed" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ruby <<-R @@ -209,8 +209,8 @@ RSpec.describe "Bundler.setup" do it "doesn't create a Gemfile.lock if the setup fails" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ruby <<-R, raise_on_error: false @@ -224,15 +224,15 @@ RSpec.describe "Bundler.setup" do it "doesn't change the Gemfile.lock if the setup fails" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G lockfile = File.read(bundled_app_lock) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "nosuchgem", "10.0" G @@ -247,8 +247,8 @@ RSpec.describe "Bundler.setup" do it "makes a Gemfile.lock if setup succeeds" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G File.read(bundled_app_lock) @@ -263,12 +263,12 @@ RSpec.describe "Bundler.setup" do context "user provides an absolute path" do it "uses BUNDLE_GEMFILE to locate the gemfile if present" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G gemfile bundled_app("4realz"), <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", "2.3.5" G @@ -282,7 +282,7 @@ RSpec.describe "Bundler.setup" do context "an absolute path is not provided" do it "uses BUNDLE_GEMFILE to locate the gemfile if present and doesn't fail in deployment mode" do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G bundle "install" @@ -308,23 +308,23 @@ RSpec.describe "Bundler.setup" do it "prioritizes gems in BUNDLE_PATH over gems in GEM_HOME" do ENV["BUNDLE_PATH"] = bundled_app(".bundle").to_s install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" G - build_gem "rack", "1.0", to_system: true do |s| - s.write "lib/rack.rb", "RACK = 'FAIL'" + build_gem "myrack", "1.0", to_system: true do |s| + s.write "lib/myrack.rb", "MYRACK = 'FAIL'" end - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end describe "integrate with rubygems" do describe "by replacing #gem" do before :each do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "0.9.1" + source "https://gem.repo1" + gem "myrack", "0.9.1" G end @@ -344,7 +344,7 @@ RSpec.describe "Bundler.setup" do it "replaces #gem but raises when the version is wrong" do run <<-R begin - gem "rack", "1.0.0" + gem "myrack", "1.0.0" puts "FAIL" rescue LoadError puts "WIN" @@ -359,7 +359,7 @@ RSpec.describe "Bundler.setup" do before :each do system_gems "activesupport-2.3.5" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" G end @@ -381,37 +381,37 @@ RSpec.describe "Bundler.setup" do describe "with paths" do it "activates the gems in the path source" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" - build_lib "rack", "1.0.0" do |s| - s.write "lib/rack.rb", "puts 'WIN'" + build_lib "myrack", "1.0.0" do |s| + s.write "lib/myrack.rb", "puts 'WIN'" end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - path "#{lib_path("rack-1.0.0")}" do - gem "rack" + source "https://gem.repo1" + path "#{lib_path("myrack-1.0.0")}" do + gem "myrack" end G - run "require 'rack'" + run "require 'myrack'" expect(out).to eq("WIN") end end describe "with git" do before do - build_git "rack", "1.0.0" + build_git "myrack", "1.0.0" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-1.0.0")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-1.0.0")}" G end it "provides a useful exception when the git repo is not checked out yet" do run "1", raise_on_error: false - expect(err).to match(/the git source #{lib_path("rack-1.0.0")} is not yet checked out. Please run `bundle install`/i) + expect(err).to match(/the git source #{lib_path("myrack-1.0.0")} is not yet checked out. Please run `bundle install`/i) end it "does not hit the git binary if the lockfile is available and up to date" do @@ -460,7 +460,7 @@ RSpec.describe "Bundler.setup" do bundle "config set --local path vendor/bundle" bundle :install FileUtils.rm_rf vendored_gems("cache") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end it "does not randomly change the path when specifying --path and the bundle directory becomes read only" do @@ -468,7 +468,7 @@ RSpec.describe "Bundler.setup" do bundle :install with_read_only("#{bundled_app}/**/*") do - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end @@ -477,91 +477,91 @@ RSpec.describe "Bundler.setup" do bundle "install" with_read_only("#{bundled_app(".bundle")}/**/*") do - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end end describe "when specifying local override" do it "explodes if given path does not exist on runtime" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install - FileUtils.rm_rf(lib_path("local-rack")) - run "require 'rack'", raise_on_error: false - expect(err).to match(/Cannot use local override for rack-0.8 because #{Regexp.escape(lib_path("local-rack").to_s)} does not exist/) + FileUtils.rm_rf(lib_path("local-myrack")) + run "require 'myrack'", raise_on_error: false + expect(err).to match(/Cannot use local override for myrack-0.8 because #{Regexp.escape(lib_path("local-myrack").to_s)} does not exist/) end it "explodes if branch is not given on runtime" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}" G - run "require 'rack'", raise_on_error: false + run "require 'myrack'", raise_on_error: false expect(err).to match(/because :branch is not specified in Gemfile/) end it "explodes on different branches on runtime" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) + bundle %(config set local.myrack #{lib_path("local-myrack")}) bundle :install gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "changed" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "changed" G - run "require 'rack'", raise_on_error: false + run "require 'myrack'", raise_on_error: false expect(err).to match(/is using branch main but Gemfile specifies changed/) end it "explodes on refs with different branches on runtime" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) + FileUtils.cp_r("#{lib_path("myrack-0.8")}/.", lib_path("local-myrack")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :ref => "main", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :ref => "main", :branch => "main" G gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :ref => "main", :branch => "nonexistent" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :ref => "main", :branch => "nonexistent" G - bundle %(config set local.rack #{lib_path("local-rack")}) - run "require 'rack'", raise_on_error: false + bundle %(config set local.myrack #{lib_path("local-myrack")}) + run "require 'myrack'", raise_on_error: false expect(err).to match(/is using branch main but Gemfile specifies nonexistent/) end end @@ -570,7 +570,7 @@ RSpec.describe "Bundler.setup" do it "doesn't change the resolve if --without is used" do bundle "config set --local without rails" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" group :rails do @@ -586,7 +586,7 @@ RSpec.describe "Bundler.setup" do it "remembers --without and does not bail on bare Bundler.setup" do bundle "config set --local without rails" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" group :rails do @@ -606,7 +606,7 @@ RSpec.describe "Bundler.setup" do build_lib "foo", path: path install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", "2.3.2" gem 'foo', :path => 'vendor/foo', :group => :development G @@ -629,7 +629,7 @@ RSpec.describe "Bundler.setup" do end install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "depends_on_bundler" G @@ -641,7 +641,7 @@ RSpec.describe "Bundler.setup" do it "doesn't fail in frozen mode when bundler is a Gemfile dependency" do install_gemfile <<~G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "bundler" G @@ -651,14 +651,14 @@ RSpec.describe "Bundler.setup" do it "doesn't re-resolve when deleting dependencies" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "actionpack" G install_gemfile <<-G, verbose: true - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G expect(out).to include("Some dependencies were deleted, using a subset of the resolution from the lockfile") @@ -668,11 +668,11 @@ RSpec.describe "Bundler.setup" do it "remembers --without and does not include groups passed to Bundler.setup" do bundle "config set --local without rails" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" - group :rack do - gem "rack" + group :myrack do + gem "myrack" end group :rails do @@ -680,8 +680,8 @@ RSpec.describe "Bundler.setup" do end G - expect(the_bundle).not_to include_gems "activesupport 2.3.2", groups: :rack - expect(the_bundle).to include_gems "rack 1.0.0", groups: :rack + expect(the_bundle).not_to include_gems "activesupport 2.3.2", groups: :myrack + expect(the_bundle).to include_gems "myrack 1.0.0", groups: :myrack end end @@ -691,8 +691,8 @@ RSpec.describe "Bundler.setup" do build_git "no-gemspec", gemspec: false install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" gem "foo", :git => "#{lib_path("foo-1.0")}" gem "no-gemspec", "1.0", :git => "#{lib_path("no-gemspec-1.0")}" G @@ -708,8 +708,8 @@ RSpec.describe "Bundler.setup" do it "does not load all gemspecs" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G run <<-R @@ -757,8 +757,8 @@ end it "ignores empty gem paths" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ENV["GEM_HOME"] = "" @@ -767,10 +767,10 @@ end expect(err).to be_empty end - it "can require rubygems without warnings, when using a local cache" do + it "can require rubygems without warnings, when using a local cache", :truffleruby do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G bundle "package" @@ -790,7 +790,7 @@ end end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "with_man" G @@ -814,7 +814,7 @@ end end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "with_man" G @@ -827,7 +827,7 @@ end expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}#{File::PATH_SEPARATOR}\ntrue") install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "with_man_overriding_system_man" G @@ -854,7 +854,7 @@ end end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem "requirepaths", :require => nil G @@ -870,7 +870,7 @@ end system_gems full_gem_name install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" G ruby <<-R @@ -917,7 +917,7 @@ end end it "should not remove itself from the LOAD_PATH and require a different copy of 'bundler/setup'" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" ruby <<-R, env: { "GEM_PATH" => symlinked_gem_home } TracePoint.trace(:class) do |tp| @@ -934,17 +934,17 @@ end end it "does not reveal system gems even when Gem.refresh is called" do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport" G run <<-R - puts Bundler.rubygems.all_specs.map(&:name) + puts Bundler.rubygems.installed_specs.map(&:name) Gem.refresh - puts Bundler.rubygems.all_specs.map(&:name) + puts Bundler.rubygems.installed_specs.map(&:name) R expect(out).to eq("activesupport\nbundler\nactivesupport\nbundler") @@ -966,7 +966,7 @@ end FileUtils.rm(File.join(path, "foo.gemspec")) install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', '1.2.3', :path => 'vendor/foo' G @@ -987,7 +987,7 @@ end FileUtils.rm(File.join(absolute_path, "foo.gemspec")) gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', '1.2.3', :path => '#{relative_path}' G @@ -1006,7 +1006,7 @@ end build_git "no_gemspec", gemspec: false install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "no_gemspec", "1.0", :git => "#{lib_path("no_gemspec-1.0")}" G end @@ -1023,10 +1023,10 @@ end describe "with bundled and system gems" do before :each do - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", "2.3.5" G @@ -1035,7 +1035,7 @@ end it "does not pull in system gems" do run <<-R begin; - require 'rack' + require 'myrack' rescue LoadError puts 'WIN' end @@ -1057,13 +1057,13 @@ end it "raises an exception if gem is used to invoke a system gem not in the bundle" do run <<-R begin - gem 'rack' + gem 'myrack' rescue LoadError => e puts e.message end R - expect(out).to eq("rack is not part of the bundle. Add it to your Gemfile.") + expect(out).to eq("myrack is not part of the bundle. Add it to your Gemfile.") end it "sets GEM_HOME appropriately" do @@ -1075,11 +1075,11 @@ end describe "with system gems in the bundle" do before :each do bundle "config set path.system true" - system_gems "rack-1.0.0" + system_gems "myrack-1.0.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" + source "https://gem.repo1" + gem "myrack", "1.0.0" gem "activesupport", "2.3.5" G end @@ -1109,7 +1109,7 @@ end end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :git => "#{lib_path("bar-1.0")}" G end @@ -1156,7 +1156,7 @@ end describe "when Bundler is bundled" do it "doesn't blow up" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bundler", :path => "#{root}" G @@ -1169,15 +1169,15 @@ end def lock_with(bundler_version = nil) lock = <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack L if bundler_version @@ -1191,8 +1191,8 @@ end bundle "config set --local path.system true" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end @@ -1229,20 +1229,20 @@ end def lock_with(ruby_version = nil) checksums = checksums_section do |c| - c.checksum gem_repo1, "rack", "1.0.0" + c.checksum gem_repo1, "myrack", "1.0.0" end lock = <<~L GEM - remote: #{file_uri_for(gem_repo1)}/ + remote: https://gem.repo1/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES - rack + myrack #{checksums} L @@ -1262,8 +1262,8 @@ end before do install_gemfile <<-G ruby ">= 0" - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G lockfile lock_with(ruby_version) end @@ -1305,19 +1305,19 @@ end s.files = Dir["lib/**/*.rb"] s.author = 'no one' - s.add_runtime_dependency 'digest' + s.add_dependency 'digest' end G end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "bar", :git => "#{lib_path("bar-1.0")}" G bundle :install - ruby <<-RUBY + ruby <<-RUBY, artifice: nil require 'bundler/setup' puts defined?(::Digest) ? "Digest defined" : "Digest undefined" require 'digest' @@ -1326,7 +1326,7 @@ end end it "does not load Psych" do - gemfile "source \"#{file_uri_for(gem_repo1)}\"" + gemfile "source 'https://gem.repo1'" ruby <<-RUBY require 'bundler/setup' puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined" @@ -1339,8 +1339,8 @@ end end it "does not load openssl" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" - ruby <<-RUBY + install_gemfile "source 'https://gem.repo1'" + ruby <<-RUBY, artifice: nil require "bundler/setup" puts defined?(OpenSSL) || "undefined" require "openssl" @@ -1363,11 +1363,11 @@ end G install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "test", path: "#{bundled_app("test")}" G - ruby <<-RUBY + ruby <<-RUBY, artifice: nil require "bundler/setup" puts defined?(URI) || "undefined" require "uri" @@ -1376,10 +1376,28 @@ end expect(out).to eq("undefined\nconstant") end + it "activates default gems when they are part of the bundle, but not installed explicitly", :ruby_repo do + default_json_version = ruby "gem 'json'; require 'json'; puts JSON::VERSION" + + build_repo2 do + build_gem "json", default_json_version + end + + gemfile "source \"https://gem.repo2\"; gem 'json'" + + ruby <<-RUBY + require "bundler/setup" + require "json" + puts defined?(::JSON) ? "JSON defined" : "JSON undefined" + RUBY + + expect(err).to be_empty + end + describe "default gem activation" do let(:exemptions) do exempts = %w[did_you_mean bundler uri pathname] - exempts << "etc" if Gem.ruby_version < Gem::Version.new("3.2") && Gem.win_platform? + exempts << "etc" if (Gem.ruby_version < Gem::Version.new("3.2") || Gem.ruby_version >= Gem::Version.new("3.3.2")) && Gem.win_platform? exempts << "set" unless Gem.rubygems_version >= Gem::Version.new("3.2.6") exempts << "tsort" unless Gem.rubygems_version >= Gem::Version.new("3.2.31") exempts << "error_highlight" # added in Ruby 3.1 as a default gem @@ -1422,13 +1440,13 @@ end RUBY it "activates no gems with -rbundler/setup" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" - ruby code, env: { "RUBYOPT" => activation_warning_hack_rubyopt + " -rbundler/setup" } + install_gemfile "source 'https://gem.repo1'" + ruby code, env: { "RUBYOPT" => activation_warning_hack_rubyopt + " -rbundler/setup" }, artifice: nil expect(out).to eq("{}") end it "activates no gems with bundle exec" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" create_file("script.rb", code) bundle "exec ruby ./script.rb", env: { "RUBYOPT" => activation_warning_hack_rubyopt } expect(out).to eq("{}") @@ -1437,7 +1455,7 @@ end it "activates no gems with bundle exec that is loaded" do skip "not executable" if Gem.win_platform? - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" create_file("script.rb", "#!/usr/bin/env ruby\n\n#{code}") FileUtils.chmod(0o777, bundled_app("script.rb")) bundle "exec ./script.rb", artifice: nil, env: { "RUBYOPT" => activation_warning_hack_rubyopt } @@ -1452,7 +1470,7 @@ end system_gems "net-http-pipeline-1.0.1", gem_repo: gem_repo4 gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "net-http-pipeline", "1.0.1" G @@ -1474,11 +1492,11 @@ end end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "#{g}", "999999" G - expect(the_bundle).to include_gem("#{g} 999999", env: { "RUBYOPT" => activation_warning_hack_rubyopt }) + expect(the_bundle).to include_gem("#{g} 999999", env: { "RUBYOPT" => activation_warning_hack_rubyopt }, artifice: nil) end it "activates older versions of #{g}", :ruby_repo do @@ -1489,11 +1507,11 @@ end end install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" gem "#{g}", "0.0.0.a" G - expect(the_bundle).to include_gem("#{g} 0.0.0.a", env: { "RUBYOPT" => activation_warning_hack_rubyopt }) + expect(the_bundle).to include_gem("#{g} 0.0.0.a", env: { "RUBYOPT" => activation_warning_hack_rubyopt }, artifice: nil) end end end @@ -1502,28 +1520,28 @@ end describe "after setup" do it "allows calling #gem on random objects", bundler: "< 3" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ruby <<-RUBY require "bundler/setup" - Object.new.gem "rack" - puts Gem.loaded_specs["rack"].full_name + Object.new.gem "myrack" + puts Gem.loaded_specs["myrack"].full_name RUBY - expect(out).to eq("rack-1.0.0") + expect(out).to eq("myrack-1.0.0") end it "keeps Kernel#gem private", bundler: "3" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ruby <<-RUBY, raise_on_error: false require "bundler/setup" - Object.new.gem "rack" + Object.new.gem "myrack" puts "FAIL" RUBY @@ -1533,13 +1551,13 @@ end it "keeps Kernel#require private" do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G ruby <<-RUBY, raise_on_error: false require "bundler/setup" - Object.new.require "rack" + Object.new.require "myrack" puts "FAIL" RUBY @@ -1549,9 +1567,9 @@ end it "memoizes initial set of specs when requiring bundler/setup, so that even if further code mutates dependencies, Bundler.definition.specs is not affected" do install_gemfile <<~G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "yard" - gem "rack", :group => :test + gem "myrack", :group => :test G ruby <<-RUBY, raise_on_error: false @@ -1560,7 +1578,7 @@ end puts Bundler.definition.specs.map(&:name).join(", ") RUBY - expect(out).to include("rack, yard") + expect(out).to include("myrack, yard") end it "does not cause double loads when higher versions of default gems are activated before bundler" do @@ -1576,7 +1594,7 @@ end system_gems "json-999.999.999", gem_repo: gem_repo2 - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" ruby <<-RUBY require "json" require "bundler/setup" @@ -1588,7 +1606,7 @@ end end it "does not undo the Kernel.require decorations", rubygems: ">= 3.4.6" do - install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + install_gemfile "source 'https://gem.repo1'" script = bundled_app("bin/script") create_file(script, <<~RUBY) module Kernel @@ -1613,17 +1631,21 @@ end end it "performs an automatic bundle install" do + build_repo4 do + build_gem "myrack", "1.0.0" + end + gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :group => :test + source "https://gem.repo1" + gem "myrack", :group => :test G bundle "config set auto_install 1" - ruby <<-RUBY + ruby <<-RUBY, artifice: "compact_index" require 'bundler/setup' RUBY expect(err).to be_empty - expect(out).to include("Installing rack 1.0.0") + expect(out).to include("Installing myrack 1.0.0") end end diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb index 135c71b0af..8c3582f7ac 100644 --- a/spec/bundler/runtime/with_unbundled_env_spec.rb +++ b/spec/bundler/runtime/with_unbundled_env_spec.rb @@ -2,13 +2,13 @@ RSpec.describe "Bundler.with_env helpers" do def bundle_exec_ruby(args, options = {}) - build_bundler_context options + build_bundler_context options.dup bundle "exec '#{Gem.ruby}' #{args}", options end def build_bundler_context(options = {}) - bundle "config set path vendor/bundle" - gemfile "source \"#{file_uri_for(gem_repo1)}\"" + bundle "config set path vendor/bundle", options.dup + gemfile "source 'https://gem.repo1'" bundle "install", options end @@ -65,11 +65,11 @@ RSpec.describe "Bundler.with_env helpers" do # Simulate bundler has not yet been loaded ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) }) - original = ruby('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")') + original = ruby('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")', artifice: "fail") create_file("source.rb", <<-RUBY) puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n") RUBY - bundle_exec_ruby bundled_app("source.rb") + bundle_exec_ruby bundled_app("source.rb"), artifice: "fail" expect(out).to eq original end end diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 66bdcfa028..c6bd786347 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -87,11 +87,10 @@ RSpec.configure do |config| # Don't wrap output in tests ENV["THOR_COLUMNS"] = "10000" - extend(Spec::Helpers) - system_gems :bundler, path: pristine_system_gem_path - end + Spec::Helpers.install_dev_bundler unless ENV["CI"] + + extend(Spec::Builders) - config.before :all do check_test_gems! build_repo1 diff --git a/spec/bundler/support/artifice/fail.rb b/spec/bundler/support/artifice/fail.rb index 8822e5b8e2..5ddbc4e590 100644 --- a/spec/bundler/support/artifice/fail.rb +++ b/spec/bundler/support/artifice/fail.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/vendored_net_http" +require_relative "../vendored_net_http" class Fail < Gem::Net::HTTP # Gem::Net::HTTP uses a @newimpl instance variable to decide whether diff --git a/spec/bundler/support/artifice/helpers/compact_index.rb b/spec/bundler/support/artifice/helpers/compact_index.rb index a803a2d30a..f045b71bcf 100644 --- a/spec/bundler/support/artifice/helpers/compact_index.rb +++ b/spec/bundler/support/artifice/helpers/compact_index.rb @@ -40,7 +40,7 @@ class CompactIndexAPI < Endpoint end def requested_range_for(response_body) - ranges = Rack::Utils.byte_ranges(env, response_body.bytesize) + ranges = Rack::Utils.get_byte_ranges(env["HTTP_RANGE"], response_body.bytesize) if ranges status 206 @@ -68,7 +68,10 @@ class CompactIndexAPI < Endpoint @gems[gem_repo] ||= begin specs = Bundler::Deprecate.skip_during do %w[specs.4.8 prerelease_specs.4.8].map do |filename| - Marshal.load(File.open(gem_repo.join(filename)).read).map do |name, version, platform| + spec_index = gem_repo.join(filename) + next [] unless File.exist?(spec_index) + + Marshal.load(File.binread(spec_index)).map do |name, version, platform| load_spec(name, version, platform, gem_repo) end end.flatten diff --git a/spec/bundler/support/artifice/helpers/endpoint.rb b/spec/bundler/support/artifice/helpers/endpoint.rb index 83ba1be0fc..329d2d807a 100644 --- a/spec/bundler/support/artifice/helpers/endpoint.rb +++ b/spec/bundler/support/artifice/helpers/endpoint.rb @@ -62,7 +62,7 @@ class Endpoint < Sinatra::Base return [] if gem_names.nil? || gem_names.empty? all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| - Marshal.load(File.open(gem_repo.join(filename)).read) + Marshal.load(File.binread(gem_repo.join(filename))) end.inject(:+) all_specs.map do |name, version, platform| diff --git a/spec/bundler/support/artifice/helpers/rack_request.rb b/spec/bundler/support/artifice/helpers/rack_request.rb index f419bacb8c..05ff034463 100644 --- a/spec/bundler/support/artifice/helpers/rack_request.rb +++ b/spec/bundler/support/artifice/helpers/rack_request.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "rack/test" -require "bundler/vendored_net_http" +require_relative "../../vendored_net_http" module Artifice module Net diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index 7b9a8bdeaf..2386a4c6b7 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/vendored_net_http" +require_relative "../vendored_net_http" require_relative "../path" CASSETTE_PATH = "#{Spec::Path.spec_dir}/support/artifice/vcr_cassettes".freeze diff --git a/spec/bundler/support/build_metadata.rb b/spec/bundler/support/build_metadata.rb index 5898e7f3bd..189100edb7 100644 --- a/spec/bundler/support/build_metadata.rb +++ b/spec/bundler/support/build_metadata.rb @@ -41,7 +41,7 @@ module Spec end def git_commit_sha - ruby_core_tarball? ? "unknown" : sys_exec("git rev-parse --short HEAD", dir: source_root).strip + ruby_core_tarball? ? "unknown" : git("rev-parse --short HEAD", source_root).strip end extend self diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb index 8f646b9358..7102c1aad1 100644 --- a/spec/bundler/support/builders.rb +++ b/spec/bundler/support/builders.rb @@ -5,6 +5,11 @@ require "shellwords" module Spec module Builders + def self.extended(mod) + mod.extend Path + mod.extend Helpers + end + def self.constantize(name) name.delete("-").upcase end @@ -22,7 +27,7 @@ module Spec end def build_repo1 - rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first + rake_path = Dir["#{base_system_gems}/**/rake*.gem"].first build_repo gem_repo1 do FileUtils.cp rake_path, "#{gem_repo1}/gems/" @@ -32,23 +37,23 @@ module Spec build_gem "puma" build_gem "minitest" - build_gem "rack", %w[0.9.1 1.0.0] do |s| - s.executables = "rackup" - s.post_install_message = "Rack's post install message" + build_gem "myrack", %w[0.9.1 1.0.0] do |s| + s.executables = "myrackup" + s.post_install_message = "Myrack's post install message" end build_gem "thin" do |s| - s.add_dependency "rack" + s.add_dependency "myrack" s.post_install_message = "Thin's post install message" end - build_gem "rack-obama" do |s| - s.add_dependency "rack" - s.post_install_message = "Rack-obama's post install message" + build_gem "myrack-obama" do |s| + s.add_dependency "myrack" + s.post_install_message = "Myrack-obama's post install message" end - build_gem "rack_middleware", "1.0" do |s| - s.add_dependency "rack", "0.9.1" + build_gem "myrack_middleware", "1.0" do |s| + s.add_dependency "myrack", "0.9.1" end build_gem "rails", "2.3.2" do |s| @@ -81,80 +86,66 @@ module Spec s.write "lib/spec.rb", "SPEC = '1.2.7'" end - build_gem "rack-test", no_default: true do |s| - s.write "lib/rack/test.rb", "RACK_TEST = '1.0'" + build_gem "myrack-test", no_default: true do |s| + s.write "lib/myrack/test.rb", "MYRACK_TEST = '1.0'" end build_gem "platform_specific" do |s| s.platform = Gem::Platform.local - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 #{Gem::Platform.local}'" end build_gem "platform_specific" do |s| s.platform = "java" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 JAVA'" end build_gem "platform_specific" do |s| s.platform = "ruby" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'" end build_gem "platform_specific" do |s| s.platform = "x86-mswin32" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0 x86-mswin32'" end build_gem "platform_specific" do |s| s.platform = "x64-mswin64" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0 x64-mswin64'" end build_gem "platform_specific" do |s| s.platform = "x86-mingw32" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0 x86-mingw32'" end build_gem "platform_specific" do |s| s.platform = "x64-mingw32" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0 x64-mingw32'" end build_gem "platform_specific" do |s| s.platform = "x64-mingw-ucrt" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0 x64-mingw-ucrt'" end build_gem "platform_specific" do |s| s.platform = "x86-darwin-100" - s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 x86-darwin-100'" end build_gem "only_java", "1.0" do |s| s.platform = "java" - s.write "lib/only_java.rb", "ONLY_JAVA = '1.0.0 JAVA'" end build_gem "only_java", "1.1" do |s| s.platform = "java" - s.write "lib/only_java.rb", "ONLY_JAVA = '1.1.0 JAVA'" end build_gem "nokogiri", "1.4.2" build_gem "nokogiri", "1.4.2" do |s| s.platform = "java" - s.write "lib/nokogiri.rb", "NOKOGIRI = '1.4.2 JAVA'" s.add_dependency "weakling", ">= 0.0.3" end build_gem "laduradura", "5.15.2" build_gem "laduradura", "5.15.2" do |s| s.platform = "java" - s.write "lib/laduradura.rb", "LADURADURA = '5.15.2 JAVA'" end build_gem "laduradura", "5.15.3" do |s| s.platform = "java" - s.write "lib/laduradura.rb", "LADURADURA = '5.15.2 JAVA'" end build_gem "weakling", "0.0.3" @@ -218,7 +209,7 @@ module Spec def build_security_repo build_repo security_repo do - build_gem "rack" + build_gem "myrack" build_gem "signed_gem" do |s| cert = "signing-cert.pem" @@ -240,12 +231,12 @@ module Spec end def check_test_gems! - rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first + rake_path = Dir["#{base_system_gems}/**/rake*.gem"].first if rake_path.nil? - FileUtils.rm_rf(Path.base_system_gems) + FileUtils.rm_rf(base_system_gems) Spec::Rubygems.install_test_deps - rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first + rake_path = Dir["#{base_system_gems}/**/rake*.gem"].first end if rake_path.nil? @@ -254,16 +245,17 @@ module Spec end def update_repo(path, build_compact_index: true) - if path == gem_repo1 && caller.first.split(" ").last == "`build_repo`" + exempted_caller = Gem.ruby_version >= Gem::Version.new("3.4.0.dev") ? "#{Module.nesting.first}#build_repo" : "build_repo" + if path == gem_repo1 && caller_locations(1, 1).first.label != exempted_caller raise "Updating gem_repo1 is unsupported -- use gem_repo2 instead" end return unless block_given? @_build_path = "#{path}/gems" @_build_repo = File.basename(path) yield - with_gem_path_as Path.base_system_gem_path do - Dir[Spec::Path.base_system_gem_path.join("gems/rubygems-generate_index*/lib")].first || - raise("Could not find rubygems-generate_index lib directory in #{Spec::Path.base_system_gem_path}") + with_gem_path_as base_system_gem_path do + Dir[base_system_gem_path.join("gems/rubygems-generate_index*/lib")].first || + raise("Could not find rubygems-generate_index lib directory in #{base_system_gem_path}") command = "generate_index" command += " --no-compact" if !build_compact_index && gem_command(command + " --help").include?("--[no-]compact") @@ -489,7 +481,6 @@ module Spec end def add_c_extension - require_paths << "ext" extensions << "ext/extconf.rb" write "ext/extconf.rb", <<-RUBY require "mkmf" diff --git a/spec/bundler/support/checksums.rb b/spec/bundler/support/checksums.rb index f758559b3b..19a3fd6a4d 100644 --- a/spec/bundler/support/checksums.rb +++ b/spec/bundler/support/checksums.rb @@ -110,5 +110,17 @@ module Spec _checksums, tail = remaining.split("\n\n", 2) head.concat(tail) end + + def checksum_from_package(gem_file, name, version) + name_tuple = Gem::NameTuple.new(name, version) + + checksum = nil + + File.open(gem_file, "rb") do |f| + checksum = Bundler::Checksum.from_gem(f, gemfile) + end + + "#{name_tuple.lock_name} #{checksum.to_lock}" + end end end diff --git a/spec/bundler/support/command_execution.rb b/spec/bundler/support/command_execution.rb index 5639fda3b6..02726744d3 100644 --- a/spec/bundler/support/command_execution.rb +++ b/spec/bundler/support/command_execution.rb @@ -1,7 +1,37 @@ # frozen_string_literal: true module Spec - CommandExecution = Struct.new(:command, :working_directory, :exitstatus, :original_stdout, :original_stderr) do + class CommandExecution + def initialize(command, working_directory:, timeout:) + @command = command + @working_directory = working_directory + @timeout = timeout + @original_stdout = String.new + @original_stderr = String.new + end + + attr_accessor :exitstatus, :command, :original_stdout, :original_stderr + attr_reader :timeout + attr_writer :failure_reason + + def raise_error! + return unless failure? + + error_header = if failure_reason == :timeout + "Invoking `#{command}` was aborted after #{timeout} seconds with output:" + else + "Invoking `#{command}` failed with output:" + end + + raise <<~ERROR + #{error_header} + + ---------------------------------------------------------------------- + #{stdboth} + ---------------------------------------------------------------------- + ERROR + end + def to_s "$ #{command}" end @@ -12,16 +42,11 @@ module Spec end def stdout - original_stdout + normalize(original_stdout) end - # Can be removed once/if https://github.com/oneclick/rubyinstaller2/pull/369 is resolved def stderr - return original_stderr unless Gem.win_platform? - - original_stderr.split("\n").reject do |l| - l.include?("operating_system_defaults") - end.join("\n") + normalize(original_stderr) end def to_s_verbose @@ -42,5 +67,13 @@ module Spec return true unless exitstatus exitstatus > 0 end + + private + + attr_reader :failure_reason + + def normalize(string) + string.force_encoding(Encoding::UTF_8).strip.gsub("\r\n", "\n") + end end end diff --git a/spec/bundler/support/env.rb b/spec/bundler/support/env.rb new file mode 100644 index 0000000000..4d99c892cd --- /dev/null +++ b/spec/bundler/support/env.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Spec + module Env + def ruby_core? + !ENV["GEM_COMMAND"].nil? + end + end +end diff --git a/spec/bundler/support/filters.rb b/spec/bundler/support/filters.rb index 8e164af756..e1683ae75b 100644 --- a/spec/bundler/support/filters.rb +++ b/spec/bundler/support/filters.rb @@ -14,7 +14,7 @@ class RequirementChecker < Proc attr_accessor :provided def inspect - "\"!= #{provided}\"" + "\"#{provided}\"" end end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index dbb8b8152b..13f77ec56a 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -1,12 +1,21 @@ # frozen_string_literal: true -require_relative "command_execution" require_relative "the_bundle" require_relative "path" +require_relative "options" +require_relative "subprocess" module Spec module Helpers include Spec::Path + include Spec::Options + include Spec::Subprocess + + def self.extended(mod) + mod.extend Spec::Path + mod.extend Spec::Options + mod.extend Spec::Subprocess + end def reset! Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir| @@ -27,22 +36,6 @@ module Spec TheBundle.new(*args) end - def command_executions - @command_executions ||= [] - end - - def last_command - command_executions.last || raise("There is no last command") - end - - def out - last_command.stdout - end - - def err - last_command.stderr - end - MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/ def err_without_deprecations @@ -53,10 +46,6 @@ module Spec err.split("\n").select {|l| l =~ MAJOR_DEPRECATION }.join("\n").split(MAJOR_DEPRECATION) end - def exitstatus - last_command.exitstatus - end - def run(cmd, *args) opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") @@ -82,31 +71,26 @@ module Spec bundle_bin ||= installed_bindir.join("bundle") env = options.delete(:env) || {} + preserve_ruby_flags = options.delete(:preserve_ruby_flags) requires = options.delete(:requires) || [] - realworld = RSpec.current_example.metadata[:realworld] - artifice = options.delete(:artifice) do - if realworld - "vcr" - else - "fail" - end - end - if artifice - requires << "#{Path.spec_dir}/support/artifice/#{artifice}.rb" - end + dir = options.delete(:dir) || bundled_app load_path = [] load_path << spec_dir - dir = options.delete(:dir) || bundled_app + build_ruby_options = { load_path: load_path, requires: requires, env: env } + build_ruby_options.merge!(artifice: options.delete(:artifice)) if options.key?(:artifice) + + match_source(cmd) + + env, ruby_cmd = build_ruby_cmd(build_ruby_options) + raise_on_error = options.delete(:raise_on_error) args = options.map do |k, v| case v - when nil - next when true " --#{k}" when false @@ -116,19 +100,30 @@ module Spec end end.join - ruby_cmd = build_ruby_cmd({ load_path: load_path, requires: requires, env: env }) cmd = "#{ruby_cmd} #{bundle_bin} #{cmd}#{args}" + env["BUNDLER_SPEC_ORIGINAL_CMD"] = "#{ruby_cmd} #{bundle_bin}" if preserve_ruby_flags sys_exec(cmd, { env: env, dir: dir, raise_on_error: raise_on_error }, &block) end + def main_source(dir) + gemfile = File.expand_path("Gemfile", dir) + return unless File.exist?(gemfile) + + match = File.readlines(gemfile).first.match(/source ["'](?<source>[^"']+)["']/) + return unless match + + match[:source] + end + def bundler(cmd, options = {}) - options[:bundle_bin] = system_gem_path.join("bin/bundler") + options[:bundle_bin] = system_gem_path("bin/bundler") bundle(cmd, options) end def ruby(ruby, options = {}) - ruby_cmd = build_ruby_cmd + env, ruby_cmd = build_ruby_cmd({ artifice: nil }.merge(options)) escaped_ruby = ruby.shellescape + options[:env] = env if env sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options) end @@ -146,17 +141,44 @@ module Spec libs = options.delete(:load_path) lib_option = libs ? "-I#{libs.join(File::PATH_SEPARATOR)}" : [] + env = options.delete(:env) || {} + current_example = RSpec.current_example + + main_source = @gemfile_source if defined?(@gemfile_source) + compact_index_main_source = main_source&.start_with?("https://gem.repo", "https://gems.security") + requires = options.delete(:requires) || [] + artifice = options.delete(:artifice) do + if current_example && current_example.metadata[:realworld] + "vcr" + elsif compact_index_main_source + env["BUNDLER_SPEC_GEM_REPO"] ||= + case main_source + when "https://gem.repo1" then gem_repo1.to_s + when "https://gem.repo2" then gem_repo2.to_s + when "https://gem.repo3" then gem_repo3.to_s + when "https://gem.repo4" then gem_repo4.to_s + when "https://gems.security" then security_repo.to_s + end + + "compact_index" + else + "fail" + end + end + if artifice + requires << "#{Path.spec_dir}/support/artifice/#{artifice}.rb" + end hax_path = "#{Path.spec_dir}/support/hax.rb" # For specs that need to ignore the default Bundler gem, load hax before # anything else since other stuff may actually load bundler and not skip # the default version - options[:env]&.include?("BUNDLER_IGNORE_DEFAULT_GEM") ? requires.prepend(hax_path) : requires.append(hax_path) + env.include?("BUNDLER_IGNORE_DEFAULT_GEM") ? requires.prepend(hax_path) : requires.append(hax_path) require_option = requires.map {|r| "-r#{r}" } - [Gem.ruby, *lib_option, *require_option].compact.join(" ") + [env, [Gem.ruby, *lib_option, *require_option].compact.join(" ")] end def gembin(cmd, options = {}) @@ -175,54 +197,13 @@ module Spec "#{Gem.ruby} -S #{ENV["GEM_PATH"]}/bin/rake" end - def git(cmd, path, options = {}) - sys_exec("git #{cmd}", options.merge(dir: path)) - end - - def sys_exec(cmd, options = {}) + def sys_exec(cmd, options = {}, &block) env = options[:env] || {} env["RUBYOPT"] = opt_add(opt_add("-r#{spec_dir}/support/switch_rubygems.rb", env["RUBYOPT"]), ENV["RUBYOPT"]) - dir = options[:dir] || bundled_app - command_execution = CommandExecution.new(cmd.to_s, dir) - - require "open3" - require "shellwords" - Open3.popen3(env, *cmd.shellsplit, chdir: dir) do |stdin, stdout, stderr, wait_thr| - yield stdin, stdout, wait_thr if block_given? - stdin.close - - stdout_read_thread = Thread.new { stdout.read } - stderr_read_thread = Thread.new { stderr.read } - command_execution.original_stdout = stdout_read_thread.value.strip - command_execution.original_stderr = stderr_read_thread.value.strip - - status = wait_thr.value - command_execution.exitstatus = if status.exited? - status.exitstatus - elsif status.signaled? - exit_status_for_signal(status.termsig) - end - end - - unless options[:raise_on_error] == false || command_execution.success? - raise <<~ERROR - - Invoking `#{cmd}` failed with output: - ---------------------------------------------------------------------- - #{command_execution.stdboth} - ---------------------------------------------------------------------- - ERROR - end - - command_executions << command_execution - - command_execution.stdout - end - - def all_commands_output - return "" if command_executions.empty? + options[:env] = env + options[:dir] ||= bundled_app - "\n\nCommands:\n#{command_executions.map(&:to_s_verbose).join("\n\n")}" + sh(cmd, options, &block) end def config(config = nil, path = bundled_app(".bundle/config")) @@ -260,6 +241,7 @@ module Spec if contents.nil? read_gemfile else + match_source(contents) create_file(args.pop || "Gemfile", contents) end end @@ -325,6 +307,12 @@ module Spec end end + def self.install_dev_bundler + extend self + + system_gems :bundler, path: pristine_system_gem_path + end + def install_gem(path, install_dir, default = false) raise "OMG `#{path}` does not exist!" unless File.exist?(path) @@ -335,6 +323,8 @@ module Spec end def with_built_bundler(version = nil, &block) + require_relative "builders" + Builders::BundlerBuilder.new(self, "bundler", version)._build(&block) end @@ -369,16 +359,6 @@ module Spec end end - def opt_add(option, options) - [option.strip, options].compact.reject(&:empty?).join(" ") - end - - def opt_remove(option, options) - return unless options - - options.split(" ").reject {|opt| opt.strip == option.strip }.join(" ") - end - def break_git! FileUtils.mkdir_p(tmp("broken_path")) File.open(tmp("broken_path/git"), "w", 0o755) do |f| @@ -479,7 +459,7 @@ module Spec end def revision_for(path) - sys_exec("git rev-parse HEAD", dir: path).strip + git("rev-parse HEAD", path).strip end def with_read_only(pattern) @@ -566,6 +546,13 @@ module Spec private + def match_source(contents) + match = /source ["']?(?<source>http[^"']+)["']?/.match(contents) + return unless match + + @gemfile_source = match[:source] + end + def git_root_dir? root.to_s == `git rev-parse --show-toplevel`.chomp end diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb index 086a311551..7960bae59f 100644 --- a/spec/bundler/support/indexes.rb +++ b/spec/bundler/support/indexes.rb @@ -77,8 +77,8 @@ module Spec def an_awesome_index build_index do - gem "rack", %w[0.8 0.9 0.9.1 0.9.2 1.0 1.1] - gem "rack-mount", %w[0.4 0.5 0.5.1 0.5.2 0.6] + gem "myrack", %w[0.8 0.9 0.9.1 0.9.2 1.0 1.1] + gem "myrack-mount", %w[0.4 0.5 0.5.1 0.5.2 0.6] # --- Pre-release support gem "RubyGems\0", ["1.3.2"] @@ -89,10 +89,10 @@ module Spec gem "actionpack", version do dep "activesupport", version if version >= v("3.0.0.beta") - dep "rack", "~> 1.1" - dep "rack-mount", ">= 0.5" - elsif version > v("2.3") then dep "rack", "~> 1.0.0" - elsif version > v("2.0.0") then dep "rack", "~> 0.9.0" + dep "myrack", "~> 1.1" + dep "myrack-mount", ">= 0.5" + elsif version > v("2.3") then dep "myrack", "~> 1.0.0" + elsif version > v("2.0.0") then dep "myrack", "~> 0.9.0" end end gem "activerecord", version do @@ -367,7 +367,7 @@ module Spec def a_circular_index build_index do - gem "rack", "1.0.1" + gem "myrack", "1.0.1" gem("foo", "0.2.6") do dep "bar", ">= 0" end diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index 0f027dcf04..ed11e3ba52 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -118,6 +118,7 @@ module Spec opts[:raise_on_error] = false @errors = names.map do |full_name| name, version, platform = full_name.split(/\s+/) + platform ||= "ruby" require_path = name.tr("-", "/") version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) source_const = "#{Spec::Builders.constantize(name)}_SOURCE" @@ -127,6 +128,7 @@ module Spec require '#{require_path}' actual_version, actual_platform = #{version_const}.split(/\s+/, 2) + actual_platform ||= "ruby" unless Gem::Version.new(actual_version) == Gem::Version.new('#{version}') puts actual_version exit 64 @@ -150,7 +152,7 @@ module Spec end if exitstatus == 65 actual_platform = out.split("\n").last - next "#{name} was expected to be of platform #{platform || "ruby"} but was #{actual_platform || "ruby"}" + next "#{name} was expected to be of platform #{platform} but was #{actual_platform}" end if exitstatus == 66 actual_source = out.split("\n").last diff --git a/spec/bundler/support/options.rb b/spec/bundler/support/options.rb new file mode 100644 index 0000000000..551fa1acd8 --- /dev/null +++ b/spec/bundler/support/options.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Spec + module Options + def opt_add(option, options) + [option.strip, options].compact.reject(&:empty?).join(" ") + end + + def opt_remove(option, options) + return unless options + + options.split(" ").reject {|opt| opt.strip == option.strip }.join(" ") + end + end +end diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index 7352d5a353..26be5488c3 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -3,8 +3,12 @@ require "pathname" require "rbconfig" +require_relative "env" + module Spec module Path + include Spec::Env + def source_root @source_root ||= Pathname.new(ruby_core? ? "../../.." : "../..").expand_path(__dir__) end @@ -58,7 +62,7 @@ module Spec end def gem_bin - @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "gem" + @gem_bin ||= ENV["GEM_COMMAND"] || "gem" end def path @@ -109,7 +113,7 @@ module Spec end def home(*path) - tmp.join("home", *path) + tmp("home", *path) end def default_bundle_path(*path) @@ -129,13 +133,13 @@ module Spec end def bundled_app(*path) - root = tmp.join("bundled_app") + root = tmp("bundled_app") FileUtils.mkdir_p(root) root.join(*path) end def bundled_app2(*path) - root = tmp.join("bundled_app2") + root = tmp("bundled_app2") FileUtils.mkdir_p(root) root.join(*path) end @@ -161,15 +165,15 @@ module Spec end def base_system_gems - tmp.join("gems/base") + tmp("gems/base") end def rubocop_gems - tmp.join("gems/rubocop") + tmp("gems/rubocop") end def standard_gems - tmp.join("gems/standard") + tmp("gems/standard") end def file_uri_for(path) @@ -257,17 +261,6 @@ module Spec File.open(gemspec_file, "w") {|f| f << contents } end - def ruby_core? - # avoid to warnings - @ruby_core ||= nil - - if @ruby_core.nil? - @ruby_core = true & ENV["GEM_COMMAND"] - else - @ruby_core - end - end - def git_root ruby_core? ? source_root : source_root.parent end @@ -277,7 +270,7 @@ module Spec def git_ls_files(glob) skip "Not running on a git context, since running tests from a tarball" if ruby_core_tarball? - sys_exec("git ls-files -z -- #{glob}", dir: source_root).split("\x0") + git("ls-files -z -- #{glob}", source_root).split("\x0") end def tracked_files_glob diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index 889ebc90c3..fb03d4892e 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -70,14 +70,20 @@ module Spec ENV["BUNDLE_PATH"] = nil ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gem_path.to_s - ENV["PATH"] = [Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + ENV["PATH"] = [Path.system_gem_path("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) ENV["PATH"] = [Path.bindir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core? end def install_test_deps + Gem.clear_paths + install_gems(test_gemfile, Path.base_system_gems.to_s) install_gems(rubocop_gemfile, Path.rubocop_gems.to_s) install_gems(standard_gemfile, Path.standard_gems.to_s) + + # For some reason, doing this here crashes on JRuby + Windows. So defer to + # when the test suite is running in that case. + Helpers.install_dev_bundler unless Gem.win_platform? && RUBY_ENGINE == "jruby" end def check_source_control_changes(success_message:, error_message:) @@ -117,7 +123,14 @@ module Spec def gem_activate_and_possibly_install(gem_name) gem_activate(gem_name) rescue Gem::LoadError => e - Gem.install(gem_name, e.requirement) + # Windows 3.0 puts a Windows stub script as `rake` while it should be + # named `rake.bat`. RubyGems does not like that and avoids overwriting it + # unless explicitly instructed to do so with `force`. + if RUBY_VERSION.start_with?("3.0") && Gem.win_platform? + Gem.install(gem_name, e.requirement, force: true) + else + Gem.install(gem_name, e.requirement) + end retry end diff --git a/spec/bundler/support/rubygems_version_manager.rb b/spec/bundler/support/rubygems_version_manager.rb index 88da14b67e..c174c461f0 100644 --- a/spec/bundler/support/rubygems_version_manager.rb +++ b/spec/bundler/support/rubygems_version_manager.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true -require "pathname" -require_relative "helpers" -require_relative "path" +require_relative "options" +require_relative "env" +require_relative "subprocess" class RubygemsVersionManager - include Spec::Helpers - include Spec::Path + include Spec::Options + include Spec::Env + include Spec::Subprocess def initialize(source) @source = source @@ -57,7 +58,7 @@ class RubygemsVersionManager cmd = [RbConfig.ruby, $0, *ARGV].compact - ENV["RUBYOPT"] = opt_add("-I#{local_copy_path.join("lib")}", opt_remove("--disable-gems", ENV["RUBYOPT"])) + ENV["RUBYOPT"] = opt_add("-I#{File.join(local_copy_path, "lib")}", opt_remove("--disable-gems", ENV["RUBYOPT"])) exec(ENV, *cmd) end @@ -65,14 +66,14 @@ class RubygemsVersionManager def switch_local_copy_if_needed return unless local_copy_switch_needed? - sys_exec("git checkout #{target_tag}", dir: local_copy_path) + git("checkout #{target_tag}", local_copy_path) - ENV["RGV"] = local_copy_path.to_s + ENV["RGV"] = local_copy_path end def rubygems_unrequire_needed? require "rubygems" - !$LOADED_FEATURES.include?(local_copy_path.join("lib/rubygems.rb").to_s) + !$LOADED_FEATURES.include?(File.join(local_copy_path, "lib/rubygems.rb")) end def local_copy_switch_needed? @@ -84,7 +85,7 @@ class RubygemsVersionManager end def local_copy_tag - sys_exec("git rev-parse --abbrev-ref HEAD", dir: local_copy_path) + git("rev-parse --abbrev-ref HEAD", local_copy_path) end def local_copy_path @@ -94,21 +95,25 @@ class RubygemsVersionManager def resolve_local_copy_path return expanded_source if source_is_path? - rubygems_path = source_root.join("tmp/rubygems") + rubygems_path = File.join(source_root, "tmp/rubygems") - unless rubygems_path.directory? - sys_exec("git clone .. #{rubygems_path}", dir: source_root) + unless File.directory?(rubygems_path) + git("clone .. #{rubygems_path}", source_root) end rubygems_path end def source_is_path? - expanded_source.directory? + File.directory?(expanded_source) end def expanded_source - @expanded_source ||= Pathname.new(@source).expand_path(source_root) + @expanded_source ||= File.expand_path(@source, source_root) + end + + def source_root + @source_root ||= File.expand_path(ruby_core? ? "../../.." : "../..", __dir__) end def resolve_target_tag diff --git a/spec/bundler/support/subprocess.rb b/spec/bundler/support/subprocess.rb new file mode 100644 index 0000000000..ade18e7805 --- /dev/null +++ b/spec/bundler/support/subprocess.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +require_relative "command_execution" + +module Spec + module Subprocess + class TimeoutExceeded < StandardError; end + + def command_executions + @command_executions ||= [] + end + + def last_command + command_executions.last || raise("There is no last command") + end + + def out + last_command.stdout + end + + def err + last_command.stderr + end + + def exitstatus + last_command.exitstatus + end + + def git(cmd, path = Dir.pwd, options = {}) + sh("git #{cmd}", options.merge(dir: path)) + end + + def sh(cmd, options = {}) + dir = options[:dir] + env = options[:env] || {} + + command_execution = CommandExecution.new(cmd.to_s, working_directory: dir, timeout: 60) + + require "open3" + require "shellwords" + Open3.popen3(env, *cmd.shellsplit, chdir: dir) do |stdin, stdout, stderr, wait_thr| + yield stdin, stdout, wait_thr if block_given? + stdin.close + + stdout_handler = ->(data) { command_execution.original_stdout << data } + stderr_handler = ->(data) { command_execution.original_stderr << data } + + stdout_thread = read_stream(stdout, stdout_handler, timeout: command_execution.timeout) + stderr_thread = read_stream(stderr, stderr_handler, timeout: command_execution.timeout) + + stdout_thread.join + stderr_thread.join + + status = wait_thr.value + command_execution.exitstatus = if status.exited? + status.exitstatus + elsif status.signaled? + exit_status_for_signal(status.termsig) + end + rescue TimeoutExceeded + command_execution.failure_reason = :timeout + command_execution.exitstatus = exit_status_for_signal(Signal.list["INT"]) + end + + unless options[:raise_on_error] == false || command_execution.success? + command_execution.raise_error! + end + + command_executions << command_execution + + command_execution.stdout + end + + # Mostly copied from https://github.com/piotrmurach/tty-command/blob/49c37a895ccea107e8b78d20e4cb29de6a1a53c8/lib/tty/command/process_runner.rb#L165-L193 + def read_stream(stream, handler, timeout:) + Thread.new do + Thread.current.report_on_exception = false + cmd_start = Time.now + readers = [stream] + + while readers.any? + ready = IO.select(readers, nil, readers, timeout) + raise TimeoutExceeded if ready.nil? + + ready[0].each do |reader| + chunk = reader.readpartial(16 * 1024) + handler.call(chunk) + + # control total time spent reading + runtime = Time.now - cmd_start + time_left = timeout - runtime + raise TimeoutExceeded if time_left < 0.0 + rescue Errno::EAGAIN, Errno::EINTR + rescue EOFError, Errno::EPIPE, Errno::EIO + readers.delete(reader) + reader.close + end + end + end + end + + def all_commands_output + return "" if command_executions.empty? + + "\n\nCommands:\n#{command_executions.map(&:to_s_verbose).join("\n\n")}" + end + end +end diff --git a/spec/bundler/support/vendored_net_http.rb b/spec/bundler/support/vendored_net_http.rb new file mode 100644 index 0000000000..8ff2ccd1fe --- /dev/null +++ b/spec/bundler/support/vendored_net_http.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# This defined? guard can be removed once RubyGems 3.4 support is dropped. +# +# Bundler specs load this code from `spec/support/vendored_net_http.rb` to avoid +# activating the Bundler gem too early. Without this guard, we get redefinition +# warnings once Bundler is actually activated and +# `lib/bundler/vendored_net_http.rb` is required. This is not an issue in +# RubyGems versions including `rubygems/vendored_net_http` since `require` takes +# care of avoiding the double load. +# +unless defined?(Gem::Net) + begin + require "rubygems/vendored_net_http" + rescue LoadError + begin + require "rubygems/net/http" + rescue LoadError + require "net/http" + Gem::Net = Net + end + end +end diff --git a/spec/bundler/update/gemfile_spec.rb b/spec/bundler/update/gemfile_spec.rb index d32a7945b0..cb94799061 100644 --- a/spec/bundler/update/gemfile_spec.rb +++ b/spec/bundler/update/gemfile_spec.rb @@ -4,8 +4,8 @@ RSpec.describe "bundle update" do context "with --gemfile" do it "finds the gemfile" do gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle :install, gemfile: bundled_app("NotGemfile") @@ -14,15 +14,15 @@ RSpec.describe "bundle update" do # Specify BUNDLE_GEMFILE for `the_bundle` # to retrieve the proper Gemfile ENV["BUNDLE_GEMFILE"] = "NotGemfile" - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "myrack 1.0.0" end end context "with gemfile set via config" do before do gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' G bundle "config set --local gemfile #{bundled_app("NotGemfile")}" @@ -33,7 +33,7 @@ RSpec.describe "bundle update" do bundle "update", all: true bundle "list" - expect(out).to include("rack (1.0.0)") + expect(out).to include("myrack (1.0.0)") end it "uses the gemfile while in a subdirectory" do @@ -41,7 +41,7 @@ RSpec.describe "bundle update" do bundle "update", all: true, dir: bundled_app("subdir") bundle "list", dir: bundled_app("subdir") - expect(out).to include("rack (1.0.0)") + expect(out).to include("myrack (1.0.0)") end end end diff --git a/spec/bundler/update/gems/fund_spec.rb b/spec/bundler/update/gems/fund_spec.rb index 4a87c16bf7..a5624d3e0a 100644 --- a/spec/bundler/update/gems/fund_spec.rb +++ b/spec/bundler/update/gems/fund_spec.rb @@ -24,7 +24,7 @@ RSpec.describe "bundle update" do end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding_and_other_metadata' gem 'has_funding', '< 2.0' G @@ -35,7 +35,7 @@ RSpec.describe "bundle update" do context "when listed gems are updated" do before do gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" gem 'has_funding_and_other_metadata' gem 'has_funding' G diff --git a/spec/bundler/update/gems/post_install_spec.rb b/spec/bundler/update/gems/post_install_spec.rb index e3593387d4..9c71f6e0e3 100644 --- a/spec/bundler/update/gems/post_install_spec.rb +++ b/spec/bundler/update/gems/post_install_spec.rb @@ -5,8 +5,8 @@ RSpec.describe "bundle update" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack', "< 1.0" + source "https://gem.repo1" + gem 'myrack', "< 1.0" gem 'thin' G @@ -17,10 +17,10 @@ RSpec.describe "bundle update" do shared_examples "a config observer" do context "when ignore post-install messages for gem is set" do - let(:config) { "ignore_messages.rack true" } + let(:config) { "ignore_messages.myrack true" } it "doesn't display gem's post-install message" do - expect(out).not_to include("Rack's post install message") + expect(out).not_to include("Myrack's post install message") end end @@ -35,8 +35,8 @@ RSpec.describe "bundle update" do shared_examples "a post-install message outputter" do it "should display post-install messages for updated gems" do - expect(out).to include("Post-install message from rack:") - expect(out).to include("Rack's post install message") + expect(out).to include("Post-install message from myrack:") + expect(out).to include("Myrack's post install message") end it "should not display the post-install message for non-updated gems" do @@ -47,8 +47,8 @@ RSpec.describe "bundle update" do context "when listed gem is updated" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gem 'thin' G @@ -62,8 +62,8 @@ RSpec.describe "bundle update" do context "when dependency triggers update" do before do gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack-obama' + source "https://gem.repo1" + gem 'myrack-obama' gem 'thin' G diff --git a/spec/bundler/update/git_spec.rb b/spec/bundler/update/git_spec.rb index 3b7bbfd979..d6e95d27dd 100644 --- a/spec/bundler/update/git_spec.rb +++ b/spec/bundler/update/git_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "bundle update" do update_git "foo", branch: "omg" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :branch => "omg" do gem 'foo' end @@ -29,8 +29,8 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rails", :git => "#{file_uri_for(lib_path("rails"))}" + source "https://gem.repo1" + gem "rails", :git => "#{lib_path("rails")}" G bundle "update rails" @@ -42,7 +42,7 @@ RSpec.describe "bundle update" do update_git "foo", branch: "omg", path: lib_path("foo") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" git "#{lib_path("foo")}", :branch => "omg" do gem 'foo' end @@ -64,8 +64,8 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo"))}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo")}" gem "bar" G @@ -83,30 +83,30 @@ RSpec.describe "bundle update" do build_git "foo", path: lib_path("foo_two") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", "1.0", :git => "#{file_uri_for(lib_path("foo_one"))}" + source "https://gem.repo1" + gem "foo", "1.0", :git => "#{lib_path("foo_one")}" G FileUtils.rm_rf lib_path("foo_one") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", "1.0", :git => "#{file_uri_for(lib_path("foo_two"))}" + source "https://gem.repo1" + gem "foo", "1.0", :git => "#{lib_path("foo_two")}" G expect(err).to be_empty - expect(out).to include("Fetching #{file_uri_for(lib_path)}/foo_two") + expect(out).to include("Fetching #{lib_path}/foo_two") expect(out).to include("Bundle complete!") end it "fetches tags from the remote" do build_git "foo" @remote = build_git("bar", bare: true) - update_git "foo", remote: file_uri_for(@remote.path) + update_git "foo", remote: @remote.path update_git "foo", push: "main" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{@remote.path}" G @@ -115,7 +115,7 @@ RSpec.describe "bundle update" do update_git "foo", push: "fubar" gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem 'foo', :git => "#{@remote.path}", :tag => "fubar" G @@ -142,13 +142,13 @@ RSpec.describe "bundle update" do s.add_dependency "submodule" end - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", dir: lib_path("has_submodule-1.0") - sys_exec "git commit -m \"submodulator\"", dir: lib_path("has_submodule-1.0") + git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0") + git "commit -m \"submodulator\"", lib_path("has_submodule-1.0") end it "it unlocks the source when submodules are added to a git source" do install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}" do gem "has_submodule" end @@ -158,7 +158,7 @@ RSpec.describe "bundle update" do expect(out).to eq("GEM") install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}", :submodules => true do gem "has_submodule" end @@ -170,7 +170,7 @@ RSpec.describe "bundle update" do it "unlocks the source when submodules are removed from git source", git: ">= 2.9.0" do install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}", :submodules => true do gem "has_submodule" end @@ -180,7 +180,7 @@ RSpec.describe "bundle update" do expect(out).to eq("GIT") install_gemfile <<-G - source "#{file_uri_for(gem_repo4)}" + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}" do gem "has_submodule" end @@ -195,8 +195,8 @@ RSpec.describe "bundle update" do build_git "foo", "1.0" install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}" + source "https://gem.repo1" + gem "foo", :git => "#{lib_path("foo-1.0")}" G lib_path("foo-1.0").join(".git").rmtree @@ -207,19 +207,19 @@ RSpec.describe "bundle update" do end it "should not explode on invalid revision on update of gem by name" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - build_git "rack", "0.8", path: lib_path("local-rack") do |s| - s.write "lib/rack.rb", "puts :LOCAL" + build_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack", :git => "#{file_uri_for(lib_path("rack-0.8"))}", :branch => "main" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config set local.rack #{lib_path("local-rack")}) - bundle "update rack" + bundle %(config set local.myrack #{lib_path("local-myrack")}) + bundle "update myrack" expect(out).to include("Bundle updated!") end @@ -227,14 +227,14 @@ RSpec.describe "bundle update" do build_git "rails", "2.3.2", path: lib_path("rails") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rails", :git => "#{file_uri_for(lib_path("rails"))}" + source "https://gem.repo1" + gem "rails", :git => "#{lib_path("rails")}" G update_git "rails", "3.0", path: lib_path("rails"), gemspec: true bundle "update", all: true - expect(out).to include("Using rails 3.0 (was 2.3.2) from #{file_uri_for(lib_path("rails"))} (at main@#{revision_for(lib_path("rails"))[0..6]})") + expect(out).to include("Using rails 3.0 (was 2.3.2) from #{lib_path("rails")} (at main@#{revision_for(lib_path("rails"))[0..6]})") end end @@ -246,11 +246,11 @@ RSpec.describe "bundle update" do end install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" git "#{lib_path("foo")}" do gem 'foo' end - gem 'rack' + gem 'myrack' G end @@ -279,7 +279,7 @@ RSpec.describe "bundle update" do update_git "foo", path: @git.path bundle "update --source foo" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end @@ -289,11 +289,11 @@ RSpec.describe "bundle update" do @git = build_git "foo", path: lib_path("bar") install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "https://gem.repo2" git "#{lib_path("bar")}" do gem 'foo' end - gem 'rack' + gem 'myrack' G end @@ -311,7 +311,7 @@ RSpec.describe "bundle update" do checksums = checksums_section_when_existing do |c| c.no_checksum "foo", "2.0" - c.checksum gem_repo2, "rack", "1.0.0" + c.checksum gem_repo2, "myrack", "1.0.0" end expect(lockfile).to eq <<~G @@ -322,16 +322,16 @@ RSpec.describe "bundle update" do foo (2.0) GEM - remote: #{file_uri_for(gem_repo2)}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES foo! - rack + myrack #{checksums} BUNDLED WITH #{Bundler::VERSION} diff --git a/spec/bundler/update/path_spec.rb b/spec/bundler/update/path_spec.rb index 1f8992b33f..8c76c94e1a 100644 --- a/spec/bundler/update/path_spec.rb +++ b/spec/bundler/update/path_spec.rb @@ -6,7 +6,7 @@ RSpec.describe "path sources" do build_lib "activesupport", "2.3.5", path: lib_path("rails/activesupport") install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "https://gem.repo1" gem "activesupport", :path => "#{lib_path("rails/activesupport")}" G diff --git a/spec/bundler/update/redownload_spec.rb b/spec/bundler/update/redownload_spec.rb index 4a8c711bfa..66437fb938 100644 --- a/spec/bundler/update/redownload_spec.rb +++ b/spec/bundler/update/redownload_spec.rb @@ -3,42 +3,42 @@ RSpec.describe "bundle update" do before :each do install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" + source "https://gem.repo1" + gem "myrack" G end describe "with --force" do it "shows a deprecation when single flag passed", bundler: 2 do - bundle "update rack --force" + bundle "update myrack --force" expect(err).to include "[DEPRECATED] The `--force` option has been renamed to `--redownload`" end it "shows a deprecation when multiple flags passed", bundler: 2 do - bundle "update rack --no-color --force" + bundle "update myrack --no-color --force" expect(err).to include "[DEPRECATED] The `--force` option has been renamed to `--redownload`" end end describe "with --redownload" do it "does not show a deprecation when single flag passed" do - bundle "update rack --redownload" + bundle "update myrack --redownload" expect(err).not_to include "[DEPRECATED] The `--force` option has been renamed to `--redownload`" end it "does not show a deprecation when single multiple flags passed" do - bundle "update rack --no-color --redownload" + bundle "update myrack --no-color --redownload" expect(err).not_to include "[DEPRECATED] The `--force` option has been renamed to `--redownload`" end it "re-installs installed gems" do - rack_lib = default_bundle_path("gems/rack-1.0.0/lib/rack.rb") - rack_lib.open("w") {|f| f.write("blah blah blah") } + myrack_lib = default_bundle_path("gems/myrack-1.0.0/lib/myrack.rb") + myrack_lib.open("w") {|f| f.write("blah blah blah") } bundle :update, redownload: true - expect(out).to include "Installing rack 1.0.0" - expect(rack_lib.open(&:read)).to eq("RACK = '1.0.0'\n") - expect(the_bundle).to include_gems "rack 1.0.0" + expect(out).to include "Installing myrack 1.0.0" + expect(myrack_lib.open(&:read)).to eq("MYRACK = '1.0.0'\n") + expect(the_bundle).to include_gems "myrack 1.0.0" end end end diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index 7014843bba..5b6ba999a4 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -816,9 +816,15 @@ class Gem::TestCase < Test::Unit::TestCase Gem::Specification.unresolved_deps.values.map(&:to_s).sort end - def new_default_spec(name, version, deps = nil, *files) + def new_default_spec(name, version, deps = nil, *files, executable: false) spec = util_spec name, version, deps + if executable + spec.executables = %w[executable] + + write_file File.join(@tempdir, "bin", "executable") + end + spec.loaded_from = File.join(@gemhome, "specifications", "default", spec.spec_name) spec.files = files @@ -827,10 +833,8 @@ class Gem::TestCase < Test::Unit::TestCase Gem.instance_variable_set(:@default_gem_load_paths, [*Gem.send(:default_gem_load_paths), lib_dir]) $LOAD_PATH.unshift(lib_dir) files.each do |file| - rb_path = File.join(lib_dir, file) - FileUtils.mkdir_p(File.dirname(rb_path)) - File.open(rb_path, "w") do |rb| - rb << "# #{file}" + write_file File.join(lib_dir, file) do |io| + io.write "# #{file}" end end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 40a473f8d6..e8a294d65c 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1562,21 +1562,20 @@ class TestGem < Gem::TestCase assert_equal m1.gem_dir, File.join(Gem.user_dir, "gems", "m-1") tests = [ - [:dir0, [Gem.dir, Gem.user_dir], m0], - [:dir1, [Gem.user_dir, Gem.dir], m1], + [:dir0, [Gem.dir, Gem.user_dir]], + [:dir1, [Gem.user_dir, Gem.dir]], ] - tests.each do |name, paths, expected| + tests.each do |name, paths| Gem.use_paths paths.first, paths - Gem::Specification.reset Gem.searcher = nil assert_equal Gem::Dependency.new("m","1").to_specs, Gem::Dependency.new("m","1").to_specs.sort assert_equal \ - [expected.gem_dir], - Gem::Dependency.new("m","1").to_specs.map(&:gem_dir).sort, + [m0.gem_dir, m1.gem_dir], + Gem::Dependency.new("m","1").to_specs.map(&:gem_dir).uniq.sort, "Wrong specs for #{name}" spec = Gem::Dependency.new("m","1").to_spec @@ -1616,9 +1615,11 @@ class TestGem < Gem::TestCase Gem.use_paths Gem.dir, [Gem.dir, Gem.user_dir] + spec = Gem::Dependency.new("m", "1").to_spec + assert_equal \ File.join(Gem.dir, "gems", "m-1"), - Gem::Dependency.new("m","1").to_spec.gem_dir, + spec.gem_dir, "Wrong spec selected" end diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb index 6d88810493..b72670b802 100644 --- a/test/rubygems/test_gem_bundler_version_finder.rb +++ b/test/rubygems/test_gem_bundler_version_finder.rb @@ -45,6 +45,8 @@ class TestGemBundlerVersionFinder < Gem::TestCase 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 = "/foo/bar/bundler" + assert_equal v("1.1.1.1"), bvf.bundler_version $0 = "other" assert_nil bvf.bundler_version end diff --git a/test/rubygems/test_gem_commands_exec_command.rb b/test/rubygems/test_gem_commands_exec_command.rb index e52fe247a2..8d9c810d59 100644 --- a/test/rubygems/test_gem_commands_exec_command.rb +++ b/test/rubygems/test_gem_commands_exec_command.rb @@ -182,7 +182,7 @@ class TestGemCommandsExecCommand < Gem::TestCase fetcher.download "a", 2 do |s| s.executables = %w[a] s.files = %w[bin/a lib/a.rb] - s.add_runtime_dependency "with_platform" + s.add_dependency "with_platform" write_file File.join(*%W[gems #{s.original_name} bin a]) do |f| f << 'require "with_platform"' << "\n" @@ -222,7 +222,7 @@ class TestGemCommandsExecCommand < Gem::TestCase fetcher.download "a", 2 do |s| s.executables = %w[a] s.files = %w[bin/a lib/a.rb] - s.add_runtime_dependency "with_platform" + s.add_dependency "with_platform" s.platform = Gem::Platform.local.to_s write_file File.join(*%W[gems #{s.original_name} bin a]) do |f| @@ -234,7 +234,7 @@ class TestGemCommandsExecCommand < Gem::TestCase fetcher.download "a", 2 do |s| s.executables = %w[a] s.files = %w[bin/a lib/a.rb extconf.rb] - s.add_runtime_dependency "with_platform" + s.add_dependency "with_platform" write_file File.join(*%W[gems #{s.original_name} bin a]) do |f| f << 'require "with_platform"' << "\n" @@ -261,7 +261,7 @@ class TestGemCommandsExecCommand < Gem::TestCase fetcher.download "with_platform", 2 do |s| s.files = %w[lib/with_platform.rb] - s.add_runtime_dependency "sometimes_used" + s.add_dependency "sometimes_used" end fetcher.download "sometimes_used", 2 do |s| @@ -677,7 +677,7 @@ class TestGemCommandsExecCommand < Gem::TestCase fetcher.gem "a", 1 do |s| s.executables = %w[] s.files = %w[lib/a.rb] - s.add_runtime_dependency "b" + s.add_dependency "b" end fetcher.gem "b", 1 do |s| @@ -711,7 +711,7 @@ class TestGemCommandsExecCommand < Gem::TestCase fetcher.download "a", 2 do |s| s.executables = %w[a] s.files = %w[bin/a lib/a.rb] - s.add_runtime_dependency "b" + s.add_dependency "b" write_file File.join(*%W[gems #{s.original_name} bin a]) do |f| f << "Gem.ui.say #{s.original_name.dump}" diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb index 6afe4f35c5..02a7103f89 100644 --- a/test/rubygems/test_gem_commands_lock_command.rb +++ b/test/rubygems/test_gem_commands_lock_command.rb @@ -9,11 +9,11 @@ class TestGemCommandsLockCommand < Gem::TestCase @a1 = quick_gem "a", "1" @b1 = quick_gem "b", "1" do |s| - s.add_runtime_dependency "a" + s.add_dependency "a" end @d1 = quick_gem "d", "1" do |s| - s.add_runtime_dependency "z" + s.add_dependency "z" end @cmd = Gem::Commands::LockCommand.new diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index a17d7837c9..b8b39133ff 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -96,7 +96,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase out = @ui.output.split("\n") assert_equal "Restoring gems to pristine condition...", out.shift - assert_equal "Restored #{a.full_name}", out.shift + assert_equal "Restored #{a.full_name} in #{Gem.user_dir}", out.shift assert_empty out, out.inspect ensure FileUtils.chmod(0o755, @gemhome) @@ -404,7 +404,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase out = @ui.output.split "\n" assert_equal "Restoring gems to pristine condition...", out.shift - assert_equal "Restored #{a.full_name}", out.shift + assert_equal "Restored #{a.full_name} in #{@gemhome}", out.shift assert_equal "Restored #{b.full_name}", out.shift assert_empty out, out.inspect @@ -476,8 +476,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase [ "Restoring gems to pristine condition...", - "Cached gem for a-1 not found, attempting to fetch...", - "Restored a-1", + "Cached gem for a-1 in #{@gemhome} not found, attempting to fetch...", + "Restored a-1 in #{@gemhome}", + "Restored b-1 in #{@gemhome}", "Cached gem for b-1 not found, attempting to fetch...", "Restored b-1", ].each do |line| @@ -495,7 +496,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase assert_path_exist File.join(gemhome2, "cache", "b-1.gem") assert_path_not_exist File.join(@gemhome, "cache", "b-2.gem") assert_path_exist File.join(gemhome2, "gems", "b-1") - assert_path_not_exist File.join(@gemhome, "gems", "b-1") + assert_path_exist File.join(@gemhome, "gems", "b-1") end def test_execute_no_gem diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index 77d75e6b88..8eedb6c03a 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -31,7 +31,6 @@ class TestGemCommandsSetupCommand < Gem::TestCase bundler/lib/bundler/man/gemfile.5 bundler/lib/bundler/man/gemfile.5.ronn bundler/lib/bundler/templates/.circleci/config.yml - bundler/lib/bundler/templates/.travis.yml ] create_dummy_files(filelist) @@ -195,7 +194,6 @@ class TestGemCommandsSetupCommand < Gem::TestCase assert_path_exist File.join(dir, "bundler/b.rb") assert_path_exist File.join(dir, "bundler/templates/.circleci/config.yml") - assert_path_exist File.join(dir, "bundler/templates/.travis.yml") end end diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 4daa61cb0c..81fadfcb99 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -32,7 +32,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase @cmd.execute end - assert_equal %w[a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1], + assert_equal %w[a-4 a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1], Gem::Specification.all_names.sort end @@ -81,6 +81,35 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert_equal "Successfully uninstalled z-2", output.shift end + def test_execute_does_not_remove_default_gem_executables + z_1_default = new_default_spec "z", "1", executable: true + install_default_gems z_1_default + + z_1, = util_gem "z", "1" do |spec| + util_make_exec spec + end + install_gem z_1, force: true + + Gem::Specification.reset + + @cmd.options[:all] = true + @cmd.options[:force] = true + @cmd.options[:executables] = true + @cmd.options[:args] = %w[z] + + use_ui @ui do + @cmd.execute + end + + assert File.exist? File.join(@gemhome, "bin", "executable") + + output = @ui.output.split "\n" + + refute_includes output, "Removing executable" + assert_equal "Successfully uninstalled z-1", output.shift + assert_equal "There was both a regular copy and a default copy of z-1. The regular copy was successfully uninstalled, but the default copy was left around because default gems can't be removed.", output.shift + end + def test_execute_dependency_order initial_install diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 2683840f2e..194ebb030a 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -217,7 +217,15 @@ class TestGemCommandsUpdateCommand < Gem::TestCase end def test_execute_system_update_installed_in_non_default_gem_path - rubygems_update_spec = quick_gem "rubygems-update", 9 do |s| + rubygems_update_spec = Gem::Specification.new do |s| + s.name = "rubygems-update" + s.version = "9" + s.author = "A User" + s.email = "[email protected]" + s.homepage = "http://example.com" + s.summary = "this is a summary" + s.description = "This is a test description" + write_file File.join(@tempdir, "setup.rb") s.files += %w[setup.rb] diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index c56fa1a3cc..50fdfc6f90 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -568,4 +568,71 @@ if you believe they were disclosed to a third party. actual = Gem::ConfigFile.load_with_rubygems_config_hash(yaml) assert_equal("bar", actual[:foo]) end + + def test_s3_source + yaml = <<~YAML + --- + :sources: + - s3://bucket1/ + - s3://bucket2/ + - s3://bucket3/path_to_gems_dir/ + - s3://bucket4/ + - https://rubygems.org/ + :s3_source: + :bucket1: + :provider: env + :bucket2: + :provider: instance_profile + :region: us-west-2 + :bucket3: + :id: AOUEAOEU123123AOEUAO + :secret: aodnuhtdao/saeuhto+19283oaehu/asoeu+123h + :region: us-east-2 + :bucket4: + :id: AOUEAOEU123123AOEUAO + :secret: aodnuhtdao/saeuhto+19283oaehu/asoeu+123h + :security_token: AQoDYXdzEJr + :region: us-west-1 + YAML + + File.open @temp_conf, "w" do |fp| + fp.puts yaml + end + util_config_file + + assert_equal(["s3://bucket1/", "s3://bucket2/", "s3://bucket3/path_to_gems_dir/", "s3://bucket4/", "https://rubygems.org/"], @cfg.sources) + expected_config = { + bucket1: { provider: "env" }, + bucket2: { provider: "instance_profile", region: "us-west-2" }, + bucket3: { id: "AOUEAOEU123123AOEUAO", secret: "aodnuhtdao/saeuhto+19283oaehu/asoeu+123h", region: "us-east-2" }, + bucket4: { id: "AOUEAOEU123123AOEUAO", secret: "aodnuhtdao/saeuhto+19283oaehu/asoeu+123h", security_token: "AQoDYXdzEJr", region: "us-west-1" }, + } + assert_equal(expected_config, @cfg[:s3_source]) + assert_equal(expected_config[:bucket1], @cfg[:s3_source][:bucket1]) + assert_equal(expected_config[:bucket2], @cfg[:s3_source][:bucket2]) + assert_equal(expected_config[:bucket3], @cfg[:s3_source][:bucket3]) + assert_equal(expected_config[:bucket4], @cfg[:s3_source][:bucket4]) + end + + def test_s3_source_with_config_without_lookahead + yaml = <<~YAML + :sources: + - s3://bucket1/ + s3_source: + bucket1: + provider: env + YAML + + File.open @temp_conf, "w" do |fp| + fp.puts yaml + end + util_config_file + + assert_equal(["s3://bucket1/"], @cfg.sources) + expected_config = { + "bucket1" => { "provider" => "env" }, + } + assert_equal(expected_config, @cfg[:s3_source]) + assert_equal(expected_config[:bucket1], @cfg[:s3_source][:bucket1]) + end end diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock index abd1e0ae33..40532cf46c 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock @@ -152,18 +152,18 @@ dependencies = [ [[package]] name = "rb-sys" -version = "0.9.97" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d30bcad206b51f2f66121190ca678dce1fdf3a2eae0ac5d838d1818b19bdf5" +checksum = "8914b2e6af10bd50dd7aaac8c5146872d3924d6012929b4ff504e988f6badd24" dependencies = [ "rb-sys-build", ] [[package]] name = "rb-sys-build" -version = "0.9.97" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbd92f281615f3c2dcb9dcb0f0576624752afbf9a7f99173b37c4b55b62dd8a" +checksum = "12af68c9757d419b82d65a12b5db538990dfe9416049fea3f0ba4b9a8ca108cd" dependencies = [ "bindgen", "lazy_static", diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml index ad3e7f9b76..f28abd74a0 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -rb-sys = "0.9.97" +rb-sys = "0.9.98" diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock index 1d174f569e..f3969f3621 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock @@ -145,18 +145,18 @@ dependencies = [ [[package]] name = "rb-sys" -version = "0.9.97" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d30bcad206b51f2f66121190ca678dce1fdf3a2eae0ac5d838d1818b19bdf5" +checksum = "8914b2e6af10bd50dd7aaac8c5146872d3924d6012929b4ff504e988f6badd24" dependencies = [ "rb-sys-build", ] [[package]] name = "rb-sys-build" -version = "0.9.97" +version = "0.9.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbd92f281615f3c2dcb9dcb0f0576624752afbf9a7f99173b37c4b55b62dd8a" +checksum = "12af68c9757d419b82d65a12b5db538990dfe9416049fea3f0ba4b9a8ca108cd" dependencies = [ "bindgen", "lazy_static", diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml index 60cf49ce03..ac8fd45bc6 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -rb-sys = "0.9.97" +rb-sys = "0.9.98" diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 00e48498c6..070c8007bc 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -90,46 +90,46 @@ class TestGemPlatform < Gem::TestCase "java" => [nil, "java", nil], "jruby" => [nil, "java", nil], "universal-dotnet" => ["universal", "dotnet", nil], - "universal-dotnet2.0" => ["universal", "dotnet", "2.0"], - "universal-dotnet4.0" => ["universal", "dotnet", "4.0"], + "universal-dotnet2.0" => ["universal", "dotnet", "2.0"], + "universal-dotnet4.0" => ["universal", "dotnet", "4.0"], "powerpc-aix5.3.0.0" => ["powerpc", "aix", "5"], - "powerpc-darwin7" => ["powerpc", "darwin", "7"], - "powerpc-darwin8" => ["powerpc", "darwin", "8"], + "powerpc-darwin7" => ["powerpc", "darwin", "7"], + "powerpc-darwin8" => ["powerpc", "darwin", "8"], "powerpc-linux" => ["powerpc", "linux", nil], "powerpc64-linux" => ["powerpc64", "linux", nil], "sparc-solaris2.10" => ["sparc", "solaris", "2.10"], - "sparc-solaris2.8" => ["sparc", "solaris", "2.8"], - "sparc-solaris2.9" => ["sparc", "solaris", "2.9"], - "universal-darwin8" => ["universal", "darwin", "8"], - "universal-darwin9" => ["universal", "darwin", "9"], - "universal-macruby" => ["universal", "macruby", nil], - "i386-cygwin" => ["x86", "cygwin", nil], - "i686-darwin" => ["x86", "darwin", nil], - "i686-darwin8.4.1" => ["x86", "darwin", "8"], - "i386-freebsd4.11" => ["x86", "freebsd", "4"], - "i386-freebsd5" => ["x86", "freebsd", "5"], - "i386-freebsd6" => ["x86", "freebsd", "6"], - "i386-freebsd7" => ["x86", "freebsd", "7"], + "sparc-solaris2.8" => ["sparc", "solaris", "2.8"], + "sparc-solaris2.9" => ["sparc", "solaris", "2.9"], + "universal-darwin8" => ["universal", "darwin", "8"], + "universal-darwin9" => ["universal", "darwin", "9"], + "universal-macruby" => ["universal", "macruby", nil], + "i386-cygwin" => ["x86", "cygwin", nil], + "i686-darwin" => ["x86", "darwin", nil], + "i686-darwin8.4.1" => ["x86", "darwin", "8"], + "i386-freebsd4.11" => ["x86", "freebsd", "4"], + "i386-freebsd5" => ["x86", "freebsd", "5"], + "i386-freebsd6" => ["x86", "freebsd", "6"], + "i386-freebsd7" => ["x86", "freebsd", "7"], "i386-freebsd" => ["x86", "freebsd", nil], "universal-freebsd" => ["universal", "freebsd", nil], "i386-java1.5" => ["x86", "java", "1.5"], "x86-java1.6" => ["x86", "java", "1.6"], "i386-java1.6" => ["x86", "java", "1.6"], - "i686-linux" => ["x86", "linux", nil], - "i586-linux" => ["x86", "linux", nil], - "i486-linux" => ["x86", "linux", nil], - "i386-linux" => ["x86", "linux", nil], - "i586-linux-gnu" => ["x86", "linux", "gnu"], - "i386-linux-gnu" => ["x86", "linux", "gnu"], + "i686-linux" => ["x86", "linux", nil], + "i586-linux" => ["x86", "linux", nil], + "i486-linux" => ["x86", "linux", nil], + "i386-linux" => ["x86", "linux", nil], + "i586-linux-gnu" => ["x86", "linux", "gnu"], + "i386-linux-gnu" => ["x86", "linux", "gnu"], "i386-mingw32" => ["x86", "mingw32", nil], "x64-mingw-ucrt" => ["x64", "mingw", "ucrt"], "i386-mswin32" => ["x86", "mswin32", nil], - "i386-mswin32_80" => ["x86", "mswin32", "80"], - "i386-mswin32-80" => ["x86", "mswin32", "80"], + "i386-mswin32_80" => ["x86", "mswin32", "80"], + "i386-mswin32-80" => ["x86", "mswin32", "80"], "x86-mswin32" => ["x86", "mswin32", nil], - "x86-mswin32_60" => ["x86", "mswin32", "60"], - "x86-mswin32-60" => ["x86", "mswin32", "60"], - "i386-netbsdelf" => ["x86", "netbsdelf", nil], + "x86-mswin32_60" => ["x86", "mswin32", "60"], + "x86-mswin32-60" => ["x86", "mswin32", "60"], + "i386-netbsdelf" => ["x86", "netbsdelf", nil], "i386-openbsd4.0" => ["x86", "openbsd", "4.0"], "i386-solaris2.10" => ["x86", "solaris", "2.10"], "i386-solaris2.8" => ["x86", "solaris", "2.8"], @@ -142,8 +142,8 @@ class TestGemPlatform < Gem::TestCase "arm-linux-gnueabi" => ["arm", "linux", "gnueabi"], "arm-linux-musleabi" => ["arm", "linux", "musleabi"], "arm-linux-uclibceabi" => ["arm", "linux", "uclibceabi"], - "x86_64-openbsd3.9" => ["x86_64", "openbsd", "3.9"], - "x86_64-openbsd4.0" => ["x86_64", "openbsd", "4.0"], + "x86_64-openbsd3.9" => ["x86_64", "openbsd", "3.9"], + "x86_64-openbsd4.0" => ["x86_64", "openbsd", "4.0"], "x86_64-openbsd" => ["x86_64", "openbsd", nil], "wasm32-wasi" => ["wasm32", "wasi", nil], "wasm32-wasip1" => ["wasm32", "wasi", nil], @@ -368,18 +368,27 @@ class TestGemPlatform < Gem::TestCase arm = Gem::Platform.new "arm-linux" armv5 = Gem::Platform.new "armv5-linux" armv7 = Gem::Platform.new "armv7-linux" + arm64 = Gem::Platform.new "arm64-linux" util_set_arch "armv5-linux" assert((arm === Gem::Platform.local), "arm === armv5") assert((armv5 === Gem::Platform.local), "armv5 === armv5") refute((armv7 === Gem::Platform.local), "armv7 === armv5") + refute((arm64 === Gem::Platform.local), "arm64 === armv5") refute((Gem::Platform.local === arm), "armv5 === arm") util_set_arch "armv7-linux" assert((arm === Gem::Platform.local), "arm === armv7") refute((armv5 === Gem::Platform.local), "armv5 === armv7") assert((armv7 === Gem::Platform.local), "armv7 === armv7") + refute((arm64 === Gem::Platform.local), "arm64 === armv7") refute((Gem::Platform.local === arm), "armv7 === arm") + + util_set_arch "arm64-linux" + refute((arm === Gem::Platform.local), "arm === arm64") + refute((armv5 === Gem::Platform.local), "armv5 === arm64") + refute((armv7 === Gem::Platform.local), "armv7 === arm64") + assert((arm64 === Gem::Platform.local), "arm64 === arm64") end def test_equals3_universal_mingw diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index e71b2f5ff6..ca858cfda5 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -2,105 +2,14 @@ require_relative "helper" -require "webrick" -require "webrick/https" if Gem::HAVE_OPENSSL - -unless Gem::HAVE_OPENSSL - warn "Skipping Gem::RemoteFetcher tests. openssl not found." -end - require "rubygems/remote_fetcher" require "rubygems/package" -# = Testing Proxy Settings -# -# These tests check the proper proxy server settings by running two -# web servers. The web server at http://localhost:#{SERVER_PORT} -# represents the normal gem server and returns a gemspec with a rake -# version of 0.4.11. The web server at http://localhost:#{PROXY_PORT} -# represents the proxy server and returns a different dataset where -# rake has version 0.4.2. This allows us to detect which server is -# returning the data. -# -# Note that the proxy server is not a *real* proxy server. But our -# software doesn't really care, as long as we hit the proxy URL when a -# proxy is configured. - class TestGemRemoteFetcher < Gem::TestCase include Gem::DefaultUserInteraction - SERVER_DATA = <<-EOY ---- !ruby/object:Gem::Cache -gems: - rake-0.4.11: !ruby/object:Gem::Specification - rubygems_version: "0.7" - specification_version: 1 - name: rake - version: !ruby/object:Gem::Version - version: 0.4.11 - date: 2004-11-12 - summary: Ruby based make-like utility. - require_paths: - - lib - author: Jim Weirich - email: [email protected] - homepage: http://rake.rubyforge.org - description: Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax. - autorequire: - bindir: bin - has_rdoc: true - required_ruby_version: !ruby/object:Gem::Version::Requirement - requirements: - - - - ">" - - !ruby/object:Gem::Version - version: 0.0.0 - version: - platform: ruby - files: - - README - test_files: [] - library_stubs: - rdoc_options: - extra_rdoc_files: - executables: - - rake - extensions: [] - requirements: [] - dependencies: [] - EOY - - PROXY_DATA = SERVER_DATA.gsub(/0.4.11/, "0.4.2") - - # Generated via: - # x = OpenSSL::PKey::DH.new(2048) # wait a while... - # x.to_s => pem - TEST_KEY_DH2048 = OpenSSL::PKey::DH.new <<-_END_OF_PEM_ ------BEGIN DH PARAMETERS----- -MIIBCAKCAQEA3Ze2EHSfYkZLUn557torAmjBgPsqzbodaRaGZtgK1gEU+9nNJaFV -G1JKhmGUiEDyIW7idsBpe4sX/Wqjnp48Lr8IeI/SlEzLdoGpf05iRYXC8Cm9o8aM -cfmVgoSEAo9YLBpzoji2jHkO7Q5IPt4zxbTdlmmGFLc/GO9q7LGHhC+rcMcNTGsM -49AnILNn49pq4Y72jSwdmvq4psHZwwFBbPwLdw6bLUDDCN90jfqvYt18muwUxDiN -NP0fuvVAIB158VnQ0liHSwcl6+9vE1mL0Jo/qEXQxl0+UdKDjaGfTsn6HIrwTnmJ -PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== ------END DH PARAMETERS----- - _END_OF_PEM_ - def setup - @proxies = %w[https_proxy http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY] - @old_proxies = @proxies.map {|k| ENV[k] } - @proxies.each {|k| ENV[k] = nil } - super - start_servers - self.enable_yaml = true - self.enable_zip = false - - base_server_uri = "http://localhost:#{normal_server_port}" - @proxy_uri = "http://localhost:#{proxy_server_port}" - - @server_uri = base_server_uri + "/yaml" - @server_z_uri = base_server_uri + "/yaml.Z" @cache_dir = File.join @gemhome, "cache" @@ -116,14 +25,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== @fetcher = Gem::RemoteFetcher.fetcher end - def teardown - @fetcher.close_all - stop_servers - super - Gem.configuration[:http_proxy] = nil - @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] } - end - def test_self_fetcher fetcher = Gem::RemoteFetcher.fetcher refute_nil fetcher @@ -140,6 +41,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== refute_nil fetcher assert_kind_of Gem::RemoteFetcher, fetcher assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy).to_s + ensure + Gem.configuration[:http_proxy] = nil end def test_fetch_path_bad_uri @@ -153,14 +56,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== assert_equal "uri scheme is invalid: nil", e.message end - def test_no_proxy - use_ui @stub_ui do - assert_data_from_server @fetcher.fetch_path(@server_uri) - response = @fetcher.fetch_path(@server_uri, nil, true) - assert_equal SERVER_DATA.size, response["content-length"].to_i - end - end - def test_cache_update_path uri = Gem::URI "http://example/file" path = File.join @tempdir, "file" @@ -616,41 +511,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== assert_nil fetcher.fetch_path(Gem::URI.parse(@gem_repo), Time.at(0)) end - def test_implicit_no_proxy - use_ui @stub_ui do - ENV["http_proxy"] = "http://fakeurl:12345" - fetcher = Gem::RemoteFetcher.new :no_proxy - @fetcher = fetcher - assert_data_from_server fetcher.fetch_path(@server_uri) - end - end - - def test_implicit_proxy - use_ui @stub_ui do - ENV["http_proxy"] = @proxy_uri - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - assert_data_from_proxy fetcher.fetch_path(@server_uri) - end - end - - def test_implicit_upper_case_proxy - use_ui @stub_ui do - ENV["HTTP_PROXY"] = @proxy_uri - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - assert_data_from_proxy fetcher.fetch_path(@server_uri) - end - end - - def test_implicit_proxy_no_env - use_ui @stub_ui do - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - assert_data_from_server fetcher.fetch_path(@server_uri) - end - end - def test_fetch_http fetcher = Gem::RemoteFetcher.new nil @fetcher = fetcher @@ -712,247 +572,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== assert_equal "redirecting but no redirect location was given (#{url})", e.message end - def test_fetch_http_with_additional_headers - ENV["http_proxy"] = @proxy_uri - ENV["no_proxy"] = Gem::URI.parse(@server_uri).host - fetcher = Gem::RemoteFetcher.new nil, nil, { "X-Captain" => "murphy" } - @fetcher = fetcher - assert_equal "murphy", fetcher.fetch_path(@server_uri) - end - - def assert_fetch_s3(url, signature, token=nil, region="us-east-1", instance_profile_json=nil) - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - $fetched_uri = nil - $instance_profile = instance_profile_json - - def fetcher.request(uri, request_class, last_modified = nil) - $fetched_uri = uri - res = Gem::Net::HTTPOK.new nil, 200, nil - def res.body - "success" - end - res - end - - def fetcher.s3_uri_signer(uri) - require "json" - s3_uri_signer = Gem::S3URISigner.new(uri) - def s3_uri_signer.ec2_metadata_credentials_json - JSON.parse($instance_profile) - end - # Running sign operation to make sure uri.query is not mutated - s3_uri_signer.sign - raise "URI query is not empty: #{uri.query}" unless uri.query.nil? - s3_uri_signer - end - - data = fetcher.fetch_s3 Gem::URI.parse(url) - - assert_equal "https://my-bucket.s3.#{region}.amazonaws.com/gems/specs.4.8.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=testuser%2F20190624%2F#{region}%2Fs3%2Faws4_request&X-Amz-Date=20190624T050641Z&X-Amz-Expires=86400#{token ? "&X-Amz-Security-Token=" + token : ""}&X-Amz-SignedHeaders=host&X-Amz-Signature=#{signature}", $fetched_uri.to_s - assert_equal "success", data - ensure - $fetched_uri = nil - end - - def test_fetch_s3_config_creds - Gem.configuration[:s3_source] = { - "my-bucket" => { id: "testuser", secret: "testpass" }, - } - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b" - end - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_config_creds_with_region - Gem.configuration[:s3_source] = { - "my-bucket" => { id: "testuser", secret: "testpass", region: "us-west-2" }, - } - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2" - end - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_config_creds_with_token - Gem.configuration[:s3_source] = { - "my-bucket" => { id: "testuser", secret: "testpass", security_token: "testtoken" }, - } - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken" - end - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_env_creds - ENV["AWS_ACCESS_KEY_ID"] = "testuser" - ENV["AWS_SECRET_ACCESS_KEY"] = "testpass" - ENV["AWS_SESSION_TOKEN"] = nil - Gem.configuration[:s3_source] = { - "my-bucket" => { provider: "env" }, - } - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b" - end - ensure - ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") } - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_env_creds_with_region - ENV["AWS_ACCESS_KEY_ID"] = "testuser" - ENV["AWS_SECRET_ACCESS_KEY"] = "testpass" - ENV["AWS_SESSION_TOKEN"] = nil - Gem.configuration[:s3_source] = { - "my-bucket" => { provider: "env", region: "us-west-2" }, - } - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2" - end - ensure - ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") } - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_env_creds_with_token - ENV["AWS_ACCESS_KEY_ID"] = "testuser" - ENV["AWS_SECRET_ACCESS_KEY"] = "testpass" - ENV["AWS_SESSION_TOKEN"] = "testtoken" - Gem.configuration[:s3_source] = { - "my-bucket" => { provider: "env" }, - } - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken" - end - ensure - ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") } - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_url_creds - url = "s3://testuser:testpass@my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b" - end - end - - def test_fetch_s3_instance_profile_creds - Gem.configuration[:s3_source] = { - "my-bucket" => { provider: "instance_profile" }, - } - - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b", nil, "us-east-1", - '{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}' - end - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_instance_profile_creds_with_region - Gem.configuration[:s3_source] = { - "my-bucket" => { provider: "instance_profile", region: "us-west-2" }, - } - - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2", - '{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}' - end - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_instance_profile_creds_with_token - Gem.configuration[:s3_source] = { - "my-bucket" => { provider: "instance_profile" }, - } - - url = "s3://my-bucket/gems/specs.4.8.gz" - Time.stub :now, Time.at(1_561_353_581) do - assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken", "us-east-1", - '{"AccessKeyId": "testuser", "SecretAccessKey": "testpass", "Token": "testtoken"}' - end - ensure - Gem.configuration[:s3_source] = nil - end - - def refute_fetch_s3(url, expected_message) - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - - e = assert_raise Gem::RemoteFetcher::FetchError do - fetcher.fetch_s3 Gem::URI.parse(url) - end - - assert_match expected_message, e.message - end - - def test_fetch_s3_no_source_key - url = "s3://my-bucket/gems/specs.4.8.gz" - refute_fetch_s3 url, "no s3_source key exists in .gemrc" - end - - def test_fetch_s3_no_host - Gem.configuration[:s3_source] = { - "my-bucket" => { id: "testuser", secret: "testpass" }, - } - - url = "s3://other-bucket/gems/specs.4.8.gz" - refute_fetch_s3 url, "no key for host other-bucket in s3_source in .gemrc" - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_no_id - Gem.configuration[:s3_source] = { "my-bucket" => { secret: "testpass" } } - - url = "s3://my-bucket/gems/specs.4.8.gz" - refute_fetch_s3 url, "s3_source for my-bucket missing id or secret" - ensure - Gem.configuration[:s3_source] = nil - end - - def test_fetch_s3_no_secret - Gem.configuration[:s3_source] = { "my-bucket" => { id: "testuser" } } - - url = "s3://my-bucket/gems/specs.4.8.gz" - refute_fetch_s3 url, "s3_source for my-bucket missing id or secret" - ensure - Gem.configuration[:s3_source] = nil - end - - def test_observe_no_proxy_env_single_host - use_ui @stub_ui do - ENV["http_proxy"] = @proxy_uri - ENV["no_proxy"] = Gem::URI.parse(@server_uri).host - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - assert_data_from_server fetcher.fetch_path(@server_uri) - end - end - - def test_observe_no_proxy_env_list - use_ui @stub_ui do - ENV["http_proxy"] = @proxy_uri - ENV["no_proxy"] = "fakeurl.com, #{Gem::URI.parse(@server_uri).host}" - fetcher = Gem::RemoteFetcher.new nil - @fetcher = fetcher - assert_data_from_server fetcher.fetch_path(@server_uri) - end - end - def test_request_block fetcher = Gem::RemoteFetcher.new nil @fetcher = fetcher @@ -967,112 +586,12 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_yaml_error_on_size use_ui @stub_ui do - self.enable_yaml = false fetcher = Gem::RemoteFetcher.new nil @fetcher = fetcher assert_error { fetcher.size } end end - def test_ssl_connection - ssl_server = start_ssl_server - temp_ca_cert = File.join(__dir__, "ca_cert.pem") - with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - - def test_ssl_client_cert_auth_connection - ssl_server = start_ssl_server( - { SSLVerifyClient: OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT } - ) - - temp_ca_cert = File.join(__dir__, "ca_cert.pem") - temp_client_cert = File.join(__dir__, "client.pem") - - with_configured_fetcher( - ":ssl_ca_cert: #{temp_ca_cert}\n" \ - ":ssl_client_cert: #{temp_client_cert}\n" - ) do |fetcher| - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - - def test_do_not_allow_invalid_client_cert_auth_connection - ssl_server = start_ssl_server( - { SSLVerifyClient: OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT } - ) - - temp_ca_cert = File.join(__dir__, "ca_cert.pem") - temp_client_cert = File.join(__dir__, "invalid_client.pem") - - with_configured_fetcher( - ":ssl_ca_cert: #{temp_ca_cert}\n" \ - ":ssl_client_cert: #{temp_client_cert}\n" - ) do |fetcher| - assert_raise Gem::RemoteFetcher::FetchError do - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - end - - def test_do_not_allow_insecure_ssl_connection_by_default - ssl_server = start_ssl_server - with_configured_fetcher do |fetcher| - assert_raise Gem::RemoteFetcher::FetchError do - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - end - - def test_ssl_connection_allow_verify_none - ssl_server = start_ssl_server - with_configured_fetcher(":ssl_verify_mode: 0") do |fetcher| - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - - def test_do_not_follow_insecure_redirect - ssl_server = start_ssl_server - temp_ca_cert = File.join(__dir__, "ca_cert.pem") - expected_error_message = - "redirecting to non-https resource: #{@server_uri} (https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri})" - - with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| - err = assert_raise Gem::RemoteFetcher::FetchError do - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/insecure_redirect?to=#{@server_uri}") - end - - assert_equal(err.message, expected_error_message) - end - end - - def test_nil_ca_cert - ssl_server = start_ssl_server - temp_ca_cert = nil - - with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| - assert_raise Gem::RemoteFetcher::FetchError do - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}") - end - end - end - - def with_configured_fetcher(config_str = nil, &block) - if config_str - temp_conf = File.join @tempdir, ".gemrc" - File.open temp_conf, "w" do |fp| - fp.puts config_str - end - Gem.configuration = Gem::ConfigFile.new %W[--config-file #{temp_conf}] - end - fetcher = Gem::RemoteFetcher.new - yield fetcher - ensure - fetcher.close_all - Gem.configuration = nil - end - def assert_error(exception_class=Exception) got_exception = false @@ -1084,152 +603,4 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== assert got_exception, "Expected exception conforming to #{exception_class}" end - - def assert_data_from_server(data) - assert_match(/0\.4\.11/, data, "Data is not from server") - end - - def assert_data_from_proxy(data) - assert_match(/0\.4\.2/, data, "Data is not from proxy") - end - - class NilLog < WEBrick::Log - def log(level, data) # Do nothing - end - end - - private - - attr_reader :normal_server, :proxy_server - attr_accessor :enable_zip, :enable_yaml - - def start_servers - @normal_server ||= start_server(SERVER_DATA) - @proxy_server ||= start_server(PROXY_DATA) - @enable_yaml = true - @enable_zip = false - @ssl_server = nil - @ssl_server_thread = nil - end - - def stop_servers - if @normal_server - @normal_server.kill.join - @normal_server = nil - end - if @proxy_server - @proxy_server.kill.join - @proxy_server = nil - end - if @ssl_server - @ssl_server.stop - @ssl_server = nil - end - if @ssl_server_thread - @ssl_server_thread.kill.join - @ssl_server_thread = nil - end - WEBrick::Utils::TimeoutHandler.terminate - end - - def normal_server_port - @normal_server[:server].config[:Port] - end - - def proxy_server_port - @proxy_server[:server].config[:Port] - end - - def start_ssl_server(config = {}) - pend "starting this test server fails randomly on jruby" if Gem.java_platform? - - null_logger = NilLog.new - server = WEBrick::HTTPServer.new({ - Port: 0, - Logger: null_logger, - AccessLog: [], - SSLEnable: true, - SSLCACertificateFile: File.join(__dir__, "ca_cert.pem"), - SSLCertificate: cert("ssl_cert.pem"), - SSLPrivateKey: key("ssl_key.pem"), - SSLVerifyClient: nil, - SSLCertName: nil, - }.merge(config)) - server.mount_proc("/yaml") do |_req, res| - res.body = "--- true\n" - end - server.mount_proc("/insecure_redirect") do |req, res| - res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query["to"]) - end - server.ssl_context.tmp_dh_callback = proc { TEST_KEY_DH2048 } - t = Thread.new do - server.start - rescue StandardError => ex - puts "ERROR during server thread: #{ex.message}" - raise - ensure - server.shutdown - end - while server.status != :Running - sleep 0.1 - unless t.alive? - t.join - raise - end - end - @ssl_server = server - @ssl_server_thread = t - server - end - - def start_server(data) - null_logger = NilLog.new - s = WEBrick::HTTPServer.new( - Port: 0, - DocumentRoot: nil, - Logger: null_logger, - AccessLog: null_logger - ) - s.mount_proc("/kill") {|_req, _res| s.shutdown } - s.mount_proc("/yaml") do |req, res| - if req["X-Captain"] - res.body = req["X-Captain"] - elsif @enable_yaml - res.body = data - res["Content-Type"] = "text/plain" - res["content-length"] = data.size - else - res.status = "404" - res.body = "<h1>NOT FOUND</h1>" - res["Content-Type"] = "text/html" - end - end - s.mount_proc("/yaml.Z") do |_req, res| - if @enable_zip - res.body = Zlib::Deflate.deflate(data) - res["Content-Type"] = "text/plain" - else - res.status = "404" - res.body = "<h1>NOT FOUND</h1>" - res["Content-Type"] = "text/html" - end - end - th = Thread.new do - s.start - rescue StandardError => ex - abort "ERROR during server thread: #{ex.message}" - ensure - s.shutdown - end - th[:server] = s - th - end - - def cert(filename) - OpenSSL::X509::Certificate.new(File.read(File.join(__dir__, filename))) - end - - def key(filename) - OpenSSL::PKey::RSA.new(File.read(File.join(__dir__, filename))) - end -end if Gem::HAVE_OPENSSL +end diff --git a/test/rubygems/test_gem_remote_fetcher_local_server.rb b/test/rubygems/test_gem_remote_fetcher_local_server.rb new file mode 100644 index 0000000000..3d3e8b503b --- /dev/null +++ b/test/rubygems/test_gem_remote_fetcher_local_server.rb @@ -0,0 +1,220 @@ +# frozen_string_literal: true + +require_relative "helper" + +require "socket" + +require "rubygems/remote_fetcher" +require "rubygems/package" + +# = Testing Proxy Settings +# +# These tests check the proper proxy server settings by running two +# web servers. The web server at http://localhost:#{SERVER_PORT} +# represents the normal gem server and returns a gemspec with a rake +# version of 0.4.11. The web server at http://localhost:#{PROXY_PORT} +# represents the proxy server and returns a different dataset where +# rake has version 0.4.2. This allows us to detect which server is +# returning the data. +# +# Note that the proxy server is not a *real* proxy server. But our +# software doesn't really care, as long as we hit the proxy URL when a +# proxy is configured. + +class TestGemRemoteFetcherLocalServer < Gem::TestCase + include Gem::DefaultUserInteraction + + SERVER_DATA = <<-EOY +--- !ruby/object:Gem::Cache +gems: + rake-0.4.11: !ruby/object:Gem::Specification + rubygems_version: "0.7" + specification_version: 1 + name: rake + version: !ruby/object:Gem::Version + version: 0.4.11 + date: 2004-11-12 + summary: Ruby based make-like utility. + require_paths: + - lib + author: Jim Weirich + email: [email protected] + homepage: http://rake.rubyforge.org + description: Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax. + autorequire: + bindir: bin + has_rdoc: true + required_ruby_version: !ruby/object:Gem::Version::Requirement + requirements: + - + - ">" + - !ruby/object:Gem::Version + version: 0.0.0 + version: + platform: ruby + files: + - README + test_files: [] + library_stubs: + rdoc_options: + extra_rdoc_files: + executables: + - rake + extensions: [] + requirements: [] + dependencies: [] + EOY + + PROXY_DATA = SERVER_DATA.gsub(/0.4.11/, "0.4.2") + + def setup + @proxies = %w[https_proxy http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY] + @old_proxies = @proxies.map {|k| ENV[k] } + @proxies.each {|k| ENV[k] = nil } + + super + + @normal_server ||= start_server(SERVER_DATA) + @proxy_server ||= start_server(PROXY_DATA) + + @server_uri = "http://localhost:#{@normal_server[:server].addr[1]}" + "/yaml" + @proxy_uri = "http://localhost:#{@proxy_server[:server].addr[1]}" + + Gem::RemoteFetcher.fetcher = nil + @stub_ui = Gem::MockGemUi.new + @fetcher = Gem::RemoteFetcher.fetcher + end + + def teardown + @fetcher&.close_all + + if @normal_server + @normal_server.kill.join + @normal_server[:server].close + @normal_server = nil + end + if @proxy_server + @proxy_server.kill.join + @proxy_server[:server].close + @proxy_server = nil + end + + super + Gem.configuration[:http_proxy] = nil + @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] } + end + + def test_no_proxy + use_ui @stub_ui do + assert_data_from_server @fetcher.fetch_path(@server_uri) + response = @fetcher.fetch_path(@server_uri, nil, true) + assert_equal SERVER_DATA.size, response["content-length"].to_i + end + end + + def test_implicit_no_proxy + use_ui @stub_ui do + ENV["http_proxy"] = "http://fakeurl:12345" + fetcher = Gem::RemoteFetcher.new :no_proxy + @fetcher = fetcher + assert_data_from_server fetcher.fetch_path(@server_uri) + end + end + + def test_implicit_proxy + use_ui @stub_ui do + ENV["http_proxy"] = @proxy_uri + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + end + + def test_implicit_upper_case_proxy + use_ui @stub_ui do + ENV["HTTP_PROXY"] = @proxy_uri + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + end + + def test_implicit_proxy_no_env + use_ui @stub_ui do + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + assert_data_from_server fetcher.fetch_path(@server_uri) + end + end + + def test_fetch_http_with_additional_headers + ENV["http_proxy"] = @proxy_uri + ENV["no_proxy"] = Gem::URI.parse(@server_uri).host + fetcher = Gem::RemoteFetcher.new nil, nil, { "X-Captain" => "murphy" } + @fetcher = fetcher + assert_equal "murphy", fetcher.fetch_path(@server_uri) + end + + def test_observe_no_proxy_env_single_host + use_ui @stub_ui do + ENV["http_proxy"] = @proxy_uri + ENV["no_proxy"] = Gem::URI.parse(@server_uri).host + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + assert_data_from_server fetcher.fetch_path(@server_uri) + end + end + + def test_observe_no_proxy_env_list + use_ui @stub_ui do + ENV["http_proxy"] = @proxy_uri + ENV["no_proxy"] = "fakeurl.com, #{Gem::URI.parse(@server_uri).host}" + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + assert_data_from_server fetcher.fetch_path(@server_uri) + end + end + + private + + attr_reader :normal_server, :proxy_server + + def assert_data_from_server(data) + assert_match(/0\.4\.11/, data, "Data is not from server") + end + + def assert_data_from_proxy(data) + assert_match(/0\.4\.2/, data, "Data is not from proxy") + end + + def start_server(data) + server = TCPServer.new("localhost", 0) + thread = Thread.new do + loop do + client = server.accept + handle_request(client, data) + end + end + thread[:server] = server + thread + end + + def handle_request(client, data) + request_line = client.gets + headers = {} + while (line = client.gets) && line != "\r\n" + key, value = line.split(": ", 2) + headers[key] = value.strip + end + + if request_line.start_with?("GET /yaml") + response = headers["X-Captain"] ? headers["X-Captain"] : data + client.print "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: #{response.size}\r\n\r\n#{response}" + elsif request_line.start_with?("HEAD /yaml") || request_line.start_with?("GET http://") && request_line.include?("/yaml") + client.print "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: #{data.size}\r\n\r\n#{data}" + else + client.print "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\n<h1>NOT FOUND</h1>" + end + client.close + end +end diff --git a/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb b/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb new file mode 100644 index 0000000000..ad5be1a033 --- /dev/null +++ b/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb @@ -0,0 +1,195 @@ +# frozen_string_literal: true + +require_relative "helper" +require "socket" +require "openssl" + +unless Gem::HAVE_OPENSSL + warn "Skipping Gem::RemoteFetcher tests. openssl not found." +end + +require "rubygems/remote_fetcher" +require "rubygems/package" + +class TestGemRemoteFetcherLocalSSLServer < Gem::TestCase + include Gem::DefaultUserInteraction + + # Generated via: + # x = OpenSSL::PKey::DH.new(2048) # wait a while... + # x.to_s => pem + TEST_KEY_DH2048 = OpenSSL::PKey::DH.new <<-_END_OF_PEM_ +-----BEGIN DH PARAMETERS----- +MIIBCAKCAQEA3Ze2EHSfYkZLUn557torAmjBgPsqzbodaRaGZtgK1gEU+9nNJaFV +G1JKhmGUiEDyIW7idsBpe4sX/Wqjnp48Lr8IeI/SlEzLdoGpf05iRYXC8Cm9o8aM +cfmVgoSEAo9YLBpzoji2jHkO7Q5IPt4zxbTdlmmGFLc/GO9q7LGHhC+rcMcNTGsM +49AnILNn49pq4Y72jSwdmvq4psHZwwFBbPwLdw6bLUDDCN90jfqvYt18muwUxDiN +NP0fuvVAIB158VnQ0liHSwcl6+9vE1mL0Jo/qEXQxl0+UdKDjaGfTsn6HIrwTnmJ +PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== +-----END DH PARAMETERS----- + _END_OF_PEM_ + + def setup + super + @ssl_server_thread = nil + @ssl_server = nil + end + + def teardown + if @ssl_server_thread + @ssl_server_thread.kill.join + @ssl_server_thread = nil + end + if @ssl_server + @ssl_server.close + @ssl_server = nil + end + super + end + + def test_ssl_connection + ssl_server = start_ssl_server + temp_ca_cert = File.join(__dir__, "ca_cert.pem") + with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}/yaml") + end + end + + def test_ssl_client_cert_auth_connection + ssl_server = start_ssl_server( + { verify_mode: OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT } + ) + + temp_ca_cert = File.join(__dir__, "ca_cert.pem") + temp_client_cert = File.join(__dir__, "client.pem") + + with_configured_fetcher( + ":ssl_ca_cert: #{temp_ca_cert}\n" \ + ":ssl_client_cert: #{temp_client_cert}\n" + ) do |fetcher| + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}/yaml") + end + end + + def test_do_not_allow_invalid_client_cert_auth_connection + ssl_server = start_ssl_server( + { verify_mode: OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT } + ) + + temp_ca_cert = File.join(__dir__, "ca_cert.pem") + temp_client_cert = File.join(__dir__, "invalid_client.pem") + + with_configured_fetcher( + ":ssl_ca_cert: #{temp_ca_cert}\n" \ + ":ssl_client_cert: #{temp_client_cert}\n" + ) do |fetcher| + assert_raise Gem::RemoteFetcher::FetchError do + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}/yaml") + end + end + end + + def test_do_not_allow_insecure_ssl_connection_by_default + ssl_server = start_ssl_server + with_configured_fetcher do |fetcher| + assert_raise Gem::RemoteFetcher::FetchError do + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}/yaml") + end + end + end + + def test_ssl_connection_allow_verify_none + ssl_server = start_ssl_server + with_configured_fetcher(":ssl_verify_mode: 0") do |fetcher| + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}/yaml") + end + end + + def test_do_not_follow_insecure_redirect + @server_uri = "http://example.com" + ssl_server = start_ssl_server + temp_ca_cert = File.join(__dir__, "ca_cert.pem") + expected_error_message = + "redirecting to non-https resource: #{@server_uri} (https://localhost:#{ssl_server.addr[1]}/insecure_redirect?to=#{@server_uri})" + + with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| + err = assert_raise Gem::RemoteFetcher::FetchError do + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}/insecure_redirect?to=#{@server_uri}") + end + + assert_equal(err.message, expected_error_message) + end + end + + def test_nil_ca_cert + ssl_server = start_ssl_server + temp_ca_cert = nil + + with_configured_fetcher(":ssl_ca_cert: #{temp_ca_cert}") do |fetcher| + assert_raise Gem::RemoteFetcher::FetchError do + fetcher.fetch_path("https://localhost:#{ssl_server.addr[1]}") + end + end + end + + private + + def with_configured_fetcher(config_str = nil, &block) + if config_str + temp_conf = File.join @tempdir, ".gemrc" + File.open temp_conf, "w" do |fp| + fp.puts config_str + end + Gem.configuration = Gem::ConfigFile.new %W[--config-file #{temp_conf}] + end + fetcher = Gem::RemoteFetcher.new + yield fetcher + sleep 0.5 unless RUBY_PLATFORM.match?(/mswin|mingw/) + ensure + fetcher.close_all + Gem.configuration = nil + end + + def start_ssl_server(config = {}) + server = TCPServer.new(0) + ctx = OpenSSL::SSL::SSLContext.new + ctx.cert = cert("ssl_cert.pem") + ctx.key = key("ssl_key.pem") + ctx.ca_file = File.join(__dir__, "ca_cert.pem") + ctx.tmp_dh_callback = proc { TEST_KEY_DH2048 } + ctx.verify_mode = config[:verify_mode] if config[:verify_mode] + @ssl_server = OpenSSL::SSL::SSLServer.new(server, ctx) + @ssl_server_thread = Thread.new do + loop do + ssl_client = @ssl_server.accept + Thread.new(ssl_client) do |client| + handle_request(client) + ensure + client.close + end + rescue OpenSSL::SSL::SSLError + # Ignore SSL errors because we're testing them implicitly + end + end + @ssl_server + end + + def handle_request(client) + request = client.gets + if request.start_with?("GET /yaml") + client.print "HTTP/1.1 200 OK\r\nContent-Type: text/yaml\r\n\r\n--- true\n" + elsif request.start_with?("GET /insecure_redirect") + location = request.match(/to=([^ ]+)/)[1] + client.print "HTTP/1.1 301 Moved Permanently\r\nLocation: #{location}\r\n\r\n" + else + client.print "HTTP/1.1 404 Not Found\r\n\r\n" + end + end + + def cert(filename) + OpenSSL::X509::Certificate.new(File.read(File.join(__dir__, filename))) + end + + def key(filename) + OpenSSL::PKey::RSA.new(File.read(File.join(__dir__, filename))) + end +end if Gem::HAVE_OPENSSL diff --git a/test/rubygems/test_gem_remote_fetcher_s3.rb b/test/rubygems/test_gem_remote_fetcher_s3.rb new file mode 100644 index 0000000000..fe7eb7ec01 --- /dev/null +++ b/test/rubygems/test_gem_remote_fetcher_s3.rb @@ -0,0 +1,233 @@ +# frozen_string_literal: true + +require_relative "helper" + +require "rubygems/remote_fetcher" +require "rubygems/package" + +class TestGemRemoteFetcherS3 < Gem::TestCase + include Gem::DefaultUserInteraction + + def setup + super + + @a1, @a1_gem = util_gem "a", "1" do |s| + s.executables << "a_bin" + end + + @a1.loaded_from = File.join(@gemhome, "specifications", @a1.full_name) + end + + def assert_fetch_s3(url, signature, token=nil, region="us-east-1", instance_profile_json=nil) + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + $fetched_uri = nil + $instance_profile = instance_profile_json + + def fetcher.request(uri, request_class, last_modified = nil) + $fetched_uri = uri + res = Gem::Net::HTTPOK.new nil, 200, nil + def res.body + "success" + end + res + end + + def fetcher.s3_uri_signer(uri) + require "json" + s3_uri_signer = Gem::S3URISigner.new(uri) + def s3_uri_signer.ec2_metadata_credentials_json + JSON.parse($instance_profile) + end + # Running sign operation to make sure uri.query is not mutated + s3_uri_signer.sign + raise "URI query is not empty: #{uri.query}" unless uri.query.nil? + s3_uri_signer + end + + data = fetcher.fetch_s3 Gem::URI.parse(url) + + assert_equal "https://my-bucket.s3.#{region}.amazonaws.com/gems/specs.4.8.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=testuser%2F20190624%2F#{region}%2Fs3%2Faws4_request&X-Amz-Date=20190624T050641Z&X-Amz-Expires=86400#{token ? "&X-Amz-Security-Token=" + token : ""}&X-Amz-SignedHeaders=host&X-Amz-Signature=#{signature}", $fetched_uri.to_s + assert_equal "success", data + ensure + $fetched_uri = nil + end + + def test_fetch_s3_config_creds + Gem.configuration[:s3_source] = { + "my-bucket" => { id: "testuser", secret: "testpass" }, + } + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b" + end + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_config_creds_with_region + Gem.configuration[:s3_source] = { + "my-bucket" => { id: "testuser", secret: "testpass", region: "us-west-2" }, + } + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2" + end + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_config_creds_with_token + Gem.configuration[:s3_source] = { + "my-bucket" => { id: "testuser", secret: "testpass", security_token: "testtoken" }, + } + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken" + end + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_env_creds + ENV["AWS_ACCESS_KEY_ID"] = "testuser" + ENV["AWS_SECRET_ACCESS_KEY"] = "testpass" + ENV["AWS_SESSION_TOKEN"] = nil + Gem.configuration[:s3_source] = { + "my-bucket" => { provider: "env" }, + } + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b" + end + ensure + ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") } + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_env_creds_with_region + ENV["AWS_ACCESS_KEY_ID"] = "testuser" + ENV["AWS_SECRET_ACCESS_KEY"] = "testpass" + ENV["AWS_SESSION_TOKEN"] = nil + Gem.configuration[:s3_source] = { + "my-bucket" => { provider: "env", region: "us-west-2" }, + } + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2" + end + ensure + ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") } + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_env_creds_with_token + ENV["AWS_ACCESS_KEY_ID"] = "testuser" + ENV["AWS_SECRET_ACCESS_KEY"] = "testpass" + ENV["AWS_SESSION_TOKEN"] = "testtoken" + Gem.configuration[:s3_source] = { + "my-bucket" => { provider: "env" }, + } + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken" + end + ensure + ENV.each_key {|key| ENV.delete(key) if key.start_with?("AWS") } + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_url_creds + url = "s3://testuser:testpass@my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b" + end + end + + def test_fetch_s3_instance_profile_creds + Gem.configuration[:s3_source] = { + "my-bucket" => { provider: "instance_profile" }, + } + + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b", nil, "us-east-1", + '{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}' + end + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_instance_profile_creds_with_region + Gem.configuration[:s3_source] = { + "my-bucket" => { provider: "instance_profile", region: "us-west-2" }, + } + + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2", + '{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}' + end + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_instance_profile_creds_with_token + Gem.configuration[:s3_source] = { + "my-bucket" => { provider: "instance_profile" }, + } + + url = "s3://my-bucket/gems/specs.4.8.gz" + Time.stub :now, Time.at(1_561_353_581) do + assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken", "us-east-1", + '{"AccessKeyId": "testuser", "SecretAccessKey": "testpass", "Token": "testtoken"}' + end + ensure + Gem.configuration[:s3_source] = nil + end + + def refute_fetch_s3(url, expected_message) + fetcher = Gem::RemoteFetcher.new nil + @fetcher = fetcher + + e = assert_raise Gem::RemoteFetcher::FetchError do + fetcher.fetch_s3 Gem::URI.parse(url) + end + + assert_match expected_message, e.message + end + + def test_fetch_s3_no_source_key + url = "s3://my-bucket/gems/specs.4.8.gz" + refute_fetch_s3 url, "no s3_source key exists in .gemrc" + end + + def test_fetch_s3_no_host + Gem.configuration[:s3_source] = { + "my-bucket" => { id: "testuser", secret: "testpass" }, + } + + url = "s3://other-bucket/gems/specs.4.8.gz" + refute_fetch_s3 url, "no key for host other-bucket in s3_source in .gemrc" + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_no_id + Gem.configuration[:s3_source] = { "my-bucket" => { secret: "testpass" } } + + url = "s3://my-bucket/gems/specs.4.8.gz" + refute_fetch_s3 url, "s3_source for my-bucket missing id or secret" + ensure + Gem.configuration[:s3_source] = nil + end + + def test_fetch_s3_no_secret + Gem.configuration[:s3_source] = { "my-bucket" => { id: "testuser" } } + + url = "s3://my-bucket/gems/specs.4.8.gz" + refute_fetch_s3 url, "s3_source for my-bucket missing id or secret" + ensure + Gem.configuration[:s3_source] = nil + end +end diff --git a/test/rubygems/test_gem_request_set_gem_dependency_api.rb b/test/rubygems/test_gem_request_set_gem_dependency_api.rb index af32005a16..4b5eaa38ed 100644 --- a/test/rubygems/test_gem_request_set_gem_dependency_api.rb +++ b/test/rubygems/test_gem_request_set_gem_dependency_api.rb @@ -44,7 +44,7 @@ class TestGemRequestSetGemDependencyAPI < Gem::TestCase def test_gempspec_with_multiple_runtime_deps save_gemspec "foo", "1.0" do |s| - s.add_runtime_dependency "bar", ">= 1.6.0", "< 1.6.4" + s.add_dependency "bar", ">= 1.6.0", "< 1.6.4" end @gda.gemspec assert_equal %w[foo bar].sort, @set.dependencies.map(&:name).sort diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb index b7dadda708..4990d5d2dd 100644 --- a/test/rubygems/test_gem_resolver.rb +++ b/test/rubygems/test_gem_resolver.rb @@ -571,7 +571,7 @@ class TestGemResolver < Gem::TestCase def test_raises_and_reports_an_implicit_request_properly a1 = util_spec "a", "1" do |s| - s.add_runtime_dependency "b", "= 2" + s.add_dependency "b", "= 2" end ad = make_dep "a", "= 1" diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index d0a1e4bc5f..dfc5278a53 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1833,7 +1833,7 @@ dependencies: [] end def test_for_cache - @a2.add_runtime_dependency "b", "1" + @a2.add_dependency "b", "1" @a2.dependencies.first.instance_variable_set :@type, nil @a2.required_rubygems_version = Gem::Requirement.new "> 0" @a2.test_files = %w[test/test_b.rb] @@ -2265,7 +2265,7 @@ dependencies: [] end def test_to_ruby - @a2.add_runtime_dependency "b", "1" + @a2.add_dependency "b", "1" @a2.dependencies.first.instance_variable_set :@type, nil @a2.required_rubygems_version = Gem::Requirement.new "> 0" @a2.require_paths << "other" @@ -2337,7 +2337,7 @@ end end def test_to_ruby_for_cache - @a2.add_runtime_dependency "b", "1" + @a2.add_dependency "b", "1" @a2.dependencies.first.instance_variable_set :@type, nil @a2.required_rubygems_version = Gem::Requirement.new "> 0" @a2.installed_by_version = Gem.rubygems_version @@ -2740,7 +2740,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use: Dir.chdir @tempdir do @a1.version = "1.0.0.beta.1" - @a1.add_runtime_dependency "b", "~> 1.2.0.beta.1" + @a1.add_dependency "b", "~> 1.2.0.beta.1" use_ui @ui do @a1.validate @@ -2754,7 +2754,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use: util_setup_validate Dir.chdir @tempdir do - @a1.add_runtime_dependency @a1.name, "1" + @a1.add_dependency @a1.name, "1" use_ui @ui do @a1.validate @@ -2787,7 +2787,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use: Dir.chdir @tempdir do @a1.extensions = ["Rakefile"] - @a1.add_runtime_dependency "rake" + @a1.add_dependency "rake" File.write File.join(@tempdir, "Rakefile"), "" use_ui @ui do @@ -2958,19 +2958,27 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use: end def test_validate_empty_require_paths - if Gem.win_platform? - pend "test_validate_empty_require_paths skipped on MS Windows (symlink)" - else - util_setup_validate + util_setup_validate - @a1.require_paths = [] - e = assert_raise Gem::InvalidSpecificationException do - @a1.validate - end + @a1.require_paths = [] + e = assert_raise Gem::InvalidSpecificationException do + @a1.validate + end - assert_equal "specification must have at least one require_path", - e.message + assert_equal "specification must have at least one require_path", + e.message + end + + def test_validate_require_paths_with_invalid_types + util_setup_validate + + @a1.require_paths = [1, 2] + e = assert_raise Gem::InvalidSpecificationException do + @a1.validate end + + assert_equal "require_paths must be an Array of String", + e.message end def test_validate_files @@ -3057,7 +3065,7 @@ Please report a bug if this causes problems. def test_duplicate_runtime_dependency expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n" out, err = capture_output do - @a1.add_runtime_dependency "b", "~> 3.0", "~> 3.0" + @a1.add_dependency "b", "~> 3.0", "~> 3.0" end assert_empty out assert_equal(expected, err) @@ -3931,6 +3939,40 @@ end assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name) end + def test_validate_for_resolution_validates_required_attributes + e = assert_raise Gem::InvalidSpecificationException do + @a1.name = nil + @a1.validate_for_resolution + end + + assert_equal "missing value for attribute name", e.message + end + + def test_validate_for_resolution_validates_name + e = assert_raise Gem::InvalidSpecificationException do + @a1.name = 123 + @a1.validate_for_resolution + end + + assert_equal 'invalid value for attribute name: "123" must be a string', e.message + end + + def test_validate_for_resolution_validates_duplicate_dependencies + e = assert_raise Gem::InvalidSpecificationException do + @a1.add_dependency "foo", "1.2.3" + @a1.add_dependency "foo", "3.4.5" + @a1.validate_for_resolution + end + + assert_match "duplicate dependency on foo", e.message + end + + def test_validate_for_resolution_ignores_metadata + @a1.summary = "TODO: Invalid summary" + @a1.metadata["homepage_uri"] = "TODO: Invalid homepage URI" + @a1.validate_for_resolution + end + def util_setup_deps @gem = util_spec "awesome", "1.0" do |awesome| awesome.add_runtime_dependency "bonobo", [] diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index aa5ab0ed67..92ea01a3bc 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -19,8 +19,6 @@ class TestGemUninstaller < Gem::InstallerTestCase @user_spec = @user_installer.spec end end - - Gem::Specification.reset end def test_initialize_expand_path @@ -405,7 +403,7 @@ create_makefile '#{@spec.name}' def test_uninstall_not_ok quick_gem "z" do |s| - s.add_runtime_dependency @spec.name + s.add_dependency @spec.name end uninstaller = Gem::Uninstaller.new @spec.name diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 30a4a477f9..42a31452ae 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -489,6 +489,22 @@ class TestGemRequire < Gem::TestCase assert_equal %w[default-3.0], loaded_spec_names end + def test_default_gem_and_normal_gem_same_version + default_gem_spec = new_default_spec("default", "3.0", + nil, "default/gem.rb") + install_default_gems(default_gem_spec) + normal_gem_spec = util_spec("default", "3.0", nil, + "lib/default/gem.rb") + install_specs(normal_gem_spec) + + # Load default ruby gems fresh as if we've just started a ruby script. + Gem::Specification.reset + + assert_require "default/gem" + assert_equal %w[default-3.0], loaded_spec_names + refute Gem.loaded_specs["default"].default_gem? + end + def test_normal_gem_does_not_shadow_default_gem default_gem_spec = new_default_spec("foo", "2.0", nil, "foo.rb") install_default_gems(default_gem_spec) |