diff options
author | Sebastian Celis <sebastian@sebastiancelis.com> | 2017-12-31 00:29:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-31 00:29:28 +0300 |
commit | c2b517707a9e9bba267aea8f950c551c86b26dcd (patch) | |
tree | 95b85dd25a354bacd82884ea264754271b56836b | |
parent | 77a7b49a18cfd0e3d2d670b3a3ab5a8215695563 (diff) | |
parent | e838dcc8fdecf22b995b2f1310901c9ffe250c51 (diff) |
Merge pull request #230 from sebastianludwig/223-unit-tests-for-222
Unit tests for regression fixed in #222
-rw-r--r-- | test/test_generate_all_localization_files.rb | 38 | ||||
-rw-r--r-- | test/test_generate_localization_file.rb | 14 |
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 |