Skip to content

Commit d095cd2

Browse files
committed
Consolidate all an_ and gp_ update metadata specs in shared examples
Thanks for nudging in this direction @AliSoftware. I had considered using shared examples but decided not to try it when I noticed the difference with the `whats_new` block. Turns out that was the only difference –that we found so far– and a simple flag was enough to account for it in the shared examples See #326 (comment)
1 parent 316b7d6 commit d095cd2

File tree

4 files changed

+166
-257
lines changed

4 files changed

+166
-257
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
Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,6 @@
11
require 'spec_helper'
2+
require 'shared_examples_for_update_metadata_source_action'
23

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

34
describe Fastlane::Actions::GpUpdateMetadataSourceAction do
4-
it 'updates any block in a given .po file with the values from the given sources' do
5-
Dir.mktmpdir do |dir|
6-
# 1: Create a dummy .po file to use as input.
7-
output_path = File.join(dir, 'output.po')
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 ""
15-
msgctxt "release_note_0121"
16-
msgid "this older release notes block should be removed"
17-
msgstr ""
18-
msgctxt "key1"
19-
msgid "this value should change"
20-
msgstr ""
21-
msgctxt "key2"
22-
msgid "this value should change"
23-
msgstr ""
24-
PO
25-
File.write(output_path, dummy_text)
26-
27-
# 2: Create source files with value to insert in the .po
28-
release_notes_path = File.join(dir, 'release_notes.txt')
29-
File.write(release_notes_path, "- release notes\n- more release notes")
30-
whats_new_path = File.join(dir, 'whats_new.txt')
31-
File.write(whats_new_path, "- something new\n- something else new")
32-
file_1_path = File.join(dir, '1.txt')
33-
File.write(file_1_path, 'value 1')
34-
file_2_path = File.join(dir, '2.txt')
35-
File.write(file_2_path, 'value 2')
36-
37-
described_class.run(
38-
po_file_path: output_path,
39-
release_version: '1.23',
40-
source_files: {
41-
release_note: release_notes_path,
42-
whats_new: whats_new_path,
43-
key1: file_1_path,
44-
key2: file_2_path
45-
}
46-
)
47-
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-
expected = <<~PO
56-
msgctxt "v1.23-whats-new"
57-
msgid ""
58-
"- something new\\n"
59-
"- something else new\\n"
60-
msgstr ""
61-
62-
msgctxt "release_note_0123"
63-
msgid ""
64-
"1.23:\\n"
65-
"- release notes\\n"
66-
"- more release notes\\n"
67-
msgstr ""
68-
69-
msgctxt "release_note_0122"
70-
msgid "previous version notes required to have current one added"
71-
msgstr ""
72-
msgctxt "key1"
73-
msgid "value 1"
74-
msgstr ""
75-
76-
msgctxt "key2"
77-
msgid "value 2"
78-
msgstr ""
79-
80-
PO
81-
expect(File.read(output_path)).to eq(expected)
82-
end
83-
end
84-
85-
it 'adds entries passed as input even if not part of the original `.po` file' do
86-
pending 'this currently fails and will be addressed as part of the upcoming refactor/rewrite of the functionality'
87-
Dir.mktmpdir do |dir|
88-
output_path = File.join(dir, 'output.po')
89-
dummy_text = <<~PO
90-
msgctxt "key1"
91-
msgid "this value should change"
92-
msgstr ""
93-
PO
94-
File.write(output_path, dummy_text)
95-
96-
# 2: Create source files with value to insert in the .po
97-
file_1_path = File.join(dir, '1.txt')
98-
File.write(file_1_path, 'value 1')
99-
file_2_path = File.join(dir, '2.txt')
100-
File.write(file_2_path, 'value 2')
101-
102-
described_class.run(
103-
po_file_path: output_path,
104-
source_files: {
105-
key1: file_1_path,
106-
key2: file_2_path
107-
}
108-
)
109-
110-
expected = <<~PO
111-
msgctxt "key1"
112-
msgid "value 1"
113-
msgstr ""
114-
115-
msgctxt "key2"
116-
msgid "value 2"
117-
msgstr ""
118-
119-
PO
120-
expect(File.read(output_path)).to eq(expected)
121-
end
122-
end
5+
include_examples 'update_metadata_source_action', whats_new_fails: false
1236
end

0 commit comments

Comments
 (0)