|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe Fastlane::Actions::GpUpdateMetadataSourceAction do
|
4 |
| - it 'works' do |
| 4 | + it 'updates any block in a given .po file with the values from the given sources' do |
5 | 5 | Dir.mktmpdir do |dir|
|
6 |
| - # Reminder: you can stub Fastlane stuff with calls like |
7 |
| - # expect(FastlaneCore::UI).to receive(:success).with('Done') |
8 |
| - |
9 |
| - # 1: Create tmp location for the po file |
10 |
| - # |
11 |
| - # Note, can't use StringIO.new because of implementation details: |
12 |
| - # |
13 |
| - # Failure/Error: "#{File.dirname(orig_file_path)}/#{File.basename(orig_file_path, '.*')}.tmp" |
| 6 | + # 1: Create a dummy .po file to use as input. |
14 | 7 | output_path = File.join(dir, 'output.po')
|
15 |
| - # Also note: The file must exist already |
16 | 8 | dummy_text = <<~PO
|
| 9 | + msgctxt "v1.0-whats-new" |
| 10 | + msgid "this value should change" |
| 11 | + msgstr "" |
| 12 | + msgctxt "release_note_0122" |
| 13 | + msgid "previous version notes required to have current one added" |
| 14 | + msgstr "" |
17 | 15 | msgctxt "key1"
|
18 | 16 | msgid "this value should change"
|
19 | 17 | msgstr ""
|
|
23 | 21 | PO
|
24 | 22 | File.write(output_path, dummy_text)
|
25 | 23 |
|
26 |
| - # 2: read a few sources |
| 24 | + # 2: Create source files with value to insert in the .po |
| 25 | + release_notes_path = File.join(dir, 'release_notes.txt') |
| 26 | + File.write(release_notes_path, "- release notes\n- more release notes") |
| 27 | + whats_new_path = File.join(dir, 'whats_new.txt') |
| 28 | + File.write(whats_new_path, "- something new\n- something else new") |
27 | 29 | file_1_path = File.join(dir, '1.txt')
|
28 | 30 | File.write(file_1_path, 'value 1')
|
29 | 31 | file_2_path = File.join(dir, '2.txt')
|
30 | 32 | File.write(file_2_path, 'value 2')
|
| 33 | + file_3_path = File.join(dir, '3.txt') |
| 34 | + File.write(file_3_path, 'value 3') |
31 | 35 |
|
32 | 36 | described_class.run(
|
33 | 37 | po_file_path: output_path,
|
34 | 38 | release_version: '1.23',
|
35 | 39 | source_files: {
|
| 40 | + release_note: release_notes_path, |
| 41 | + whats_new: whats_new_path, |
36 | 42 | key1: file_1_path,
|
37 |
| - key2: file_2_path |
| 43 | + key2: file_2_path, |
| 44 | + key3: file_3_path # This is not in the input .po and won't be added |
38 | 45 | }
|
39 | 46 | )
|
40 | 47 |
|
41 |
| - # 3: compare |
42 |
| - # notice that the new line after each block is added by the conversion |
| 48 | + # 3: Assert given .po has been updated as expected |
| 49 | + # |
| 50 | + # Notice: |
| 51 | + # |
| 52 | + # - The new line after each block is added by the conversion |
| 53 | + # - That there's no new line between release_note_0122 and key1, because |
| 54 | + # the notes are copied as they are with no extra manipulation |
| 55 | + # - The key3 source is not part of the output because was not in the |
| 56 | + # original .po input |
43 | 57 | expected = <<~PO
|
| 58 | + msgctxt "v1.23-whats-new" |
| 59 | + msgid "" |
| 60 | + "- something new\\n" |
| 61 | + "- something else new\\n" |
| 62 | + msgstr "" |
| 63 | +
|
| 64 | + msgctxt "release_note_0123" |
| 65 | + msgid "" |
| 66 | + "1.23:\\n" |
| 67 | + "- release notes\\n" |
| 68 | + "- more release notes\\n" |
| 69 | + msgstr "" |
| 70 | +
|
| 71 | + msgctxt "release_note_0122" |
| 72 | + msgid "previous version notes required to have current one added" |
| 73 | + msgstr "" |
44 | 74 | msgctxt "key1"
|
45 | 75 | msgid "value 1"
|
46 | 76 | msgstr ""
|
|
0 commit comments