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

describe Comma do
  
  it 'should extend object to add a comma method' do
    Object.should respond_to(:comma)
  end
  
  it 'should extend object to have a to_comma method' do
    Object.should respond_to(:to_comma)
  end
  
  it 'should extend object to have a to_comma_headers method' do
    Object.should respond_to(:to_comma_headers)
  end
  
end

describe Comma, 'generating CSV' do
  
  before do
    @isbn = Isbn.new('123123123', '321321321')
    @book = Book.new('Smalltalk-80', 'Language and Implementation', @isbn)
    
    @books = []
    @books << @book
  end
  
  it 'should extend Array to add a #to_comma method which will return CSV content for objects within the array' do
    @books.to_comma.should == "Title,Description,Issuer,ISBN-10,ISBN-13\nSmalltalk-80,Language and Implementation,ISBN,123123123,321321321\n"
  end
  
end

describe Comma, 'defining CSV descriptions' do
  
  describe 'with an unnamed description' do
    
    before do
      class Foo
        comma do; end
      end        
    end
  
    it 'should name the current description :default if no name has been provided' do
      Foo.comma_formats.should_not be_empty
      Foo.comma_formats[:default].should_not be_nil
    end
  end
  
  describe 'with a named description' do
   <commit_msg>Update comma spec to test case when #to_comma is called on an empty array<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe Comma do
  
  it 'should extend object to add a comma method' do
    Object.should respond_to(:comma)
  end
  
  it 'should extend object to have a to_comma method' do
    Object.should respond_to(:to_comma)
  end
  
  it 'should extend object to have a to_comma_headers method' do
    Object.should respond_to(:to_comma_headers)
  end
  
end

describe Comma, 'generating CSV' do
  
  before do
    @isbn = Isbn.new('123123123', '321321321')
    @book = Book.new('Smalltalk-80', 'Language and Implementation', @isbn)
    
    @books = []
    @books << @book
  end
  
  it 'should extend Array to add a #to_comma method which will return CSV content for objects within the array' do
    @books.to_comma.should == "Title,Description,Issuer,ISBN-10,ISBN-13\nSmalltalk-80,Language and Implementation,ISBN,123123123,321321321\n"
  end

  it 'should return an empty string when generating CSV from an empty array' do
    Array.new.to_comma.should == ''
  end
  
end

describe Comma, 'defining CSV descriptions' do
  
  describe 'with an unnamed description' do
    
    before do
      class Foo
        comma do; end
      end        
    end
  
    it 'should name the current description :default if no name has been provided' do
      Foo.comma_formats.should_not be_empty
      Foo.comma_formats[:default].should_not be_nil
    end
  end
  
  describe 'with a named description' do
   
{'fraction_non_alphanumeric': 0.07705657757723013, 'fraction_numerical': 0.030544949670253386, 'mean_word_length': 3.117142857142857, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3794750', 'n_tokens_mistral': 1002, 'n_tokens_neox': 914, 'n_words': 307}