public
Description: Translate text between two languages using www.tranexp.com
Homepage: http://tranexp.rubyforge.org
Clone URL: git://github.com/drnic/tranexp.git
tranexp / test / test_caching.rb
100644 45 lines (38 sloc) 1.142 kb
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
40
41
42
43
44
45
require File.dirname(__FILE__) + '/test_helper.rb'
 
class TestCaching < Test::Unit::TestCase
  attr_reader :translate, :http, :cache
 
  def setup
    @translate = Tranexp::Translate.new
    @http = @translate.http
    @cache = @translate.cache
 
    @cache.stubs(:home_path).
      returns(File.dirname(__FILE__) + '/cache/')
  end
 
  def teardown
    FileUtils.rm_rf File.dirname(__FILE__) + '/cache/'
  end
 
  def test_cache_db_created
    http.expects(:translate).
      with("metoder", "nor", "eng").
      returns("methods").
      once
    do_translation
    assert File.directory?(File.dirname(__FILE__) + '/cache/.tranexp'),
          "HOME/.tranexp not created"
    assert File.exists?(File.dirname(__FILE__) + '/cache/.tranexp/nor-eng.yml'),
          "HOME/.tranexp/nor-eng.yml not created"
  end
 
  def test_requests_are_cached
    http.expects(:translate).
      with("metoder", "nor", "eng").
      returns("methods").
      once
    do_translation
    do_translation
    do_translation
  end
 
  def do_translation
    english = translate.translate("metoder", "nor", "eng")
    assert_equal("methods", english)
  end
end