|
13 | 13 | @config['default_lang'] = @default_lang |
14 | 14 | @config['exclude_from_localization'] = @exclude_from_localization |
15 | 15 | @parallel_localization = @config['parallel_localization'] || true |
16 | | - |
| 16 | + |
17 | 17 | @site = Site.new( |
18 | 18 | Jekyll.configuration( |
19 | 19 | 'languages' => @langs, |
|
46 | 46 | expect(@document_url_regex).to_not match 'properties/beachside/foo' |
47 | 47 | end |
48 | 48 | it 'expect relativized_urls should handle different output' do |
49 | | - expected = "expected" |
50 | | - collection = Jekyll::Collection.new(@site, "test") |
51 | | - document = Jekyll::Document.new("about.en.md", :site => @site, :collection => collection) |
| 49 | + expected = 'expected' |
| 50 | + collection_test = Jekyll::Collection.new(@site, 'test') |
| 51 | + document = Jekyll::Document.new('about.en.md', site: @site, collection: collection_test) |
52 | 52 | document.output = expected |
53 | 53 | @site.relativize_urls(document, @relative_url_regex) |
54 | 54 | expect(document.output).to eq(expected) |
|
163 | 163 | end |
164 | 164 | end |
165 | 165 |
|
| 166 | + describe @derive_lang_from_path do |
| 167 | + before(:each) do |
| 168 | + config = Jekyll.configuration( |
| 169 | + 'site' => @site, |
| 170 | + 'languages' => ['en', 'es', 'pt-br'], # fr not included |
| 171 | + 'default_lang' => @default_lang, |
| 172 | + 'exclude_from_localization' => @exclude_from_localization, |
| 173 | + 'source' => File.expand_path('fixtures', __dir__), |
| 174 | + 'lang_from_path' => true |
| 175 | + ) |
| 176 | + @site = Site.new(config) |
| 177 | + @site.prepare |
| 178 | + end |
| 179 | + it 'should derive lang from any part of the path' do |
| 180 | + collection_en = Jekyll::Collection.new(@site, 'en') |
| 181 | + collection_es = Jekyll::Collection.new(@site, 'es') |
| 182 | + collection_pt_br = Jekyll::Collection.new(@site, 'pt-br') |
| 183 | + collection_wrong = Jekyll::Collection.new(@site, 'wrong') |
| 184 | + specs = { |
| 185 | + 'en' => [ |
| 186 | + Jekyll::Document.new('about.en.md', site: @site, collection: collection_en), |
| 187 | + Jekyll::Document.new('fr/about.en.md', site: @site, collection: collection_en) |
| 188 | + ], |
| 189 | + 'es' => [ |
| 190 | + Jekyll::Document.new('pages/es/acercade.es.md', site: @site, collection: collection_es), |
| 191 | + Jekyll::Document.new('french-touch/restaurant/fr/es/acerade.md', site: @site, collection: collection_es) |
| 192 | + ], |
| 193 | + 'pt-br' => [ |
| 194 | + Jekyll::Document.new('about.pt-br.md', site: @site, collection: collection_pt_br), |
| 195 | + Jekyll::Document.new('international/restaurant/pt-br/sobre.md', site: @site, collection: collection_pt_br) |
| 196 | + ], |
| 197 | + nil => [ |
| 198 | + Jekyll::Document.new('apropos.fr.md', site: @site, collection: collection_wrong), # not included in languages |
| 199 | + Jekyll::Document.new('missing/pt-BR/sobre.md', site: @site, collection: collection_wrong), # wrong capitalization, |
| 200 | + Jekyll::Document.new('taken/blues/newspaper.md', site: @site, collection: collection_wrong), # no matches |
| 201 | + Jekyll::Document.new('es-en-pt-br/wordswordswords.html', site: @site, collection: collection_wrong) # wont split |
| 202 | + ] |
| 203 | + } |
| 204 | + specs.each do |lang, docs| |
| 205 | + docs.each do |document| |
| 206 | + expect(@site.lang_from_path).to eq(true) |
| 207 | + derived = @site.derive_lang_from_path document |
| 208 | + expect(derived).to match lang |
| 209 | + end |
| 210 | + end |
| 211 | + end |
| 212 | + end |
| 213 | + |
166 | 214 | describe @absolute_url_regex do |
167 | 215 | it 'must match absolute url' do |
168 | 216 | @urls.each do |url| |
|
246 | 294 |
|
247 | 295 | describe 'site prepare' do |
248 | 296 | it 'should copy active_lang to additional variables' do |
249 | | - @site.config['lang_vars'] = [ 'locale', 'язык' ] |
| 297 | + @site.config['lang_vars'] = ['locale', 'язык'] |
250 | 298 | @site.prepare |
251 | 299 | @langs.each do |lang| |
252 | 300 | @site.active_lang = lang |
|
260 | 308 | it 'should spawn no more than Etc.nprocessors processes' do |
261 | 309 | forks = 0 |
262 | 310 | allow(Etc).to receive(:nprocessors).and_return(2) |
263 | | - allow(@site).to receive(:fork) { forks += 1; fork { sleep 2 } } |
264 | | - thr = Thread.new { sleep 1; forks } |
| 311 | + allow(@site).to receive(:fork) { |
| 312 | + forks += 1 |
| 313 | + fork { sleep 2 } |
| 314 | + } |
| 315 | + thr = Thread.new { |
| 316 | + sleep 1 |
| 317 | + forks |
| 318 | + } |
265 | 319 | @site.process |
266 | 320 | expect(thr.value).to eq(Etc.nprocessors) |
267 | 321 | expect(forks).to eq((@langs + [@default_lang]).uniq.length) |
|
0 commit comments