twine 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,30 +1,30 @@
1
1
  require 'command_test_case'
2
2
 
3
3
  class TestGenerateLocDrop < CommandTestCase
4
- def setup
5
- super
6
-
4
+ def new_runner(twine_file = nil)
7
5
  options = {}
8
6
  options[:output_path] = @output_path
9
7
  options[:format] = 'apple'
10
8
 
11
- @twine_file = build_twine_file 'en', 'fr' do
12
- add_section 'Section' do
13
- add_row key: 'value'
9
+ unless twine_file
10
+ twine_file = build_twine_file 'en', 'fr' do
11
+ add_section 'Section' do
12
+ add_row key: 'value'
13
+ end
14
14
  end
15
15
  end
16
16
 
17
- @runner = Twine::Runner.new(options, @twine_file)
17
+ Twine::Runner.new(options, twine_file)
18
18
  end
19
19
 
20
20
  def test_generates_zip_file
21
- @runner.generate_loc_drop
21
+ new_runner.generate_loc_drop
22
22
 
23
- assert File.exists?(@output_path), "language folder should not be created"
23
+ assert File.exists?(@output_path), "zip file should exist"
24
24
  end
25
25
 
26
26
  def test_zip_file_structure
27
- @runner.generate_loc_drop
27
+ new_runner.generate_loc_drop
28
28
 
29
29
  names = []
30
30
  Zip::File.open(@output_path) do |zipfile|
@@ -37,12 +37,18 @@ class TestGenerateLocDrop < CommandTestCase
37
37
 
38
38
  def test_uses_formatter
39
39
  formatter = prepare_mock_formatter Twine::Formatters::Apple
40
- formatter.expects(:write_file).twice.with() { |path, lang| FileUtils.touch path }
40
+ formatter.expects(:format_file).twice
41
+
42
+ new_runner.generate_loc_drop
43
+ end
41
44
 
42
- @runner.generate_loc_drop
45
+ def test_prints_empty_file_warnings
46
+ empty_twine_file = build_twine_file('en') {}
47
+ new_runner(empty_twine_file).generate_loc_drop
48
+ assert_match "Skipping file", Twine::stderr.string
43
49
  end
44
50
 
45
- class TestDeliberate < CommandTestCase
51
+ class TestValidate < CommandTestCase
46
52
  def new_runner(validate)
47
53
  options = {}
48
54
  options[:output_path] = @output_path
@@ -12,31 +12,31 @@ class TestGenerateStringFile < CommandTestCase
12
12
  Twine::Runner.new(options, strings)
13
13
  end
14
14
 
15
- def prepare_mock_write_file_formatter(formatter_class)
15
+ def prepare_mock_format_file_formatter(formatter_class)
16
16
  formatter = prepare_mock_formatter(formatter_class)
17
- formatter.expects(:write_file)
17
+ formatter.expects(:format_file).returns(true)
18
18
  end
19
19
 
20
20
  def test_deducts_android_format_from_output_path
21
- prepare_mock_write_file_formatter Twine::Formatters::Android
21
+ prepare_mock_format_file_formatter Twine::Formatters::Android
22
22
 
23
23
  new_runner('fr', 'fr.xml').generate_string_file
24
24
  end
25
25
 
26
26
  def test_deducts_apple_format_from_output_path
27
- prepare_mock_write_file_formatter Twine::Formatters::Apple
27
+ prepare_mock_format_file_formatter Twine::Formatters::Apple
28
28
 
29
29
  new_runner('fr', 'fr.strings').generate_string_file
30
30
  end
31
31
 
32
32
  def test_deducts_jquery_format_from_output_path
33
- prepare_mock_write_file_formatter Twine::Formatters::JQuery
33
+ prepare_mock_format_file_formatter Twine::Formatters::JQuery
34
34
 
35
35
  new_runner('fr', 'fr.json').generate_string_file
36
36
  end
37
37
 
38
38
  def test_deducts_gettext_format_from_output_path
39
- prepare_mock_write_file_formatter Twine::Formatters::Gettext
39
+ prepare_mock_format_file_formatter Twine::Formatters::Gettext
40
40
 
41
41
  new_runner('fr', 'fr.po').generate_string_file
42
42
  end
@@ -44,12 +44,21 @@ class TestGenerateStringFile < CommandTestCase
44
44
  def test_deducts_language_from_output_path
45
45
  random_language = KNOWN_LANGUAGES.sample
46
46
  formatter = prepare_mock_formatter Twine::Formatters::Android
