Skip to content

Commit 9aa72ad

Browse files
committed
Improve Entry spec using example from SimplePoParser
1 parent cecd72c commit 9aa72ad

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.yardoc
66
.ruby-version
77
.gitignore
8+
.idea/
89
Gemfile.lock
910
InstalledFiles
1011
_yardoc

spec/poparser/entry_spec.rb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,30 @@
2626
it 'should show a hash presentation of an entry' do
2727
@entry.msgid = 'string'
2828
@entry.msgstr = 'reshte'
29-
@entry.translator_comment = ['comment', 'second line of comments']
30-
result = {
31-
:translator_comment => ['comment', 'second line of comments'],
32-
:msgid => 'string',
33-
:msgstr => 'reshte'
34-
}
35-
expect(@entry.to_h).to eq(result)
29+
expect(@entry.to_h).to eq({:msgid=>"string", :msgstr=>"reshte"})
3630
end
3731

38-
it 'should show a hash presentation of a plural string entry' do
39-
@entry = PoParser::Entry.new
40-
@entry.msgid_plural = 'right word'
41-
@entry.msgstr_0 = %w[mot juste]
42-
@entry.msgstr_1 = %w[mots justes]
43-
@entry.translator_comment = ['comment', 'second line of comments']
44-
45-
result = {
46-
:translator_comment => ['comment', 'second line of comments'],
47-
:msgid_plural => 'right word',
48-
:'msgstr[0]' => %w[mot juste],
49-
:'msgstr[1]' => %w[mots justes]
32+
it 'should show a hash representation of a complex entry' do
33+
# Ensure the to_h method is reversible
34+
# From SimplePoParser::Parser - https://github.com/experteer/simple_po_parser/blob/v1.1.5/spec/simple_po_parser/parser_spec.rb#L31
35+
entry_hash = {
36+
:translator_comment => ["translator-comment", ""],
37+
:extracted_comment => "extract",
38+
:reference => ["reference1", "reference2"],
39+
:flag => "flag",
40+
:previous_msgctxt => "previous context",
41+
:previous_msgid => ["", "multiline\\n", "previous messageid"],
42+
:previous_msgid_plural => "previous msgid_plural",
43+
:msgctxt => "Context",
44+
:msgid => "msgid",
45+
:msgid_plural => ["", "multiline msgid_plural\\n", ""],
46+
"msgstr[0]" => "msgstr 0",
47+
"msgstr[1]" => ["", "msgstr 1 multiline 1\\n", "msgstr 1 line 2\\n"],
48+
"msgstr[2]" => "msgstr 2"
5049
}
51-
expect(@entry.to_h).to eq(result)
50+
51+
entry = PoParser::Entry.new(entry_hash)
52+
expect(entry.to_h).to eq(entry_hash)
5253
end
5354

5455
it 'should translate the entry' do

0 commit comments

Comments
 (0)