Sha256: 8b338d391bb69887ed3534e443b4b09aebcf5d7f14c4bf5045a2f205eb2d4fc3

Contents?: true

Size: 1.67 KB

Versions: 29

Compression:

Stored size: 1.67 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe YARD::I18n::Locale do
  def locale(name)
    YARD::I18n::Locale.new(name)
  end

  before do
    @locale = locale("fr")
  end

  describe "#name" do
    it "should return name" do
      locale("fr").name.should == "fr"
    end
  end

  describe "#load" do
    it "should return false for nonexistent PO" do
      File.should_receive(:exist?).with('foo/fr.po').and_return(false)
      @locale.load('foo').should == false
    end

    have_gettext_gem = true
    begin
      require "gettext/tools/poparser"
    rescue LoadError
      have_gettext_gem = false
    end
    it "should return true for existent PO", :if => have_gettext_gem do
      data = <<-eop
msgid ""
msgstr ""
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Hello"
msgstr "Bonjour"
eop
      parser = GetText::PoParser.new
      File.should_receive(:exist?).with('foo/fr.po').and_return(true)
      GetText::PoParser.should_receive(:new).and_return(parser)
      parser.should_receive(:parse_file) do |file, hash|
        file.should == 'foo/fr.po'
        parser.parse(data, hash)
      end
      @locale.load('foo').should == true
      @locale.translate('Hello').should == "Bonjour"
    end
  end

  describe "#translate" do
    before do
      messages = @locale.instance_variable_get(:@messages)
      messages["Hello"] = "Bonjour"
    end

    it "should return translated string for existent string" do
      @locale.translate("Hello") == "Bonjour"
    end

    it "should return original string for nonexistent string" do
      @locale.translate("nonexistent") == "nonexistent"
    end
  end
end

Version data entries

29 entries across 22 versions & 5 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/gems/yard-0.8.7/spec/i18n/locale_spec.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/yard-0.8.7/spec/i18n/locale_spec.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/yard-0.8.7/spec/i18n/locale_spec.rb
yard-0.8.7 spec/i18n/locale_spec.rb
challah-1.0.0 vendor/bundle/gems/yard-0.8.6.1/spec/i18n/locale_spec.rb
yard-0.8.6.2 spec/i18n/locale_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.5.2/spec/i18n/locale_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6/spec/i18n/locale_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6.1/spec/i18n/locale_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/i18n/locale_spec.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/i18n/locale_spec.rb
yard-0.8.6.1 spec/i18n/locale_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.5.2/spec/i18n/locale_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.6/spec/i18n/locale_spec.rb
yard-0.8.6 spec/i18n/locale_spec.rb
challah-1.0.0.beta vendor/bundle/gems/yard-0.8.5.2/spec/i18n/locale_spec.rb
challah-1.0.0.beta vendor/bundle/gems/yard-0.8.3/spec/i18n/locale_spec.rb
yard-0.8.5.2 spec/i18n/locale_spec.rb
yard-0.8.5.1 spec/i18n/locale_spec.rb
yard-0.8.5 spec/i18n/locale_spec.rb