|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "bundler/compact_index_client" |
| 4 | +require "bundler/compact_index_client/updater" |
| 5 | + |
| 6 | +TMP_DIR_PATH = File.expand_path("../tmp", __dir__) |
| 7 | + |
| 8 | +RSpec.shared_context "in a temporary bundler directory" do |
| 9 | + let(:project_name) { "gemfile" } |
| 10 | + |
| 11 | + let(:tmp_path) do |
| 12 | + Dir.mkdir(TMP_DIR_PATH) unless Dir.exist?(TMP_DIR_PATH) |
| 13 | + dir = Dir.mktmpdir("native_helper_spec_", TMP_DIR_PATH) |
| 14 | + Pathname.new(dir).expand_path |
| 15 | + end |
| 16 | + |
| 17 | + before do |
| 18 | + project_dependency_files(project_name).each do |file| |
| 19 | + File.write(File.join(tmp_path, file[:name]), file[:content]) |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + def in_tmp_folder(&block) |
| 24 | + Dir.chdir(tmp_path, &block) |
| 25 | + end |
| 26 | +end |
| 27 | + |
| 28 | +RSpec.shared_context "without caching rubygems" do |
| 29 | + before do |
| 30 | + # Stub Bundler to stop it using a cached versions of Rubygems |
| 31 | + allow_any_instance_of(Bundler::CompactIndexClient::Updater). |
| 32 | + to receive(:etag_for).and_return("") |
| 33 | + end |
| 34 | +end |
| 35 | + |
| 36 | +RSpec.shared_context "stub rubygems compact index" do |
| 37 | + include_context "without caching rubygems" |
| 38 | + |
| 39 | + before do |
| 40 | + # Stub the Rubygems index |
| 41 | + stub_request(:get, "https://index.rubygems.org/versions"). |
| 42 | + to_return( |
| 43 | + status: 200, |
| 44 | + body: fixture("ruby", "rubygems_responses", "index") |
| 45 | + ) |
| 46 | + |
| 47 | + # Stub the Rubygems response for each dependency we have a fixture for |
| 48 | + fixtures = |
| 49 | + Dir[File.join("../../spec", "fixtures", "ruby", "rubygems_responses", "info-*")] |
| 50 | + fixtures.each do |path| |
| 51 | + dep_name = path.split("/").last.gsub("info-", "") |
| 52 | + stub_request(:get, "https://index.rubygems.org/info/#{dep_name}"). |
| 53 | + to_return( |
| 54 | + status: 200, |
| 55 | + body: fixture("ruby", "rubygems_responses", "info-#{dep_name}") |
| 56 | + ) |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments