From ba4b69baf2e41b495db69b6c8dbc4d138e5752f1 Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Fri, 27 Nov 2015 20:10:24 +0100 Subject: [PATCH] Added unit tests for loc drop generation and consumption. --- test/fixtures/consume_loc_drop.zip | Bin 0 -> 548 bytes test/test_consume_loc_drop.rb | 27 ++++++++++++++++++ test/test_generate_loc_drop.rb | 44 +++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 test/fixtures/consume_loc_drop.zip create mode 100644 test/test_consume_loc_drop.rb create mode 100644 test/test_generate_loc_drop.rb diff --git a/test/fixtures/consume_loc_drop.zip b/test/fixtures/consume_loc_drop.zip new file mode 100644 index 0000000000000000000000000000000000000000..5efca143cc3dce8d67b127a1bf7f6717d8fb2cd6 GIT binary patch literal 548 zcmWIWW@Zs#0D;;C)$U*hl;8l;KKaRsIjP0^0Z>&OU{z}rb{@|J%60&;5R$6YJiX$Q zqRhPX;>*`BJqo%IRG_1A!ZVaZPxI6nZ~d@>(`P(cJ9jOAwp2`Y+LC1&Dxq2}Q_`O; z)slEI^R;BdlNzDVm%N292d@~)NMRv%}xeXhXwsp?!fA>Vrn_8yAhwmy19iu!yU%RWWtO)WP!oPzzD=|9YHKa zIKy;d4{4BEkgg?-YDl^e;U3_PsvkW-5c>Bc>xTzVfHx}}NDVU(ZUfR0Aj=p4)s~~a literal 0 HcmV?d00001 diff --git a/test/test_consume_loc_drop.rb b/test/test_consume_loc_drop.rb new file mode 100644 index 0000000..786eca7 --- /dev/null +++ b/test/test_consume_loc_drop.rb @@ -0,0 +1,27 @@ +require 'command_test_case' + +class TestConsumeLocDrop < CommandTestCase + def setup + super + + options = {} + options[:input_path] = fixture 'consume_loc_drop.zip' + options[:output_path] = @output_path + options[:format] = 'apple' + + @twine_file = build_twine_file 'en', 'es' do + add_section 'Section' do + add_row key1: 'value1' + end + end + + @runner = Twine::Runner.new(nil, options, @twine_file) + end + + def test_consumes_zip_file + @runner.consume_loc_drop + + assert @twine_file.strings_map['key1'].translations['en'], 'value1-english' + assert @twine_file.strings_map['key1'].translations['es'], 'value1-spanish' + end +end diff --git a/test/test_generate_loc_drop.rb b/test/test_generate_loc_drop.rb new file mode 100644 index 0000000..3571323 --- /dev/null +++ b/test/test_generate_loc_drop.rb @@ -0,0 +1,44 @@ +require 'command_test_case' + +class TestGenerateLocDrop < CommandTestCase + def setup + super + + options = {} + options[:output_path] = @output_path + options[:format] = 'apple' + + @twine_file = build_twine_file 'en', 'fr' do + add_section 'Section' do + add_row key: 'value' + end + end + + @runner = Twine::Runner.new(nil, options, @twine_file) + end + + def test_generates_zip_file + @runner.generate_loc_drop + + assert File.exists?(@output_path), "language folder should not be created" + end + + def test_zip_file_structure + @runner.generate_loc_drop + + 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(:write_file).twice.with() { |path, lang| FileUtils.touch path } + + @runner.generate_loc_drop + end +end