Add unit tests for regression fixed in #222. Closes #223.

This commit is contained in:
Sebastian Ludwig 2017-12-12 17:27:08 +01:00
parent 0688167c59
commit e838dcc8fd
2 changed files with 45 additions and 7 deletions

View file

@ -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)

View file

@ -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