<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "IndexWriter#write" do
  before do
    @path = prepare_index_dir
  end

  it "sets count to 0" do
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write
    w.count.should == 0
  end

  it "returns true when the write was a success" do
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write.should == true
  end

  it "removes the lock after a write" do
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write
    File.exists?(@path + '/index.lock').should == false
  end

  it "writes a marshalled representation of the document list" do
    w = Polecat::IndexWriter.new @path
    doc = Spec::FooDocument.new
    w.add doc
    w.write
    File.read(@path + '/ind0.ind').should == Marshal.dump([doc])
  end

  it "returns false when the directory has an 'index.lock' file" do
    w = Polecat::IndexWriter.new @path
    FileUtils.touch @path + '/index.lock'
    w.add Spec::FooDocument.new
    w.write.should == false
  end
end<commit_msg>added a new spec for IndexWriter#write<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "IndexWriter#write" do
  before do
    @path = prepare_index_dir
  end

  it "sets count to 0" do
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write
    w.count.should == 0
  end

  it "returns true when the write was a success" do
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write.should == true
  end

  it "removes the lock after a write" do
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write
    File.exists?(@path + '/index.lock').should == false
  end

  it "takes a higher number for the index file, if there is already one" do
    FileUtils.touch @path + '/ind0.ind'
    w = Polecat::IndexWriter.new @path
    w.add Spec::FooDocument.new
    w.write
    File.exists?(@path + '/ind1.ind').should == true
  end

  it "writes a marshalled representation of the document list" do
    w = Polecat::IndexWriter.new @path
    doc = Spec::FooDocument.new
    w.add doc
    w.write
    File.read(@path + '/ind0.ind').should == Marshal.dump([doc])
  end

  it "returns false when the directory has an 'index.lock' file" do
    w = Polecat::IndexWriter.new @path
    FileUtils.touch @path + '/index.lock'
    w.add Spec::FooDocument.new
    w.write.should == false
  end
end
{'fraction_non_alphanumeric': 0.11853619729514718, 'fraction_numerical': 0.0031821797931583136, 'mean_word_length': 2.9794303797468356, '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': '7565909', 'n_tokens_mistral': 864, 'n_tokens_neox': 822, 'n_words': 246}