File: module_loading_spec.rb

package info (click to toggle)
puppet 5.5.10-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,116 kB
  • sloc: ruby: 250,669; sh: 1,620; xml: 218; makefile: 151; sql: 103
file content (53 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download
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
require 'spec_helper'
require 'puppet_spec/modules'
require 'puppet_spec/files'

require 'puppet/gettext/module_translations'

describe Puppet::ModuleTranslations do
  include PuppetSpec::Files

  describe "loading translations from the module path" do
    let(:modpath) { tmpdir('modpath') }

    let(:module_a) { PuppetSpec::Modules.create(
      "mod_a",
      modpath,
      :metadata => {
        :author => 'foo'
      },
      :environment => mock("environment"))
    }

    let(:module_b) { PuppetSpec::Modules.create(
      "mod_b",
      modpath,
      :metadata => {
        :author => 'foo'
      },
      :environment => mock("environment"))
    }

    it "should attempt to load translations only for modules that have them" do
      module_a.expects(:has_translations?).returns(false)
      module_b.expects(:has_translations?).returns(true)
      Puppet::GettextConfig.expects(:load_translations).with("foo-mod_b", File.join(modpath, "mod_b", "locales"), :po).returns(true)

      Puppet::ModuleTranslations.load_from_modulepath([module_a, module_b])
    end
  end

  describe "loading translations from $vardir" do
    let(:vardir) {
      dir_containing("vardir",
        { "locales" => { "ja" => { "foo-mod_a.po" => "" } } })
    }

    it "should attempt to load translations for the current locale" do
      Puppet::GettextConfig.expects(:current_locale).returns("ja")
      Puppet::GettextConfig.expects(:load_translations).with("foo-mod_a", File.join(vardir, "locales"), :po).returns(true)

      Puppet::ModuleTranslations.load_from_vardir(vardir)
    end
  end
end