/
localized_number_spec.rb
55 lines (47 loc) · 1.67 KB
/
localized_number_spec.rb
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
# encoding: UTF-8
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
include TwitterCldr
describe LocalizedNumber do
before(:each) do
@number = 10.localize
end
describe "#to_decimal" do
it "should internally create a decimal formatter and return itself" do
mock.proxy(TwitterCldr::Formatters).const_get(:DecimalFormatter)
@number.to_decimal.should == @number
end
end
describe "#to_currency" do
it "should internally create a currency formatter and return itself" do
mock.proxy(TwitterCldr::Formatters).const_get(:CurrencyFormatter)
@number.to_currency.should == @number
end
end
describe "#to_percent" do
it "should internally create a percentage formatter and return itself" do
mock.proxy(TwitterCldr::Formatters).const_get(:PercentFormatter)
@number.to_percent.should == @number
end
end
describe "#to_s" do
it "should default precision to zero for fixnums" do
mock(@number.formatter).format(@number.base_obj, :precision => 0)
@number.to_s
end
it "should not overwrite precision when explicitly passed" do
mock(@number.formatter).format(@number.base_obj, :precision => 2)
@number.to_s(:precision => 2)
end
end
describe "#plural_rule" do
it "should return the appropriate plural rule for the number" do
1.localize(:ru).plural_rule.should == :one
2.localize(:ru).plural_rule.should == :few
5.localize(:ru).plural_rule.should == :many
FastGettext.locale = :es
1.localize.plural_rule.should == :one
2.localize.plural_rule.should == :other
5.localize.plural_rule.should == :other
end
end
end