Changed TestCrateFolders to be a CommandTestCase and renamed it to TestGenerateAllStringFiles.

This commit is contained in:
Sebastian Ludwig 2015-11-28 01:18:39 +01:00
parent 559360977c
commit 17d206f7ce
4 changed files with 45 additions and 31 deletions

View file

@ -1,4 +0,0 @@
[[My Strings]]
[key1]
en = key1-english
es = key1-spanish

View file

@ -1,26 +0,0 @@
require 'twine_test_case'
class TestCreateFolders < TwineTestCase
def test_generate_all_fails_if_output_folder_does_not_exist
assert_raises Twine::Error do
execute "generate-all-string-files #{f 'twine_key1_en_es.txt'} #{@output_dir} -f apple"
end
end
def test_generate_all_creates_output_folder
# implicitly assert nothing raised
execute "generate-all-string-files #{f 'twine_key1_en_es.txt'} #{@output_dir} -f apple --create-folders"
end
def test_generate_all_does_not_create_folders
Dir.mkdir File.join @output_dir, 'en.lproj'
execute "generate-all-string-files #{f 'twine_key1_en_es.txt'} #{@output_dir} -f apple"
assert !File.exists?(File.join(@output_dir, 'es.lproj')), "language folder should not be created"
end
def test_generate_all_creates_folders
execute "generate-all-string-files #{f 'twine_key1_en_es.txt'} #{@output_dir} -f apple --create-folders"
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
end

View file

@ -0,0 +1,44 @@
require 'command_test_case'
class TestGenerateAllStringFiles < CommandTestCase
class TestCreateFolders < CommandTestCase
def new_runner(create_folders)
options = {}
options[:output_path] = @output_dir
options[:format] = 'apple'
options[:create_folders] = create_folders
@twine_file = build_twine_file 'en', 'es' do
add_section 'Section' do
add_row key: 'value'
end
end
Twine::Runner.new(nil, options, @twine_file)
end
def test_fails_if_output_folder_does_not_exist
assert_raises Twine::Error do
new_runner(false).generate_all_string_files
end
end
def test_creates_output_folder
FileUtils.remove_entry_secure @output_dir
new_runner(true).generate_all_string_files
assert File.exists? @output_dir
end
def test_does_not_create_language_folders_by_default
Dir.mkdir File.join @output_dir, 'en.lproj'
new_runner(false).generate_all_string_files
refute File.exists?(File.join(@output_dir, 'es.lproj')), "language folder should not be created"
end
def test_creates_language_folders
new_runner(true).generate_all_string_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
end
end

View file

@ -15,7 +15,7 @@ class TwineTestCase < Minitest::Test
end
def teardown
FileUtils.remove_entry_secure @output_dir
FileUtils.remove_entry_secure @output_dir if File.exists? @output_dir
super
end