bisu 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,76 +0,0 @@
1
- describe Bisu::Dictionary do
2
- subject(:dict) { Bisu::Dictionary.new(keys) }
3
-
4
- describe ".initialize" do
5
- let(:keys) { { "lang" => { "kNo1" => "text" } } }
6
- it { expect { subject }.not_to raise_error }
7
-
8
- context "when created with invalid type parameters" do
9
- let(:keys) { "cenas" }
10
- it { expect { subject }.to raise_error /expected Hash/ }
11
- end
12
-
13
- context "when created with an invalid json schema" do
14
- let(:keys) { { "lang" => "text" } }
15
- it { expect { subject }.to raise_error /lang.+expected Hash/ }
16
- end
17
-
18
- context "when created with an invalid json schema" do
19
- let(:keys) { { "a-lang" => { "kNo1" => { "wtvr" => "text" } } } }
20
- it { expect { subject }.to raise_error /a-lang.+kNo1.+expected String/ }
21
- end
22
-
23
- context "when given empty translations" do
24
- let(:keys) { { "lang" => { "kNo1" => nil } } }
25
- it { expect { subject }.not_to raise_error }
26
- end
27
- end
28
-
29
- describe "#has_language?" do
30
- let(:keys) { {
31
- "lang1" => { "kNo1" => "no1-lang1" },
32
- "lang2" => { "kNo1" => "no1-lang2", "kNo2" => "no1-lang2" },
33
- "lang3" => { "kNo2" => "no2-lang3" }
34
- } }
35
-
36
- it "returns true if that language is translated" do
37
- expect(dict.has_language?("lang2")).to be true
38
- end
39
-
40
- it "returns true if that language is only partially translated" do
41
- expect(dict.has_language?("lang3")).to be true
42
- end
43
-
44
- it "returns false if that language does not exist in any key" do
45
- expect(dict.has_language?("lang-no-available")).to be false
46
- end
47
-
48
- it "returns true if that language is in another case" do
49
- expect(dict.has_language?("Lang2")).to be true
50
- end
51
- end
52
-
53
- describe "#localize" do
54
- let(:keys) { {
55
- "english" => { "kCray" => "You are crazy!" },
56
- "portuguese" => { "kCray" => "Estás maluco!" },
57
- "kriolo" => { "kCray" => "Bo sta crazy!" }
58
- } }
59
-
60
- it "localizes a key" do
61
- expect(dict.localize("kriolo", "kCray")).to eq "Bo sta crazy!"
62
- end
63
-
64
- it "returns nil when the key does not exist" do
65
- expect(dict.localize("kriolo", "kDoesntExist")).to be nil
66
- end
67
-
68
- it "returns nil when language is not available" do
69
- expect(dict.localize("finish", "kCray")).to be nil
70
- end
71
-
72
- it "localizes a key when the language is in another case" do
73
- expect(dict.localize("krioLo", "kCray")).to eq "Bo sta crazy!"
74
- end
75
- end
76
- end
@@ -1,212 +0,0 @@
1
- describe Bisu::Localizer do
2
- def translates(text, fallbacks: [], to:, lang: nil)
3
- translation = localizer.localize(text, lang || language, locale, fallbacks)
4
- expect(translation).to eq to
5
- end
6
-
7
- let(:language) { "Portuguese" }
8
- let(:locale) { "pt-PT" }
9
-
10
- let(:keys) { {
11
- language => {
12
- "kTranslationKey" => "Não sabes nada João das Neves",
13
- "kTranslationKey2" => "Naaada!",
14
- "k1ParameterKey" => "Não sabes nada %{name}",
15
- "k2ParametersKey" => "Sabes %{perc} por cento %{name}",
16
- "kNewLineSingle" => "Não sabes nada\nJoão das Neves",
17
- "kNewLineMultiple" => "Não sabes nada\\nJoão das Neves",
18
-
19
- # type dependent translations
20
- "kDoubleQuoted" => "Não sabes nada \"João das Neves\"",
21
- "kSingleQuoted" => "Não sabes nada 'João das Neves'",
22
- "kEllipsis" => "Não sabes nada João das Neves...",
23
- "kAmpersand" => "Não sabes nada João das Neves T&C",
24
- "kAtSign" => "\@johnsnow sabes alguma coisa?",
25
- "kPercentage" => "Sabes 0% João das Neves."
26
- },
27
- "Spanish" => {
28
- "kMissingTransKey" => "Sabes poco John Snow"
29
- },
30
- "English" => {
31
- "kMissingTransKey" => "You know little John Snow"
32
- }
33
- } }
34
-
35
- let(:kb) { Bisu::Dictionary.new(keys) }
36
- let(:localizer) { Bisu::Localizer.new(kb, type) }
37
-
38
- shared_examples_for "a localizer" do
39
- it { expect { localizer }.not_to raise_error }
40
-
41
- it { translates("a line with no key", to: "a line with no key") }
42
-
43
- it { translates("this special key: $specialKComment1$", to: "this special key: This file was automatically generated based on a translation template.") }
44
- it { translates("this special key: $specialKComment2$", to: "this special key: Remember to CHANGE THE TEMPLATE and not this file!") }
45
- it { translates("this special key: $specialKLanguage$", to: "this special key: #{language}") }
46
- it { translates("this special key: $specialKLocale$", to: "this special key: #{locale}") }
47
-
48
- it { translates("this key: $kTranslationKey$", to: "this key: Não sabes nada João das Neves") }
49
- it { translates("this key: $kTranslationKey$", to: "this key: Não sabes nada João das Neves", lang: "portuguese") }
50
- it { translates("this unknown key: $kUnknownKey$", to: "this unknown key: $kUnknownKey$") }
51
- it { translates("this key with missing translations: $kMissingTransKey$", to: "this key with missing translations: $kMissingTransKey$") }
52
- it { translates("this key with missing translations: $kMissingTransKey$", fallbacks: ["English"], to: "this key with missing translations: You know little John Snow") }
53
- it { translates("this key with missing translations: $kMissingTransKey$", fallbacks: ["Spanish", "English"], to: "this key with missing translations: Sabes poco John Snow") }
54
- it { translates("these 2 keys: $kTranslationKey$, $kTranslationKey2$", to: "these 2 keys: Não sabes nada João das Neves, Naaada!") }
55
-
56
- it { translates("1 parameter: $k1ParameterKey$", to: "1 parameter: Não sabes nada %{name}") }
57
- it { translates("1 parameter: $k1ParameterKey{name:%1$s}$", to: "1 parameter: Não sabes nada %1$s") }
58
- it { translates("2 parameters: $k2ParametersKey$", to: "2 parameters: Sabes %{perc} por cento %{name}") }
59
- it { translates("2 parameters: $k2ParametersKey{perc:%2$d, name:%1$s}$", to: "2 parameters: Sabes %2$d por cento %1$s") }
60
- it { translates("2 parameters: $k2ParametersKey{name:%1$s, perc:%2$d}$", to: "2 parameters: Sabes %2$d por cento %1$s") }
61
-
62
- it { translates("$kNewLineSingle$", to: "Não sabes nada\\nJoão das Neves") }
63
- it { translates("$kNewLineMultiple$", to: "Não sabes nada\\nJoão das Neves") }
64
-
65
- # type dependent translations
66
-
67
- it { translates("$kDoubleQuoted$", to: expected[:double_quoted]) }
68
- it { translates("$kSingleQuoted$", to: expected[:single_quoted]) }
69
- it { translates("$kEllipsis$", to: expected[:ellipsis]) }
70
- it { translates("$kAmpersand$", to: expected[:ampersand]) }
71
- it { translates("$kAtSign$", to: expected[:at_sign]) }
72
- it { translates("$kPercentage$", to: expected[:percentage]) }
73
- it { translates("$kPercentage//formatted-string$", to: expected[:percentage_formatted]) }
74
-
75
- # error handling
76
-
77
- it "throws a warnings when key has no translation" do
78
- expect {
79
- localizer.localize("$kUnknownKey$", language, locale)
80
- }.to change { Bisu::Logger.summary[:warn] }.by(1)
81
- .and not_change { Bisu::Logger.summary[:error] }
82
- end
83
-
84
- it "does not throw a warning when key is found" do
85
- expect {
86
- localizer.localize("$kTranslationKey$", language, locale)
87
- }.to not_change { Bisu::Logger.summary[:warn] }
88
- .and not_change { Bisu::Logger.summary[:error] }
89
- end
90
-
91
- it "throws a error when missing key parameters (expect on ruby on rails)" do
92
- if type == :ror
93
- expect {
94
- localizer.localize("$k1ParameterKey$", language, locale)
95
- }.to not_change { Bisu::Logger.summary[:warn] }
96
- .and not_change { Bisu::Logger.summary[:error] }
97
- else
98
- expect {
99
- localizer.localize("$k1ParameterKey$", language, locale)
100
- }.to not_change { Bisu::Logger.summary[:warn] }
101
- .and change { Bisu::Logger.summary[:error] }.by(1)
102
- end
103
- end
104
-
105
- it "does not throw an error when key parameters where given" do
106
- expect {
107
- localizer.localize("$k1ParameterKey{name:%1$s}$", language, locale)
108
- }.to not_change { Bisu::Logger.summary[:warn] }
109
- .and not_change { Bisu::Logger.summary[:error] }
110
- end
111
-
112
- it "throws an error when given parameters for parameterless key" do
113
- expect {
114
- localizer.localize("$kTranslationKey{param:%s}$", language, locale)
115
- }.to not_change { Bisu::Logger.summary[:warn] }
116
- .and change { Bisu::Logger.summary[:error] }.by(1)
117
- end
118
-
119
- # non localizable text with params
120
-
121
- it "does not try to translate params outside $$" do
122
- translates("%{some_text}", to: "%{some_text}")
123
-
124
- expect {
125
- localizer.localize("%{some_text}", language, locale)
126
- }.to not_change { Bisu::Logger.summary[:warn] }
127
- .and not_change { Bisu::Logger.summary[:error] }
128
- end
129
- end
130
-
131
- let(:type_dependent_defaults) { {
132
- double_quoted: keys[language]["kDoubleQuoted"],
133
- single_quoted: keys[language]["kSingleQuoted"],
134
- ellipsis: keys[language]["kEllipsis"],
135
- ampersand: keys[language]["kAmpersand"],
136
- at_sign: keys[language]["kAtSign"],
137
- percentage: keys[language]["kPercentage"],
138
- percentage_formatted: keys[language]["kPercentage"],
139
- } }
140
-
141
- describe "of type iOS" do
142
- let(:type) { :ios }
143
-
144
- let(:expected) { type_dependent_defaults.merge(
145
- double_quoted: "Não sabes nada \\\"João das Neves\\\"",
146
- percentage: "Sabes 0% João das Neves.",
147
- percentage_formatted: "Sabes 0%% João das Neves.",
148
- ) }
149
-
150
- it_behaves_like "a localizer"
151
-
152
- context "when a parameter replacemnt was not defined" do
153
- let(:line) { "1 parameter: $k1ParameterKey$" }
154
- let(:expected) { "1 parameter: Não sabes nada %{name}" }
155
-
156
- it { translates(line, to: expected) }
157
-
158
- it "returns an error" do
159
- expect {
160
- localizer.localize(line, language, locale)
161
- }.to not_change { Bisu::Logger.summary[:warn] }
162
- .and change { Bisu::Logger.summary[:error] }.by(1)
163
- end
164
-
165
- context "when passing //ignore-params" do
166
- let(:line) { "1 parameter: $k1ParameterKey//ignore-params$" }
167
-
168
- it { translates(line, to: expected) }
169
-
170
- it "does not return an error" do
171
- expect {
172
- localizer.localize(line, language, locale)
173
- }.to not_change { Bisu::Logger.summary[:warn] }
174
- .and not_change { Bisu::Logger.summary[:error] }
175
- end
176
- end
177
- end
178
- end
179
-
180
- describe "of type Android" do
181
- let(:type) { :android }
182
-
183
- let(:expected) { type_dependent_defaults.merge(
184
- single_quoted: "Não sabes nada \\'João das Neves\\'",
185
- double_quoted: "Não sabes nada \\\"João das Neves\\\"",
186
- ellipsis: "Não sabes nada João das Neves…",
187
- ampersand: "Não sabes nada João das Neves T&C",
188
- at_sign: "\\@johnsnow sabes alguma coisa?",
189
- percentage: "Sabes 0\\%% João das Neves.",
190
- percentage_formatted: "Sabes 0\\%% João das Neves.",
191
- ) }
192
-
193
- it_behaves_like "a localizer"
194
- end
195
-
196
- describe "of type Ruby on Rails" do
197
- let(:type) { :ror }
198
-
199
- let(:expected) { type_dependent_defaults.merge(
200
- double_quoted: "Não sabes nada \\\"João das Neves\\\"",
201
- ) }
202
-
203
- it_behaves_like "a localizer"
204
- end
205
-
206
- describe "of an unkown type" do
207
- let(:type) { :dunno }
208
- it do
209
- expect { localizer }.to raise_error /Unknown type/
210
- end
211
- end
212
- end
@@ -1,36 +0,0 @@
1
- describe Bisu::Logger do
2
- let(:summary) { Bisu::Logger.summary }
3
- let(:info) { summary[:info] }
4
- let(:warn) { summary[:warn] }
5
- let(:error) { summary[:error] }
6
-
7
- context "when logging to info" do
8
- before { Bisu::Logger.info "msg" }
9
-
10
- it "returns the expected totals" do
11
- expect(info).to eq 1
12
- expect(warn).to eq 0
13
- expect(error).to eq 0
14
- end
15
- end
16
-
17
- context "when logging to warn" do
18
- before { Bisu::Logger.warn "msg" }
19
-
20
- it "returns the expected totals" do
21
- expect(info).to eq 0
22
- expect(warn).to eq 1
23
- expect(error).to eq 0
24
- end
25
- end
26
-
27
- context "when logging to error" do
28
- before { Bisu::Logger.error "msg" }
29
-
30
- it "returns the expected totals" do
31
- expect(info).to eq 0
32
- expect(warn).to eq 0
33
- expect(error).to eq 1
34
- end
35
- end
36
- end
@@ -1,100 +0,0 @@
1
- describe Object do
2
-
3
- describe "#deep_symbolize" do
4
- subject { obj.deep_symbolize }
5
-
6
- context "when object is an Hash" do
7
- let(:obj) { { "key1" => "value1", key2: "value2" } }
8
- it { should eq({ key1: "value1", key2: "value2" }) }
9
-
10
- context "with inner Hashes" do
11
- before { obj["key2"] = { "key3" => { "key4" => "value4" } } }
12
- it { should eq({ key1: "value1", key2: { key3: { key4: "value4" } }}) }
13
- end
14
- end
15
-
16
- context "when object is an Array" do
17
- let(:obj) { ["value1"] }
18
- it { should eq obj }
19
-
20
- context "with inner Hashes" do
21
- let(:obj) { [{ "key1" => "value1" }, { "key2" => "value2" }] }
22
- it { should eq([{ key1: "value1" }, { key2: "value2" }]) }
23
- end
24
- end
25
-
26
- context "when object is something else" do
27
- let(:obj) { "value1" }
28
- it { should eq obj }
29
- end
30
- end
31
-
32
- describe "#validate_structure!" do
33
- subject { obj.validate_structure!(structure) }
34
-
35
- context "when object type differs of the structure type" do
36
- let(:obj) { "a string" }
37
- let(:structure) { { type: Integer } }
38
- it { expect { subject }.to raise_error /expected Integer, got String/i }
39
- end
40
-
41
- context "when object is a Nil" do
42
- let(:obj) { nil }
43
- let(:structure) { { type: Integer } }
44
- it { expect { subject }.to raise_error /expected Integer, got NilClass/i }
45
-
46
- context "but is also optional" do
47
- before { structure[:optional] = true }
48
- it { expect { subject }.not_to raise_error }
49
- end
50
- end
51
-
52
- context "when object is an Array" do
53
- let(:obj) { ["elem1", "elem2"] }
54
- let(:structure) { { type: Array } }
55
- it { expect { subject }.not_to raise_error }
56
-
57
- context "given an element structure" do
58
- before { structure[:elements] = { type: String } }
59
- it { expect { subject }.not_to raise_error }
60
-
61
- context "which is not respected" do
62
- before { structure[:elements] = { type: Integer } }
63
- it { expect { subject }.to raise_error /expected Integer, got String/i }
64
- end
65
- end
66
- end
67
-
68
- context "when object is an Hash" do
69
- let(:obj) { { key1: "value1", key2: "value2", key3: "value3" } }
70
- let(:structure) { { type: Hash } }
71
- it { expect { subject }.not_to raise_error }
72
-
73
- context "when given an element structure" do
74
- let(:structure) { { type: Hash, elements: { key1: { type: String }, key2: { type: String }, key3: { type: String } } } }
75
- it { expect { subject }.not_to raise_error }
76
-
77
- context "which is not respected" do
78
- before { obj[:key2] = {} }
79
- it { expect { subject }.to raise_error /expected String, got Hash/i }
80
- end
81
-
82
- context "when missing keys" do
83
- before do
84
- obj.delete(:key1)
85
- obj.delete(:key3)
86
- end
87
- it { expect { subject }.to raise_error /missing keys: key1, key3/i }
88
-
89
- context "which are optional" do
90
- before do
91
- structure[:elements][:key1][:optional] = true
92
- structure[:elements][:key3][:optional] = true
93
- end
94
- it { expect { subject }.not_to raise_error }
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
@@ -1,43 +0,0 @@
1
- describe Bisu::Source::GoogleSheet do
2
- subject(:to_i18) { Bisu::Source::GoogleSheet.new(url, "key name").to_i18 }
3
-
4
- let(:url) { "https://docs.google.com/spreadsheets/d/e/2PACX-1vTm6yu_zfbxKizC-PvUE1HVFCsplmiyz0s0qLSIGeokA7KtS3BgtqaA79CsfYfPsXH6xzUaP8HDTcj8/pub?gid=0&single=true&output=csv" }
5
- let(:response) { File.read("spec/fixtures/sample_google_response.csv") }
6
-
7
- def stub_url(status:, response:)
8
- stub_request(:get, url).
9
- to_return(:status => status, :body => response, :headers => {})
10
- end
11
-
12
- before { stub_url(status: 200, response: response) }
13
-
14
- it do
15
- expect { to_i18 }.not_to raise_error
16
- end
17
-
18
- it "returns an hash in i18 format" do
19
- expect(to_i18).to eq({
20
- "en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
21
- "ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
22
- "fr" => { "kConnectFacebook" => "Connexion par Facebook" },
23
- "de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
24
- "ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
25
- })
26
- end
27
-
28
- context "when given an inexistent sheet" do
29
- before { stub_url(status: 400, response: "Not Found") }
30
-
31
- it do
32
- expect { to_i18 }.to raise_error /Http Error/
33
- end
34
- end
35
-
36
- context "when url content is not CSV" do
37
- before { stub_url(status: 200, response: "{\"asdsa\": \"This is a json\"}") }
38
-
39
- it do
40
- expect { to_i18 }.to raise_error /Cannot parse. Expected CSV/
41
- end
42
- end
43
- end
@@ -1,53 +0,0 @@
1
- describe Bisu::Source::OneSky do
2
- subject(:to_i18) { Bisu::Source::OneSky.new(api_key, api_secret, project_id, file_name).to_i18 }
3
-
4
- let(:api_key) { "a123" }
5
- let(:api_secret) { "b123" }
6
- let(:project_id) { 98765 }
7
- let(:file_name) { "file456.json" }
8
-
9
- let(:os_response) { File.read("spec/fixtures/sample_one_sky_response.json") }
10
-
11
- def stub_multilingual(status:, response:)
12
- stub_request(:get, "https://platform.api.onesky.io/1/projects/#{project_id}/translations/multilingual").
13
- with(query: hash_including(api_key: api_key, file_format: "I18NEXT_MULTILINGUAL_JSON", source_file_name: file_name)).
14
- to_return(:status => status, :body => response, :headers => {})
15
- end
16
-
17
- before { stub_multilingual(status: 200, response: os_response) }
18
-
19
- it { expect { to_i18 }.not_to raise_error }
20
-
21
- it "returns an hash in i18 format" do
22
- expect(to_i18).to eq({
23
- "en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
24
- "ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
25
- "fr" => { "kConnectFacebook" => "Connexion par Facebook" },
26
- "de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
27
- "ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
28
- })
29
- end
30
-
31
- context "when OneSky raises an error" do
32
- before { stub_multilingual(status: 400, response: { error: "ups... not allowed!" }.to_json) }
33
-
34
- it "raises that same error" do
35
- expect { to_i18 }.to raise_error /not allowed/
36
- end
37
- end
38
-
39
- context "when OneSky returns the newline bug" do
40
- let(:os_response) { File.read("spec/fixtures/sample_one_sky_response_with_bug.json") }
41
-
42
- it { expect { to_i18 }.not_to raise_error }
43
-
44
- it "returns an hash in i18 format with the newline bug fixed" do
45
- expect(to_i18).to eq({
46
- "en" => {
47
- "kRegularNewLine" => "This is the first line\\nthis is the second line",
48
- "kErrorNewLine" => "This is the first line\\nthis is the second line"
49
- }
50
- })
51
- end
52
- end
53
- end
@@ -1,45 +0,0 @@
1
- describe Bisu::Source::Tolgee do
2
- subject(:to_i18) { Bisu::Source::Tolgee.new(api_key).to_i18 }
3
-
4
- let(:api_key) { "a123" }
5
- let(:os_response) { File.read("spec/fixtures/sample_tolgee_response.zip") }
6
-
7
- def stub_url(status:, response:, host: "app.tolgee.io")
8
- stub_request(:get, "https://#{host}/v2/projects/export?format=JSON&structureDelimiter=").
9
- to_return(:status => status, :body => response, :headers => {})
10
- end
11
-
12
- before { stub_url(status: 200, response: os_response) }
13
-
14
- it { expect { to_i18 }.not_to raise_error }
15
-
16
- it "returns an hash in i18 format" do
17
- expect(to_i18).to eq({
18
- "en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
19
- "ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
20
- "fr" => { "kConnectFacebook" => "Connexion par Facebook" },
21
- "de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
22
- "ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
23
- })
24
- end
25
-
26
- context "when get request to that URL raises an error" do
27
- before { stub_url(status: 400, response: { error: "ups... not allowed!" }.to_json) }
28
-
29
- it "raises that same error" do
30
- expect { to_i18 }.to raise_error /not allowed/
31
- end
32
- end
33
-
34
- context "with a custom host" do
35
- let(:host) { "translations.example.com" }
36
- subject(:to_i18) { Bisu::Source::Tolgee.new(api_key, host).to_i18 }
37
-
38
- before { stub_url(status: 200, response: os_response, host: host) }
39
-
40
- it "uses that host" do
41
- to_i18
42
- expect(WebMock).to have_requested(:get, "https://translations.example.com/v2/projects/export?format=JSON&structureDelimiter=")
43
- end
44
- end
45
- end
@@ -1,33 +0,0 @@
1
- describe Bisu::Source::Url do
2
- subject(:to_i18) { Bisu::Source::Url.new(url).to_i18 }
3
-
4
- let(:url) { "https://in17n-08c12b370aeb6c66.herokuapp.com/documents/1/json?api_key=0320cd5d-1a51-4785-a832-a5bed8e62ed6" }
5
- let(:os_response) { File.read("spec/fixtures/sample_json_response.json") }
6
-
7
- def stub_url(status:, response:)
8
- stub_request(:get, url).
9
- to_return(:status => status, :body => response, :headers => {})
10
- end
11
-
12
- before { stub_url(status: 200, response: os_response) }
13
-
14
- it { expect { to_i18 }.not_to raise_error }
15
-
16
- it "returns an hash in i18 format" do
17
- expect(to_i18).to eq({
18
- "en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
19
- "ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
20
- "fr" => { "kConnectFacebook" => "Connexion par Facebook" },
21
- "de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
22
- "ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
23
- })
24
- end
25
-
26
- context "when get request to that URL raises an error" do
27
- before { stub_url(status: 400, response: { error: "ups... not allowed!" }.to_json) }
28
-
29
- it "raises that same error" do
30
- expect { to_i18 }.to raise_error /not allowed/
31
- end
32
- end
33
- end
@@ -1,36 +0,0 @@
1
- describe Bisu do
2
- subject(:run) { Bisu.run([]) }
3
-
4
- context "when there is a translatable.yml" do
5
- let(:file) { File.open("spec/fixtures/sample.translatable.yml") }
6
-
7
- before do
8
- allow(Bisu).to receive(:open_file).and_return(file)
9
- allow_any_instance_of(Bisu::Source::GoogleSheet).to receive(:to_i18).and_return({
10
- "english" => { "kKey" => "Value" },
11
- "english-us" => { "kKey" => "Value" }
12
- })
13
- allow(Bisu).to receive(:localize_file)
14
- end
15
-
16
- it { expect { run }.not_to raise_error }
17
-
18
- it "logs an error" do
19
- expect {
20
- run
21
- }.to not_change { Bisu::Logger.summary[:warn] }
22
- .and not_change { Bisu::Logger.summary[:error] }
23
- end
24
- end
25
-
26
- context "when translatable.yml does not exist locally" do
27
- it { expect { run }.not_to raise_error }
28
-
29
- it "logs an error" do
30
- expect {
31
- run
32
- }.to not_change { Bisu::Logger.summary[:warn] }
33
- .and change { Bisu::Logger.summary[:error] }.by(1)
34
- end
35
- end
36
- end