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

github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Ludwig <sebastian@lurado.de>2017-12-12 19:27:08 +0300
committerSebastian Ludwig <sebastian@lurado.de>2017-12-12 19:27:08 +0300
commite838dcc8fdecf22b995b2f1310901c9ffe250c51 (patch)
tree410ac5ec41bfa6bf5e65bbebeca775a9845d0f5b
parent0688167c59c9094d9767fec91272543baadebf42 (diff)
Add unit tests for regression fixed in #222. Closes #223.
-rw-r--r--test/test_generate_all_localization_files.rb38
-rw-r--r--test/test_generate_localization_file.rb14
2 files changed, 45 insertions, 7 deletions
diff --git a/test/test_generate_all_localization_files.rb b/test/test_generate_all_localization_files.rb
index faa1bf1..42208e1 100644
--- a/test/test_generate_all_localization_files.rb
+++ b/test/test_generate_all_localization_files.rb
@@ -1,11 +1,13 @@
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
+ def new_runner(create_folders, twine_file = nil, options = {})
+ default_options = {}
+ default_options[:output_path] = @output_dir
+ default_options[:format] = 'apple'
+ default_options[:create_folders] = create_folders
+
+ options = default_options.merge options
unless twine_file
twine_file = build_twine_file 'en', 'es' do
@@ -18,6 +20,32 @@ class TestGenerateAllLocalizationFiles < CommandTest
Twine::Runner.new(options, twine_file)
end
+ class TestFormatterSelection < TestGenerateAllLocalizationFiles
+ def setup
+ super
+ Dir.mkdir File.join @output_dir, 'values-en'
+
+ # both Android and Tizen can handle folders containing `values-en`
+ android_formatter = prepare_mock_formatter(Twine::Formatters::Android)
+ tizen_formatter = prepare_mock_formatter(Twine::Formatters::Tizen, false)
+ end
+
+ def new_runner(options = {})
+ super(true, nil, options)
+ end
+
+ def test_returns_error_for_ambiguous_output_path
+ assert_raises Twine::Error do
+ new_runner(format: nil).generate_all_localization_files
+ end
+ end
+
+ def test_uses_specified_formatter_to_resolve_ambiguity
+ # implicit assert that this call doesn't raise an exception
+ new_runner(format: 'android').generate_all_localization_files
+ end
+ end
+
class TestDoNotCreateFolders < TestGenerateAllLocalizationFiles
def new_runner(twine_file = nil)
super(false, twine_file)
diff --git a/test/test_generate_localization_file.rb b/test/test_generate_localization_file.rb
index 6d4bb49..441e256 100644
--- a/test/test_generate_localization_file.rb
+++ b/test/test_generate_localization_file.rb
@@ -1,8 +1,7 @@
require 'command_test'
class TestGenerateLocalizationFile < CommandTest
- def new_runner(language, file)
- options = {}
+ def new_runner(language, file, options = {})
options[:output_path] = File.join(@output_dir, file) if file
options[:languages] = language if language
@@ -59,6 +58,17 @@ class TestGenerateLocalizationFile < CommandTest
end
end
+ def test_uses_specified_formatter_to_resolve_ambiguity
+ # both Android and Tizen use .xml
+ android_formatter = prepare_mock_formatter(Twine::Formatters::Android)
+ android_formatter.stubs(:format_file).returns(true)
+ tizen_formatter = prepare_mock_formatter(Twine::Formatters::Tizen, false)
+ tizen_formatter.stubs(:format_file).returns(true)
+
+ # implicit assert that this call doesn't raise an exception
+ new_runner('fr', 'fr.xml', format: 'android').generate_localization_file
+ end
+
def test_deducts_language_from_output_path
random_language = KNOWN_LANGUAGES.sample
formatter = prepare_mock_formatter Twine::Formatters::Android