File: po_file_spec.rb

package info (click to toggle)
ruby-fast-gettext 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 720 kB
  • ctags: 301
  • sloc: ruby: 3,092; makefile: 3
file content (68 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "spec_helper"
require 'fast_gettext/po_file'

de_file = File.join('spec','locale','de','test.po')

describe FastGettext::PoFile do
  let(:de) { FastGettext::PoFile.new(de_file) }

  before :all do
    File.exist?(de_file).should == true
  end

  it "parses a file" do
    de['car'].should == 'Auto'
  end

  it "stores untranslated values as nil" do
    de['Untranslated'].should == nil
  end

  it "finds pluralized values" do
    de.plural('Axis','Axis').should == ['Achse','Achsen']
  end

  it "returns empty array when pluralisation could not be found" do
    de.plural('Axis','Axis','Axis').should == []
  end

  it "can access plurals through []" do
    de['Axis'].should == 'Achse' #singular
  end

  it "unescapes '\\'" do
    de["You should escape '\\' as '\\\\'."].should == "Du solltest '\\' als '\\\\' escapen."
  end

  it "doesn't load the file when new instance is created" do
    File.should_not_receive(:read).with(de_file)
    FastGettext::PoFile.new(de_file)
  end

  it "loads the file when a translation is touched for the first time" do
    skip
    File.should_receive(:read).once.with(de_file).and_call_original

    de['car']
    de['car']
  end

  describe "eager loading" do
    let(:de) { FastGettext::PoFile.new(de_file, :eager_load => true) }

    it "loads the file when new instance is created" do
      skip
      File.should_receive(:read).once.with(de_file).and_call_original
      FastGettext::PoFile.new(de_file, :eager_load => true)
    end

    it "doesn't load the file when a translation is touched" do
      de
      File.should_not_receive(:read).with(de_file)

      de['car']
      de['car']
    end

  end
end