Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_generate_all_localization_files.rb « test - github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: faa1bf14f31125f5fa1cf0e1dc91bcfb5a7c5daf (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'command_test'

class TestGenerateAllLocalizationFiles < CommandTest
  def new_runner(create_folders, twine_file = nil)
    options = {}
    options[:output_path] = @output_dir
    options[:format] = 'apple'
    options[:create_folders] = create_folders

    unless twine_file
      twine_file = build_twine_file 'en', 'es' do
        add_section 'Section' do
          add_definition key: 'value'
        end
      end
    end

    Twine::Runner.new(options, twine_file)
  end

  class TestDoNotCreateFolders < TestGenerateAllLocalizationFiles
    def new_runner(twine_file = nil)
      super(false, twine_file)
    end

    def test_fails_if_output_folder_does_not_exist
      assert_raises Twine::Error do
        new_runner.generate_all_localization_files
      end
    end

    def test_does_not_create_language_folders
      Dir.mkdir File.join @output_dir, 'en.lproj'
      new_runner.generate_all_localization_files
      refute File.exists?(File.join(@output_dir, 'es.lproj')), "language folder should not be created"
    end

    def test_prints_empty_file_warnings
      Dir.mkdir File.join @output_dir, 'en.lproj'
      empty_twine_file = build_twine_file('en') {}
      new_runner(empty_twine_file).generate_all_localization_files
      assert_match "Skipping file at path", Twine::stderr.string
    end
  end

  class TestCreateFolders < TestGenerateAllLocalizationFiles
    def new_runner(twine_file = nil)
      super(true, twine_file)
    end

    def test_creates_output_folder
      FileUtils.remove_entry_secure @output_dir
      new_runner.generate_all_localization_files
      assert File.exists? @output_dir
    end

    def test_creates_language_folders
      new_runner.generate_all_localization_files
      assert File.exists?(File.join(@output_dir, 'en.lproj')), "language folder 'en.lproj' should be created"
      assert File.exists?(File.join(@output_dir, 'es.lproj')), "language folder 'es.lproj' should be created"
    end

    def test_prints_empty_file_warnings
      empty_twine_file = build_twine_file('en') {}
      new_runner(empty_twine_file).generate_all_localization_files

      assert_match "Skipping file at path", Twine::stderr.string
    end
  end

  class TestValidate < CommandTest
    def new_runner(validate)
      Dir.mkdir File.join @output_dir, 'values-en'

      options = {}
      options[:output_path] = @output_dir
      options[:format] = 'android'
      options[:validate] = validate

      twine_file = build_twine_file 'en' do
        add_section 'Section' do
          add_definition key: 'value'
          add_definition key: 'value'
        end
      end

      Twine::Runner.new(options, twine_file)
    end

    def test_does_not_validate_twine_file
      prepare_mock_formatter Twine::Formatters::Android

      new_runner(false).generate_all_localization_files
    end

    def test_validates_twine_file_if_validate
      assert_raises Twine::Error do
        new_runner(true).generate_all_localization_files
      end
    end
  end
end