Skip to content

Commit 9061436

Browse files
authored
Add high-level tests for the current .po generation behavior (#326)
2 parents 8427fb8 + d095cd2 commit 9061436

5 files changed

+176
-0
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Metrics/BlockLength:
6767
Max: 80
6868
Exclude:
6969
- spec/**/*_spec.rb
70+
- spec/**/shared_examples_*.rb
7071

7172
Metrics/ClassLength:
7273
Max: 300

.rubocop_todo.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ RSpec/FilePath:
132132
- 'spec/android_merge_translators_strings_spec.rb'
133133
- 'spec/android_version_helper_spec.rb'
134134
- 'spec/an_metadata_update_helper_spec.rb'
135+
- 'spec/an_update_metadata_source_spec.rb'
135136
- 'spec/configuration_spec.rb'
136137
- 'spec/configure_helper_spec.rb'
137138
- 'spec/encryption_helper_spec.rb'
@@ -145,6 +146,7 @@ RSpec/FilePath:
145146
- 'spec/ios_generate_strings_file_from_code_spec.rb'
146147
- 'spec/ios_l10n_helper_spec.rb'
147148
- 'spec/ios_merge_strings_files_spec.rb'
149+
- 'spec/gp_update_metadata_source_spec.rb'
148150

149151
# Offense count: 8
150152
# Cop supports --auto-correct.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'spec_helper'
2+
require 'shared_examples_for_update_metadata_source_action'
3+
4+
describe Fastlane::Actions::AnUpdateMetadataSourceAction do
5+
include_examples 'update_metadata_source_action', whats_new_fails: true
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'spec_helper'
2+
require 'shared_examples_for_update_metadata_source_action'
3+
4+
describe Fastlane::Actions::GpUpdateMetadataSourceAction do
5+
include_examples 'update_metadata_source_action', whats_new_fails: false
6+
end
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
require 'spec_helper'
2+
3+
RSpec.shared_examples 'update_metadata_source_action' do |options|
4+
it 'updates any block in a given .po file with the values from the given sources' do
5+
Dir.mktmpdir do |dir|
6+
output_path = File.join(dir, 'output.po')
7+
dummy_text = <<~PO
8+
msgctxt "key1"
9+
msgid "this value should change"
10+
msgstr ""
11+
msgctxt "key2"
12+
msgid "this value should change, too"
13+
msgstr ""
14+
PO
15+
File.write(output_path, dummy_text)
16+
17+
file_1_path = File.join(dir, '1.txt')
18+
File.write(file_1_path, 'value 1')
19+
file_2_path = File.join(dir, '2.txt')
20+
File.write(file_2_path, 'value 2')
21+
22+
described_class.run(
23+
po_file_path: output_path,
24+
source_files: {
25+
key1: file_1_path,
26+
key2: file_2_path
27+
}
28+
)
29+
30+
expected = <<~PO
31+
msgctxt "key1"
32+
msgid "value 1"
33+
msgstr ""
34+
35+
msgctxt "key2"
36+
msgid "value 2"
37+
msgstr ""
38+
39+
PO
40+
expect(File.read(output_path)).to eq(expected)
41+
end
42+
end
43+
44+
it 'combines the given `release_version` and `whats_new` parameter into a new block' do
45+
pending 'this currently fails; in the long run, we might consolidate `whats_new` with `release_notes`' if options[:whats_new_fails]
46+
47+
Dir.mktmpdir do |dir|
48+
output_path = File.join(dir, 'output.po')
49+
dummy_text = <<~PO
50+
msgctxt "v1.0-whats-new"
51+
msgid "this will not change"
52+
msgstr ""
53+
PO
54+
File.write(output_path, dummy_text)
55+
56+
whats_new_path = File.join(dir, 'whats_new.txt')
57+
File.write(whats_new_path, "- something new\n- something else new")
58+
59+
described_class.run(
60+
po_file_path: output_path,
61+
release_version: '1.23',
62+
source_files: {
63+
whats_new: whats_new_path
64+
}
65+
)
66+
67+
expected = <<~'PO'
68+
msgctxt "v1.23-whats-new"
69+
msgid ""
70+
"- something new\n"
71+
"- something else new\n"
72+
msgstr ""
73+
74+
PO
75+
expect(File.read(output_path)).to eq(expected)
76+
end
77+
end
78+
79+
it 'adds entries passed as input even if not part of the original `.po` file' do
80+
pending 'this currently fails and will be addressed as part of the upcoming refactor/rewrite of the functionality'
81+
82+
Dir.mktmpdir do |dir|
83+
output_path = File.join(dir, 'output.po')
84+
dummy_text = <<~PO
85+
msgctxt "key1"
86+
msgid "this value should change"
87+
msgstr ""
88+
PO
89+
File.write(output_path, dummy_text)
90+
91+
# 2: Create source files with value to insert in the .po
92+
file_1_path = File.join(dir, '1.txt')
93+
File.write(file_1_path, 'value 1')
94+
file_2_path = File.join(dir, '2.txt')
95+
File.write(file_2_path, 'value 2')
96+
97+
described_class.run(
98+
po_file_path: output_path,
99+
source_files: {
100+
key1: file_1_path,
101+
key2: file_2_path
102+
}
103+
)
104+
105+
expected = <<~PO
106+
msgctxt "key1"
107+
msgid "value 1"
108+
msgstr ""
109+
110+
msgctxt "key2"
111+
msgid "value 2"
112+
msgstr ""
113+
114+
PO
115+
expect(File.read(output_path)).to eq(expected)
116+
end
117+
end
118+
119+
it 'combines the given `release_version` and `release_notes` in a new block, keeps the n-1 ones, and deletes the others' do
120+
Dir.mktmpdir do |dir|
121+
output_path = File.join(dir, 'output.po')
122+
dummy_text = <<~PO
123+
msgctxt "release_note_0122"
124+
msgid "previous version notes required to have current one added"
125+
msgstr ""
126+
msgctxt "release_note_0121"
127+
msgid "this older release notes block should be removed"
128+
msgstr ""
129+
msgctxt "release_note_0120"
130+
msgid "this older release notes block should be removed"
131+
msgstr ""
132+
PO
133+
File.write(output_path, dummy_text)
134+
135+
release_notes_path = File.join(dir, 'release_notes.txt')
136+
File.write(release_notes_path, "- release notes\n- more release notes")
137+
138+
described_class.run(
139+
po_file_path: output_path,
140+
release_version: '1.23',
141+
source_files: {
142+
release_note: release_notes_path
143+
}
144+
)
145+
146+
expected = <<~'PO'
147+
msgctxt "release_note_0123"
148+
msgid ""
149+
"1.23:\n"
150+
"- release notes\n"
151+
"- more release notes\n"
152+
msgstr ""
153+
154+
msgctxt "release_note_0122"
155+
msgid "previous version notes required to have current one added"
156+
msgstr ""
157+
PO
158+
expect(File.read(output_path).inspect).to eq(expected.inspect)
159+
end
160+
end
161+
end

0 commit comments

Comments
 (0)