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 56 57 58 59 60 61 62 63
|
# frozen_string_literal: true
require 'rspec/expectations'
require 'tmpdir'
require 'spec_helper'
require 'gettext-setup'
describe GettextSetup::MetadataPot do
before(:each) do
GettextSetup.initialize(File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/locales')))
end
context '#metadata_path' do
it 'finds the right metadata path' do
expect(GettextSetup::MetadataPot.metadata_path).to match(/sinatra-i18n_metadata\.pot/)
end
end
context '#pot_string' do
it 'generates a reasonable POT string' do
expect(GettextSetup::MetadataPot.pot_string({})).to match(/Last-Translator: FULL NAME <EMAIL@ADDRESS>/)
end
it 'includes summary when provided' do
metadata = { 'summary' => 'abc' }
expect(GettextSetup::MetadataPot.pot_string(metadata)).to match(/msgid "abc"/)
end
it 'includes summary when provided' do
metadata = { 'description' => 'def' }
expect(GettextSetup::MetadataPot.pot_string(metadata)).to match(/msgid "def"/)
end
it 'includes both summary and description when provided' do
metadata = { 'summary' => 'abc', 'description' => 'def' }
result = expect(GettextSetup::MetadataPot.pot_string(metadata))
result.to match(/msgid "def"/)
result.to match(/msgid "abc"/)
end
end
context '#load_metadata' do
it 'loads metadata correctly' do
Dir.mktmpdir do |dir|
file = File.join(dir, 'metadata.json')
File.open(file, 'w') { |f| f.write('{"description":"abcdef", "summary":"ghi"}') }
metadata = GettextSetup::MetadataPot.metadata(File.join(dir, 'metadata.json').to_s)
expect(metadata).to eq('description' => 'abcdef', 'summary' => 'ghi')
end
end
it 'uses an empty hash if no metadata.json is found' do
metadata = GettextSetup::MetadataPot.metadata(File.join(Dir.mktmpdir, 'metadata.json').to_s)
expect(metadata).to eq({})
end
end
context '#generate_metadata_pot' do
it 'works with everything supplied' do
dir = Dir.mktmpdir
file = File.join(dir, 'metadata.pot')
metadata = { 'description' => 'abc', 'summary' => 'def' }
GettextSetup::MetadataPot.generate_metadata_pot(metadata,
file)
contents = File.read(file)
expect(contents).to match(/msgid "abc"/)
expect(contents).to match(/msgid "def"/)
end
end
end
|