Browse files

bundle clean should clean up the cache gems, close #1293

  • Loading branch information...
1 parent 32978b0 commit 06c7f888db20f3988a974923e42b702c68086fc8 @cldwalker cldwalker committed with hone Jul 10, 2011
Showing with 24 additions and 26 deletions.
  1. +2 −0 lib/bundler/runtime.rb
  2. +22 −26 spec/other/clean_spec.rb
View
2 lib/bundler/runtime.rb
@@ -142,6 +142,8 @@ def clean
FileUtils.rm_rf(gem_dir)
specification_file = "#{Gem.dir}/specifications/#{full_name}.gemspec"
FileUtils.rm(specification_file) if File.exists?(specification_file)
+ gem_file = "#{Gem.dir}/cache/#{full_name}.gem"
+ FileUtils.rm(gem_file) if File.exists?(gem_file)
parts = full_name.split('-')
name = parts[0..-2].join('-')
View
48 spec/other/clean_spec.rb
@@ -1,6 +1,20 @@
require "spec_helper"
describe "bundle clean" do
+ def should_have_gems(*gems)
+ gems.each do |g|
+ vendored_gems("gems/#{g}").should exist
+ vendored_gems("specifications/#{g}.gemspec").should exist
+ vendored_gems("cache/#{g}.gem").should exist
+ end
+ end
+
+ def should_not_have_gem(rubygem)
+ vendored_gems("gems/#{rubygem}").should_not exist
+ vendored_gems("specifications/#{rubygem}.gemspec").should_not exist
+ vendored_gems("cache/#{rubygem}.gem").should_not exist
+ end
+
it "removes unused gems that are different" do
gemfile = <<-G
source "file://#{gem_repo1}"
@@ -21,13 +35,8 @@
out.should == "Removing foo (1.0)"
- 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
+ should_have_gems 'thin-1.0', 'rack-1.0.0'
+ should_not_have_gem 'foo-1.0'
vendored_gems("bin/rackup").should exist
end
@@ -53,13 +62,8 @@
out.should == "Removing rack (0.9.1)"
- 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
+ should_have_gems 'foo-1.0', 'rack-1.0.0'
+ should_not_have_gem 'rack-0.9.1'
vendored_gems("bin/rackup").should exist
end
@@ -85,13 +89,8 @@
out.should == "Removing rack (1.0.0)"
- 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
+ should_have_gems 'foo-1.0', 'rack-0.9.1'
+ should_not_have_gem 'rack-1.0.0'
vendored_gems("bin/rackup").should exist
end
@@ -113,11 +112,8 @@
out.should == "Removing rack (1.0.0)"
- 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
+ should_have_gems 'foo-1.0'
+ should_not_have_gem 'rack-1.0.0'
vendored_gems("bin/rackup").should_not exist
end

0 comments on commit 06c7f88

Please sign in to comment.