Changeset 292

Show
Ignore:
Timestamp:
04/29/08 02:42:46 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

More specs!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/log_indexing_time_with_ferret/lib/picolena/templates/app/models/document.rb

    r279 r292  
    7070                            :field => :content, :excerpt_length => :all, 
    7171                            :pre_tag => "<<", :post_tag => ">>" 
    72     ) 
     72    ).first 
    7373  end 
    7474 
  • branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/document_spec.rb

    r270 r292  
    66  :complete_path=>File.join(RAILS_ROOT, '/spec/test_dirs/indexed/basic/basic.pdf'), 
    77  :extname=>'.pdf', 
    8   :filename=>'basic.pdf' 
     8  :ext_as_sym => :pdf, 
     9  :filename=>'basic.pdf', 
     10  :size => 9380 
    911} 
    1012 
    1113describe Document do 
    1214  before(:each) do 
    13     @valid_random_doc=Document.find(:random) rescue Document.new("spec/test_dirs/indexed/basic/basic.pdf") 
     15    @valid_document=Document.new("spec/test_dirs/indexed/basic/basic.pdf") 
    1416  end 
    1517 
    1618  it "should be an existing file" do 
    1719    lambda {Document.new("/patapouf.txt")}.should raise_error(Errno::ENOENT) 
    18     lambda {@valid_random_doc}.should_not raise_error 
     20    lambda {@valid_document}.should_not raise_error 
    1921    lambda {Document.new("spec/test_dirs/not_indexed/Rakefile")}.should_not raise_error(Errno::ENOENT) 
    2022  end 
    2123 
    2224  it "should belong to an indexed directory" do 
    23     lambda {@valid_random_doc}.should_not raise_error 
     25    lambda {@valid_document}.should_not raise_error 
    2426    lambda {Document.new("spec/test_dirs/not_indexed/Rakefile")}.should raise_error(ArgumentError, "required document is not in indexed directory") 
    2527  end 
     
    2729  basic_pdf_attribute.each{|attribute,expected_value| 
    2830    it "should know its #{attribute}" do 
    29       @valid_random_doc.should respond_to(attribute) 
     31      @valid_document.should respond_to(attribute) 
    3032      @basic_pdf=Document.new('spec/test_dirs/indexed/basic/basic.pdf') 
    3133      @basic_pdf.send(attribute).should == expected_value 
     
    3739    another_doc.content.should == "just a content test\nin a txt file" 
    3840  end 
     41   
     42  it "should know its cached content" do 
     43    another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") 
     44    another_doc.cached.should == "just a content test\nin a txt file" 
     45  end 
     46   
     47  it "should know its highlighted cached content for a given query" do 
     48    another_doc=Document.new("spec/test_dirs/indexed/basic/plain.txt") 
     49    another_doc.highlighted_cache('a content test').should == "just a <<content>> <<test>>\nin a txt file" 
     50  end 
    3951 
    4052  it "should know its alias_path" do 
    41     @valid_random_doc.should respond_to(:alias_path) 
    42     @valid_random_doc.alias_path.starts_with?("http://picolena.devjavu.com/browser/trunk/lib/picolena/templates/spec/test_dirs/indexed").should be_true 
     53    @valid_document.should respond_to(:alias_path) 
     54    @valid_document.alias_path.starts_with?("http://picolena.devjavu.com/browser/trunk/lib/picolena/templates/spec/test_dirs/indexed").should be_true 
    4355  end 
     56   
     57  it "should know its probably_unique_id" do 
     58    @valid_document.should respond_to(:probably_unique_id) 
     59    @valid_document.probably_unique_id.should =~/^[a-z]+$/ 
     60    @valid_document.probably_unique_id.size.should == Picolena::HashLength 
     61  end 
     62   
     63  it "should know its modification date" do 
     64    @valid_document.pretty_date.class.should == String 
     65    @valid_document.pretty_date.should =~/^\d{4}\-\d{2}\-\d{2}$/ 
     66  end 
     67   
     68  it "should know its modification time and returns it in a pretty way" do 
     69    @valid_document.should respond_to(:mtime) 
     70    @valid_document.mtime.class.should == Bignum 
     71    @valid_document.should respond_to(:pretty_mtime) 
     72    @valid_document.pretty_mtime.class.should == String 
     73    @valid_document.pretty_mtime.should =~/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/ 
     74  end 
     75   
     76  it "should know if its content can be extracted" do 
     77    @valid_document.should respond_to(:supported?) 
     78    @valid_document.should be_supported 
     79    Document.new("spec/test_dirs/indexed/others/ghjopdfg.xyz").should_not be_supported 
     80  end 
     81   
     82  it "should know its language when enough content is available" do 
     83    Document.new("spec/test_dirs/indexed/lang/goethe").language.should == "de" 
     84    Document.new("spec/test_dirs/indexed/lang/shakespeare").language.should == "en" 
     85    Document.new("spec/test_dirs/indexed/lang/lorca").language.should == "es" 
     86    Document.new("spec/test_dirs/indexed/lang/hugo").language.should == "fr" 
     87  end if Picolena::UseLanguageRecognition 
     88 
     89  it "should not try to guess language when file is too small" do 
     90    Document.new("spec/test_dirs/indexed/basic/hello.rb").language.should be_nil 
     91    Document.new("spec/test_dirs/indexed/README").language.should be_nil 
     92  end if Picolena::UseLanguageRecognition 
    4493 
    4594  it "should let finder specify its score" do 
    46     @valid_random_doc.should respond_to(:score) 
    47     @valid_random_doc.score.should be_nil 
    48     @valid_random_doc.score=25 
    49     @valid_random_doc.score.should == 25 
     95    @valid_document.should respond_to(:score) 
     96    @valid_document.score.should be_nil 
     97    @valid_document.score=25 
     98    @valid_document.score.should == 25 
    5099  end 
    51100 
    52101  it "should let finder specify its matching content" do 
    53     @valid_random_doc.should respond_to(:matching_content) 
    54     @valid_random_doc.matching_content.should be_nil 
    55     @valid_random_doc.matching_content=["thermal cooling", "heat driven cooling"] 
    56     @valid_random_doc.matching_content.should include("thermal cooling") 
     102    @valid_document.should respond_to(:matching_content) 
     103    @valid_document.matching_content.should be_nil 
     104    @valid_document.matching_content=["thermal cooling", "heat driven cooling"] 
     105    @valid_document.matching_content.should include("thermal cooling") 
    57106  end 
    58107end 
  • branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/host_indexing_system_spec.rb

    r263 r292  
    1414  it "should know which IP addresses are allowed (config/custom/white_list_ip.yml)" do 
    1515    File.should be_readable('config/custom/white_list_ip.yml') 
     16    ip_conf=YAML.load_file('config/custom/white_list_ip.yml') 
     17    ip_conf.class.should == Hash 
     18    ip_conf['Allow'].should_not be_nil 
    1619  end 
    1720 
    1821  it "should know which directories are to be indexed (config/custom/indexed_directories.yml)" do 
    1922    File.should be_readable('config/custom/indexed_directories.yml') 
     23    dirs_conf=YAML.load_file('config/custom/indexed_directories.yml') 
     24    dirs_conf.class.should == Hash 
     25    %w(development test production).all?{|env| 
     26      dirs_conf[env].should_not be_nil 
     27    } 
    2028  end 
    2129 
  • branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/plain_text_extractor_spec.rb

    r263 r292  
    2828    } 
    2929  } 
    30  
    31   it "should guess language when enough content is available" do 
    32     Document.new("spec/test_dirs/indexed/lang/goethe").language.should == "de" 
    33     Document.new("spec/test_dirs/indexed/lang/shakespeare").language.should == "en" 
    34     Document.new("spec/test_dirs/indexed/lang/lorca").language.should == "es" 
    35     Document.new("spec/test_dirs/indexed/lang/hugo").language.should == "fr" 
    36   end if Picolena::UseLanguageRecognition 
    37  
    38   it "should not try to guess language when file is too small" do 
    39     Document.new("spec/test_dirs/indexed/basic/hello.rb").language.should be_nil 
    40     Document.new("spec/test_dirs/indexed/README").language.should be_nil 
    41   end if Picolena::UseLanguageRecognition 
    4230end 
  • branches/log_indexing_time_with_ferret/lib/picolena/templates/spec/models/query_spec.rb

    r263 r292  
    22 
    33describe Query do 
    4   it "should return a BooleanQuery" do 
     4  it "should return a BooleanQuery, a TermQuery or a RangeQuery" do 
    55    Query.extract_from("whatever").class.should == Ferret::Search::BooleanQuery 
     6    Query.extract_from("lang:de").class.should  == Ferret::Search::TermQuery 
     7    Query.extract_from("date:<1990").class.should  == Ferret::Search::RangeQuery 
     8  end 
     9   
     10  it "should not remove stop-words from TermQuery" do 
     11    # it means "Italian language", but also is a stop-word. 
     12    Query.extract_from("lang:it").class.should  == Ferret::Search::TermQuery 
     13    Query.extract_from("lang:it").to_s.should   == "language:it" 
    614  end 
    715