summaryrefslogtreecommitdiff
path: root/spec/other/clean_spec.rb
blob: d7986a45c28e1cf47ad5f930fe9ff5a2fdccf305 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
require "spec_helper"

describe "bundle clean" do
  it "removes unused gems that are different" do
    gemfile = <<-G
      source "file://#{gem_repo1}"

      gem "thin"
      gem "foo"
    G

    install_gemfile(gemfile, :path => "vendor/bundle")

    install_gemfile <<-G
      source "file://#{gem_repo1}"

      gem "thin"
    G

    bundle :clean

    out.should match /\nRemoving foo \(1\.0\)\Z/

    vendored_gems("gems/thin-1.0").should exist
    vendored_gems("gems/rack-1.0.0").should exist
    vendored_gems("gems/foo-1.0").should_not exist

    vendored_gems("specifications/thin-1.0.gemspec").should exist
    vendored_gems("specifications/rack-1.0.0.gemspec").should exist
    vendored_gems("specifications/foo-1.0.gemspec").should_not exist

    vendored_gems("bin/rackup").should exist
  end

  it "removes old version of gem if unused" do
    gemfile = <<-G
      source "file://#{gem_repo1}"

      gem "rack", "0.9.1"
      gem "foo"
    G

    install_gemfile(gemfile, :path => "vendor/bundle")

    install_gemfile <<-G
      source "file://#{gem_repo1}"

      gem "rack", "1.0.0"
      gem "foo"
    G

    bundle :clean

    out.should match /\nRemoving rack \(0\.9\.1\)\Z/

    vendored_gems("gems/foo-1.0").should exist
    vendored_gems("gems/rack-1.0.0").should exist
    vendored_gems("gems/rack-0.9.1").should_not exist

    vendored_gems("specifications/foo-1.0.gemspec").should exist
    vendored_gems("specifications/rack-1.0.0.gemspec").should exist
    vendored_gems("specifications/rack-0.9.1.gemspec").should_not exist

    vendored_gems("bin/rackup").should exist
  end

  it "removes new version of gem if unused" do
    gemfile = <<-G
      source "file://#{gem_repo1}"

      gem "rack", "1.0.0"
      gem "foo"
    G

    install_gemfile(gemfile, :path => "vendor/bundle")

    install_gemfile <<-G
      source "file://#{gem_repo1}"

      gem "rack", "0.9.1"
      gem "foo"
    G

    bundle :clean

    out.should match /\nRemoving rack \(1\.0\.0\)\Z/

    vendored_gems("gems/foo-1.0").should exist
    vendored_gems("gems/rack-0.9.1").should exist
    vendored_gems("gems/rack-1.0.0").should_not exist

    vendored_gems("specifications/foo-1.0.gemspec").should exist
    vendored_gems("specifications/rack-0.9.1.gemspec").should exist
    vendored_gems("specifications/rack-1.0.0.gemspec").should_not exist

    vendored_gems("bin/rackup").should exist
  end

  it "remove gems in bundle without groups" do
    gemfile = <<-G
      source "file://#{gem_repo1}"

      gem "foo"

      group :test_group do
        gem "rack", "1.0.0"
      end
    G

    install_gemfile(gemfile, :path => "vendor/bundle")
    bundle "install --without test_group"
    bundle :clean

    out.should match /\nRemoving rack \(1\.0\.0\)\Z/

    vendored_gems("gems/foo-1.0").should exist
    vendored_gems("gems/rack-1.0.0").should_not exist

    vendored_gems("specifications/foo-1.0.gemspec").should exist
    vendored_gems("specifications/rack-1.0.0.gemspec").should_not exist

    vendored_gems("bin/rackup").should_not exist
  end

  it "removes unused git gems" do
    build_git "foo"
    @revision = revision_for(lib_path("foo-1.0"))

    gemfile = <<-G
      source "file://#{gem_repo1}"

      gem "rack", "1.0.0"
      git "file://#{lib_path('foo-1.0')}/.git", :ref => "#{@revision}" do
        gem "foo"
      end
    G

    install_gemfile(gemfile, :path => "vendor/bundle")

    install_gemfile <<-G
      source "file://#{gem_repo1}"

      gem "rack", "1.0.0"
    G

    bundle :clean

    pending "spec's that aren't Pixie Dust(TM, Bundler 2011)" do
      out.should match /\nRemoving foo \(1\.0 #{@revision[0..11]}\)\Z/
    end
    vendored_gems("gems/rack-1.0.0").should exist
    vendored_gems("bundler/gems/foo-1.0-#{@revision[0..11]}").should_not exist

    vendored_gems("specifications/rack-1.0.0.gemspec").should exist

    vendored_gems("bin/rackup").should exist
  end

  it "removes old git gems" do
    build_git "foo"
    revision = revision_for(lib_path("foo-1.0"))

    gemfile = <<-G
      source "file://#{gem_repo1}"

      gem "rack", "1.0.0"
      git "file://#{lib_path('foo-1.0')}/.git" do
        gem "foo"
      end
    G

    install_gemfile(gemfile, :path => "vendor/bundle")

    update_git "foo"
    revision2 = revision_for(lib_path("foo-1.0"))

    bundle :update
    bundle :install
    bundle :clean

    pending "spec's that aren't Pixie Dust(TM, Bundler 2011)" do
      out.should match /\nRemoving foo \(1\.0 #{revision[0..11]}\)\Z/
    end

    vendored_gems("gems/rack-1.0.0").should exist
    vendored_gems("bundler/gems/foo-1.0-#{revision[0..11]}").should_not exist
    vendored_gems("bundler/gems/foo-1.0-#{revision2[0..11]}").should exist

    vendored_gems("specifications/rack-1.0.0.gemspec").should exist

    vendored_gems("bin/rackup").should exist
  end

  it "displays an error when used without --path" do
    install_gemfile <<-G
      source "file://#{gem_repo1}"

      gem "rack", "1.0.0"
    G

    bundle :clean

    out.should == "Can only use bundle clean when --path is set"
  end
end