Skip to content

Commit ad7f3a3

Browse files
committed
Update po generation spec with examples for what's new and release notes
1 parent 5f4f6ae commit ad7f3a3

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

spec/gp_update_metadata_source_spec.rb

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
require 'spec_helper'
22

33
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
55
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.
147
output_path = File.join(dir, 'output.po')
15-
# Also note: The file must exist already
168
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 ""
1715
msgctxt "key1"
1816
msgid "this value should change"
1917
msgstr ""
@@ -23,24 +21,56 @@
2321
PO
2422
File.write(output_path, dummy_text)
2523

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")
2729
file_1_path = File.join(dir, '1.txt')
2830
File.write(file_1_path, 'value 1')
2931
file_2_path = File.join(dir, '2.txt')
3032
File.write(file_2_path, 'value 2')
33+
file_3_path = File.join(dir, '3.txt')
34+
File.write(file_3_path, 'value 3')
3135

3236
described_class.run(
3337
po_file_path: output_path,
3438
release_version: '1.23',
3539
source_files: {
40+
release_note: release_notes_path,
41+
whats_new: whats_new_path,
3642
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
3845
}
3946
)
4047

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
4357
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 ""
4474
msgctxt "key1"
4575
msgid "value 1"
4676
msgstr ""

0 commit comments

Comments
 (0)