Sha256: 052773555f4b6b0b0adea8972d4f5ff753587583ea586582220d67704bb330d5
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 require 'spec_helper' include TwitterCldr::Formatters::Plurals describe Rules do describe "#get_resource" do it "calls eval on the hash that gets returned, lambdas and all" do result = Rules.send(:get_resource, :ru) result.should include(:keys, :rule) result[:keys].size.should == 3 result[:rule].should be_a(Proc) end end describe "#rule_for" do it "returns :one for English 1, :other for everything else" do Rules.rule_for(1, :en).should == :one [5, 9, 10, 20, 60, 99, 100, 103, 141].each do |num| Rules.rule_for(num, :en).should == :other end end it "returns the correct values for Russian rules" do rules = { :one => [1, 101], :many => ((5..11).to_a + [111]), :other => [2, 3, 4, 102] } rules.each do |rule, examples| examples.each { |n| Rules.rule_for(n, :ru).should == rule } end end it "returns :other if there's an error" do stub(Rules).get_resource { lambda { raise "Jelly beans" } } Rules.rule_for(1, :en).should == :other Rules.rule_for(1, :ru).should == :other end end describe "#all_for" do it "returns a list of all applicable rules for the given locale" do Rules.all_for(:en).should =~ [:one, :other] Rules.all_for(:ru).should =~ [:one, :many, :other] end it "returns nil on error" do stub(Rules).get_resource { lambda { raise "Jelly beans" } } Rules.all_for(:en).should be_nil Rules.all_for(:ru).should be_nil end end describe "#all" do it "gets rules for the default locale (usually supplied by FastGettext)" do mock(TwitterCldr).locale { :ru } Rules.all.should =~ [:one, :many, :other] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
twitter_cldr-3.0.1 | spec/formatters/plurals/rules_spec.rb |
twitter_cldr-3.0.0 | spec/formatters/plurals/rules_spec.rb |