blob: 85913769f33b951716a3a7f349dea9a9e1a10934 (
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
|
require 'command_test'
class TestGenerateLocalizationArchive < CommandTest
def new_runner(twine_file = nil)
options = {}
options[:output_path] = @output_path
options[:format] = 'apple'
unless twine_file
twine_file = build_twine_file 'en', 'fr' do
add_section 'Section' do
add_definition key: 'value'
end
end
end
Twine::Runner.new(options, twine_file)
end
def test_generates_zip_file
new_runner.generate_localization_archive
assert File.exists?(@output_path), "zip file should exist"
end
def test_zip_file_structure
new_runner.generate_localization_archive
names = []
Zip::File.open(@output_path) do |zipfile|
zipfile.each do |entry|
names << entry.name
end
end
assert_equal ['Locales/', 'Locales/en.strings', 'Locales/fr.strings'], names
end
def test_uses_formatter
formatter = prepare_mock_formatter Twine::Formatters::Apple
formatter.expects(:format_file).twice
new_runner.generate_localization_archive
end
def test_prints_empty_file_warnings
empty_twine_file = build_twine_file('en') {}
new_runner(empty_twine_file).generate_localization_archive
assert_match "Skipping file", Twine::stderr.string
end
class TestValidate < CommandTest
def new_runner(validate)
options = {}
options[:output_path] = @output_path
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_localization_archive
end
def test_validates_twine_file_if_validate
assert_raises Twine::Error do
new_runner(true).generate_localization_archive
end
end
end
end
|