<commit_before>require File.join(File.dirname(__FILE__), 'spec_helper')

describe Gem::Cutter do
  before do
    @gem = "test-0.0.0.gem"
    @gem_file = gem_file(@gem)
    @cache_path = Gem::Cutter.server_path("cache", @gem)
    @spec_path = Gem::Cutter.server_path("specifications", @gem + "spec")

    FileUtils.rm_rf Dir["server/cache/*", "server/*specs*", "server/quick", "server/specifications/*"]
    Gem::Cutter.indexer.generate_index
  end

  describe "with a new gem" do
    before do
      @cutter = Gem::Cutter.new(@gem_file)
    end

    it "should store data" do
      @cutter.data.should == @gem_file
    end

    it "should not save an empty gem" do
      @temp_path = "temp path"
      stub(Tempfile).new("gem").stub!.path { @temp_path }
      mock(File).size(@temp_path) { 0 }

      @cutter.save_gem

      File.exists?(@cache_path).should be_false
      File.exists?(@spec_path).should be_false
      @cutter.error.should == "Empty gem cannot be processed."
    end

    it "should save gem and update index" do
      @cutter.save_gem
      File.exists?(@cache_path).should be_true
      File.exists?(@spec_path).should be_true
      FileUtils.compare_file(@gem_file.path, @cache_path).should be_true
    end
  end<commit_msg>Making sure File.open is stubbed out as well<commit_after>require File.join(File.dirname(__FILE__), 'spec_helper')

describe Gem::Cutter do
  before do
    @gem = "test-0.0.0.gem"
    @gem_file = gem_file(@gem)
    @cache_path = Gem::Cutter.server_path("cache", @gem)
    @spec_path = Gem::Cutter.server_path("specifications", @gem + "spec")

    FileUtils.rm_rf Dir["server/cache/*", "server/*specs*", "server/quick", "server/specifications/*"]
    Gem::Cutter.indexer.generate_index
  end

  describe "with a new gem" do
    before do
      @cutter = Gem::Cutter.new(@gem_file)
    end

    it "should store data" do
      @cutter.data.should == @gem_file
    end

    it "should not save an empty gem" do
      @temp_path = "temp path"
      stub(Tempfile).new("gem").stub!.path { @temp_path }
      stub(File).open(@temp_path, 'wb')
      mock(File).size(@temp_path) { 0 }

      @cutter.save_gem

      File.exists?(@cache_path).should be_false
      File.exists?(@spec_path).should be_false
      @cutter.error.should == "Empty gem cannot be processed."
    end

    it "should save gem and update index" do
      @cutter.save_gem
      File.exists?(@cache_path).should be_true
      File.exists?(@spec_path).should be_true
      FileUtils.compare_file(@gem_file.path, @cache_path).should be_true
    end
  end
{'fraction_non_alphanumeric': 0.13744631003514252, 'fraction_numerical': 0.0031237797735259665, 'mean_word_length': 3.255813953488372, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4850623', 'n_tokens_mistral': 887, 'n_tokens_neox': 872, 'n_words': 190}