summaryrefslogtreecommitdiff
path: root/spec/bundler/cache/path_spec.rb
blob: 6865e54b321fa97e1f24f051c124e8987c49d1a0 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# frozen_string_literal: true

RSpec.describe "bundle cache with path" do
  it "is no-op when the path is within the bundle" do
    build_lib "foo", path: bundled_app("lib/foo")

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "foo", :path => '#{bundled_app("lib/foo")}'
    G

    bundle :cache
    expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
    expect(the_bundle).to include_gems "foo 1.0"
  end

  it "copies when the path is outside the bundle " do
    build_lib "foo"

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "foo", :path => '#{lib_path("foo-1.0")}'
    G

    bundle :cache
    expect(bundled_app("vendor/cache/foo-1.0")).to exist
    expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file

    expect(the_bundle).to include_gems "foo 1.0"
  end

  it "copies when the path is outside the bundle and the paths intersect" do
    libname = File.basename(bundled_app) + "_gem"
    libpath = File.join(File.dirname(bundled_app), libname)

    build_lib libname, path: libpath

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "#{libname}", :path => '#{libpath}'
    G

    bundle :cache
    expect(bundled_app("vendor/cache/#{libname}")).to exist
    expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file

    expect(the_bundle).to include_gems "#{libname} 1.0"
  end

  it "updates the path on each cache" do
    build_lib "foo"

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "foo", :path => '#{lib_path("foo-1.0")}'
    G

    bundle :cache

    build_lib "foo" do |s|
      s.write "lib/foo.rb", "puts :CACHE"
    end

    bundle :cache

    expect(bundled_app("vendor/cache/foo-1.0")).to exist

    run "require 'foo'"
    expect(out).to eq("CACHE")
  end

  it "removes stale entries cache" do
    build_lib "foo"

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "foo", :path => '#{lib_path("foo-1.0")}'
    G

    bundle :cache

    expect(bundled_app("vendor/cache/foo-1.0")).to exist

    build_lib "bar"

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "bar", :path => '#{lib_path("bar-1.0")}'
    G

    bundle :cache
    expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
  end

  it "does not cache path gems if cache_all is set to false" do
    build_lib "foo"

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "foo", :path => '#{lib_path("foo-1.0")}'
    G
    bundle "config cache_all false"

    bundle :cache
    expect(err).to be_empty
    expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
  end

  it "caches path gems by default" do
    build_lib "foo"

    install_gemfile <<-G
      source "https://gem.repo1"
      gem "foo", :path => '#{lib_path("foo-1.0")}'
    G

    bundle :cache
    expect(err).to be_empty
    expect(bundled_app("vendor/cache/foo-1.0")).to exist
  end
end