Sha256: b03550cce5a0c4190ec7619e61f688cb13d639eb1a0d82001678da3364797a7a

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-1.0.1 spec/ext/numbers/localized_number_spec.rb