47
- formatter.expects(:write_file).with(anything, random_language)
47
+ formatter.expects(:format_file).with(random_language).returns(true)
48
48
 
49
49
  new_runner(nil, "#{random_language}.xml").generate_string_file
50
50
  end
51
51
 
52
- class TestDeliberate < CommandTestCase
52
+ def test_returns_error_if_nothing_written
53
+ formatter = prepare_mock_formatter Twine::Formatters::Android
54
+ formatter.expects(:format_file).returns(false)
55
+
56
+ assert_raises Twine::Error do
57
+ new_runner('fr', 'fr.xml').generate_string_file
58
+ end
59
+ end
60
+
61
+ class TestValidate < CommandTestCase
53
62
  def new_runner(validate)
54
63
  options = {}
55
64
  options[:output_path] = @output_path
@@ -43,14 +43,14 @@ class TestOutputProcessor < TwineTestCase
43
43
  end
44
44
 
45
45
  def test_include_translated
46
- processor = Twine::Processors::OutputProcessor.new(@strings, { include: 'translated' })
46
+ processor = Twine::Processors::OutputProcessor.new(@strings, { include: :translated })
47
47
  result = processor.process('fr')
48
48
 
49
49
  assert_equal %w(key4), result.strings_map.keys.sort
50
50
  end
51
51
 
52
52
  def test_include_untranslated
53
- processor = Twine::Processors::OutputProcessor.new(@strings, { include: 'untranslated' })
53
+ processor = Twine::Processors::OutputProcessor.new(@strings, { include: :untranslated })
54
54
  result = processor.process('fr')
55
55
 
56
56
  assert_equal %w(key1 key2 key3), result.strings_map.keys.sort
@@ -6,7 +6,7 @@ class TestStringsFile < TwineTestCase
6
6
  super
7
7
 
8
8
  @strings = Twine::StringsFile.new
9
- @strings.read fixture('twine_accent_values.txt')
9
+ @strings.read fixture_path('twine_accent_values.txt')
10
10
  end
11
11
 
12
12
  def test_reading_keeps_leading_accent
@@ -50,7 +50,7 @@ class TestStringsFile < TwineTestCase
50
50
 
51
51
  @strings.write @output_path
52
52
 
53
- assert_equal content('twine_accent_values.txt'), output_content
53
+ assert_equal content('twine_accent_values.txt'), File.read(@output_path)
54
54
  end
55
55
 
56
56
  end
@@ -20,7 +20,7 @@ module TwineFileDSL
20
20
  return unless @currently_built_twine_file
21
21
  return unless @currently_built_twine_file_section
22
22
 
23
- # this relies on Ruby 1.9 preserving the order of hash elements
23
+ # this relies on Ruby preserving the order of hash elements
24
24
  key, value = parameters.first
25
25
  row = Twine::StringsRow.new(key.to_s)
26
26
  if value.is_a? Hash
@@ -29,21 +29,20 @@ class TwineTestCase < Minitest::Test
29
29
  super
30
30
  end
31
31
 
32
- def output_content
33
- File.read @output_path
34
- end
35
-
36
32
  def execute(command)
37
33
  command += " -o #{@output_path}"
38
34
  Twine::Runner.run(command.split(" "))
39
35
  end
40
36
 
41
- def fixture(filename)
37
+ def fixture_path(filename)
42
38
  File.join File.dirname(__FILE__), 'fixtures', filename
43
39
  end
44
- alias :f :fixture
45
40
 
46
41
  def content(filename)
47
- ERB.new(File.read fixture(filename)).result
42
+ ERB.new(File.read fixture_path(filename)).result
43
+ end
44
+
45
+ def content_io(filename)
46
+ StringIO.new ERB.new(File.read fixture_path(filename)).result
48
47
  end
49
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -114,6 +114,11 @@ files:
114
114
  - lib/twine/version.rb
115
115
  - test/command_test_case.rb
116
116
  - test/fixtures/consume_loc_drop.zip
117
+ - test/fixtures/enc_utf16be.dummy
118
+ - test/fixtures/enc_utf16be_bom.dummy
119
+ - test/fixtures/enc_utf16le.dummy
120
+ - test/fixtures/enc_utf16le_bom.dummy
121
+ - test/fixtures/enc_utf8.dummy
117
122
  - test/fixtures/formatter_android.xml
118
123
  - test/fixtures/formatter_apple.strings
119
124
  - test/fixtures/formatter_django.po