<commit_before>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_gems(*gems)
    gems.each do |g|
      vendored_gems("gems/#{g}").should_not exist
      vendored_gems("specifications/#{g}.gemspec").should_not exist
      vendored_gems("cache/#{g}.gem").should_not exist
    end
  end

  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 == "Removing foo (1.0)"

    should_have_gems 'thin-1.0', 'rack-1.0.0'
    should_not_have_gems 'foo-1.0'

    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 == "Removing rack (0.9.1)"

    should_have_gems 'foo-1.0', 'rack-1.0.0'
    should_not_have_gems 'rack-0.9.1'

    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 == "Removing rack (1.0.0)"

    should_have_gems 'foo-1.0', 'rack-0.9.1'
    should_not_have_gems 'rack-1.0.0'

    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 == "Removing rack (1.0.0)"

    should_have_gems 'foo-1.0'
    should_not_have_gems 'rack-1.0.0'

    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 "#{lib_path('foo-1.0')}", :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

    out.should == "Removing foo (1.0 #{@revision[0..11]})"

    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<commit_msg>remove @ in @revision<commit_after>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_gems(*gems)
    gems.each do |g|
      vendored_gems("gems/#{g}").should_not exist
      vendored_gems("specifications/#{g}.gemspec").should_not exist
      vendored_gems("cache/#{g}.gem").should_not exist
    end
  end

  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 == "Removing foo (1.0)"

    should_have_gems 'thin-1.0', 'rack-1.0.0'
    should_not_have_gems 'foo-1.0'

    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 == "Removing rack (0.9.1)"

    should_have_gems 'foo-1.0', 'rack-1.0.0'
    should_not_have_gems 'rack-0.9.1'

    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 == "Removing rack (1.0.0)"

    should_have_gems 'foo-1.0', 'rack-0.9.1'
    should_not_have_gems 'rack-1.0.0'

    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 == "Removing rack (1.0.0)"

    should_have_gems 'foo-1.0'
    should_not_have_gems 'rack-1.0.0'

    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 "#{lib_path('foo-1.0')}", :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

    out.should == "Removing foo (1.0 #{revision[0..11]})"

    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
{'fraction_non_alphanumeric': 0.15693430656934307, 'fraction_numerical': 0.027068126520681267, 'mean_word_length': 2.536021505376344, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7215176', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2443, 'n_words': 519}