File: test.rb

package info (click to toggle)
ruby-ferret 0.11.8.4%2Bdebian-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,368 kB
  • sloc: ansic: 69,786; ruby: 8,131; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 979 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# a simple test script to make sure ferret is properly installed and working

require 'ferret'
require 'test/unit'
require 'fileutils'

class FerretTest < Test::Unit::TestCase

  def test_should_find_docs
    index = Ferret::Index::Index.new
    index << "some text about something"
    index << "test about other thing"
    index << "another text about the same something we said first"
    assert_equal 2, index.search('something').hits.size
  end

  def test_should_save_persistent_index
    nice_languages = %w[ Ruby Python Lua ]
    
    index = Ferret::Index::Index.new(:path => 'index.tmp')
    nice_languages.each do |lang|
      index << lang
    end
    index.commit

    index2 = Ferret::Index::Index.new(:path => 'index.tmp')
    assert_equal 0, index2.search('ruby').hits.first.doc
    assert_equal 1, index2.search('python').hits.first.doc
    assert_equal 2, index2.search('lua').hits.first.doc
  end

  def teardown
    FileUtils.rm_rf('index.tmp')
  end

end