summaryrefslogtreecommitdiff
path: root/spec/bundler/install/gems/mirror_probe_spec.rb
blob: 436f116cacf37a36f3f79f4699e070ae970ac219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true

RSpec.describe "fetching dependencies with a not available mirror" do
  before do
    build_repo2

    gemfile <<-G
      source "https://gem.repo2"
      gem 'weakling'
    G
  end

  context "with a specific fallback timeout" do
    before do
      global_config("BUNDLE_MIRROR__HTTPS://GEM__REPO2/__FALLBACK_TIMEOUT/" => "true",
                    "BUNDLE_MIRROR__HTTPS://GEM__REPO2/" => "https://gem.mirror")
    end

    it "install a gem using the original uri when the mirror is not responding" do
      bundle :install, env: { "BUNDLER_SPEC_FAKE_RESOLVE" => "gem.mirror" }, verbose: true

      expect(out).to include("Installing weakling")
      expect(out).to include("Bundle complete")
      expect(the_bundle).to include_gems "weakling 0.0.3"
    end
  end

  context "with a global fallback timeout" do
    before do
      global_config("BUNDLE_MIRROR__ALL__FALLBACK_TIMEOUT/" => "1",
                    "BUNDLE_MIRROR__ALL" => "https://gem.mirror")
    end

    it "install a gem using the original uri when the mirror is not responding" do
      bundle :install, env: { "BUNDLER_SPEC_FAKE_RESOLVE" => "gem.mirror" }

      expect(out).to include("Installing weakling")
      expect(out).to include("Bundle complete")
      expect(the_bundle).to include_gems "weakling 0.0.3"
    end
  end

  context "with a specific mirror without a fallback timeout" do
    before do
      global_config("BUNDLE_MIRROR__HTTPS://GEM__REPO2/" => "https://gem.mirror")
    end

    it "fails to install the gem with a timeout error when the mirror is not responding" do
      bundle :install, artifice: "compact_index_mirror_down", raise_on_error: false

      expect(out).to be_empty
      expect(err).to eq("Could not reach host gem.mirror. Check your network connection and try again.")
    end
  end

  context "with a global mirror without a fallback timeout" do
    before do
      global_config("BUNDLE_MIRROR__ALL" => "https://gem.mirror")
    end

    it "fails to install the gem with a timeout error when the mirror is not responding" do
      bundle :install, artifice: "compact_index_mirror_down", raise_on_error: false

      expect(out).to be_empty
      expect(err).to eq("Could not reach host gem.mirror. Check your network connection and try again.")
    end
  end
end