# -*- encoding: utf-8 -*- require File.dirname(__FILE__) + '/spec_helper' describe Belorussian do describe "with locale" do it "should define :'by' LOCALE" do Belorussian::LOCALE.should == :'by' end it "should provide 'locale' proxy" do Belorussian.locale.should == Belorussian::LOCALE end end describe "during i18n initialization" do after(:each) do I18n.load_path = [] Belorussian.init_i18n end it "should keep existing translations while switching backends" do I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'en.yml') Belorussian.init_i18n I18n.t(:foo, :locale => :'en').should == "bar" end it "should keep existing :by translations while switching backends" do I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'by.yml') Belorussian.init_i18n I18n.t(:'date.formats.default', :locale => :'by').should == "override" end it "should NOT set default locale to Belorussian locale" do locale = I18n.default_locale Belorussian.init_i18n I18n.default_locale.should == locale end end describe "with localize proxy" do before(:each) do @time = mock(:time) @options = { :format => "%d %B %Y" } end %w(l localize).each do |method| it "'#{method}' should call I18n backend localize" do I18n.should_receive(:localize).with(@time, @options.merge({ :locale => Belorussian.locale })) Belorussian.send(method, @time, @options) end end end describe "with translate proxy" do before(:all) do @object = :bar @options = { :scope => :foo } end %w(t translate).each do |method| it "'#{method}' should call I18n backend translate" do I18n.should_receive(:translate).with(@object, @options.merge({ :locale => Belorussian.locale })) Belorussian.send(method, @object, @options) end end end describe "strftime" do before(:each) do @time = mock(:time) end it "should call localize with object and format" do format = "%d %B %Y" Belorussian.should_receive(:localize).with(@time, { :format => format }) Belorussian.strftime(@time, format) end it "should call localize with object and default format when format is not specified" do Belorussian.should_receive(:localize).with(@time, { :format => :default }) Belorussian.strftime(@time) end end describe "with pluralization" do %w(p pluralize).each do |method| it "'#{method}' should pluralize with variants given" do variants = %w(вещь вещи вещей вещи) Belorussian.send(method, 1, *variants).should == "вещь" Belorussian.send(method, 2, *variants).should == 'вещи' Belorussian.send(method, 3, *variants).should == 'вещи' Belorussian.send(method, 5, *variants).should == 'вещей' Belorussian.send(method, 10, *variants).should == 'вещей' Belorussian.send(method, 21, *variants).should == 'вещь' Belorussian.send(method, 29, *variants).should == 'вещей' Belorussian.send(method, 129, *variants).should == 'вещей' Belorussian.send(method, 131, *variants).should == 'вещь' Belorussian.send(method, 3.14, *variants).should == 'вещи' end it "should raise an exception when first parameter is not a number" do lambda { Belorussian.send(method, nil, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError) lambda { Belorussian.send(method, "вещь", "вещь", "вещи", "вещей") }.should raise_error(ArgumentError) end it "should raise an exception when there are not enough variants" do lambda { Belorussian.send(method, 1) }.should raise_error(ArgumentError) lambda { Belorussian.send(method, 1, "вещь") }.should raise_error(ArgumentError) lambda { Belorussian.send(method, 1, "вещь", "вещи") }.should raise_error(ArgumentError) lambda { Belorussian.send(method, 1, "вещь", "вещи", "вещей") }.should_not raise_error(ArgumentError) lambda { Belorussian.send(method, 3.14, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError) lambda { Belorussian.send(method, 3.14, "вещь", "вещи", "вещей", "вещи") }.should_not raise_error(ArgumentError) end end end end