-
-
Notifications
You must be signed in to change notification settings - Fork 192
/
links_spec.rb
629 lines (525 loc) · 24.2 KB
/
links_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# frozen_string_literal: true
require 'spec_helper'
describe 'Links test' do
it 'fails for broken internal hash (even if the file exists)' do
broken_hash_external_filepath = "#{FIXTURES_DIR}/links/broken_hash_external.html"
proofer = run_proofer(broken_hash_external_filepath, :file)
expect(proofer.failed_tests.last).to match(%r{linking to ../images/missing_image_alt.html#asdfasfdkafl, but asdfasfdkafl does not exist})
end
it 'fails for broken hashes on the web when asked (even if the file exists)' do
broken_hash_on_the_web = "#{FIXTURES_DIR}/links/broken_hash_on_the_web.html"
proofer = run_proofer(broken_hash_on_the_web, :file, check_external_hash: true)
expect(proofer.failed_tests.first).to match(/but the hash 'no' does not/)
end
it 'passes for broken hashes on the web when ignored (even if the file exists)' do
broken_hash_on_the_web = "#{FIXTURES_DIR}/links/broken_hash_on_the_web.html"
proofer = run_proofer(broken_hash_on_the_web, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes for GitHub hashes on the web when asked' do
github_hash = "#{FIXTURES_DIR}/links/github_hash.html"
proofer = run_proofer(github_hash, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes for GitHub hashes to a file on the web when asked' do
github_hash = "#{FIXTURES_DIR}/links/github_file_hash.html"
proofer = run_proofer(github_hash, :file, {check_external_hash: true})
expect(proofer.failed_tests).to eq []
end
it 'passes for broken hashes on the web (when we look only for 4xx)' do
options = { only_4xx: true }
broken_hash_on_the_web = "#{FIXTURES_DIR}/links/broken_hash_on_the_web.html"
proofer = run_proofer(broken_hash_on_the_web, :file, options)
expect(proofer.failed_tests).to eq []
end
it 'fails for broken internal hash' do
broken_hash_internal_filepath = "#{FIXTURES_DIR}/links/broken_hash_internal.html"
proofer = run_proofer(broken_hash_internal_filepath, :file)
expect(proofer.failed_tests.first).to match(/linking to internal hash #noHash that does not exist/)
end
it 'passes when linking to the top' do
path = "#{FIXTURES_DIR}/links/topHashInternal.html"
proofer = run_proofer(path, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for broken external links' do
broken_link_external_filepath = "#{FIXTURES_DIR}/links/broken_link_external.html"
proofer = run_proofer(broken_link_external_filepath, :file)
failure = proofer.failed_tests.first
expect(failure).to match(/failed: response code 0/)
expect(failure).to match(%r{External link http://www.asdo3IRJ395295jsingrkrg4.com/ failed:})
end
it 'passes for different filename without option' do
broken_link_external_filepath = "#{FIXTURES_DIR}/links/file.foo"
proofer = run_proofer(broken_link_external_filepath, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for different filenames' do
options = { extension: '.foo' }
broken_link_external_filepath = "#{FIXTURES_DIR}/links/file.foo"
proofer = run_proofer(broken_link_external_filepath, :file, options)
expect(proofer.failed_tests.first).to match(/failed: response code 0/)
end
it 'fails for broken internal links' do
broken_link_internal_filepath = "#{FIXTURES_DIR}/links/broken_link_internal.html"
proofer = run_proofer(broken_link_internal_filepath, :file)
expect(proofer.failed_tests.first).to match(%r{internally linking to .\/notreal.html, which does not exist})
end
it 'succeeds for working internal-root-links pointing to other folder' do
broken_root_link_internal_filepath = "#{FIXTURES_DIR}/links/working_root_link_internal.html"
proofer = run_proofer(broken_root_link_internal_filepath, :file, root_dir: 'spec/html-proofer/fixtures')
expect(proofer.failed_tests).to eq []
end
it 'fails for link with no href' do
missing_link_href_filepath = "#{FIXTURES_DIR}/links/missing_link_href.html"
proofer = run_proofer(missing_link_href_filepath, :file)
expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
end
it 'should follow redirects' do
link_with_redirect_filepath = "#{FIXTURES_DIR}/links/link_with_redirect.html"
proofer = run_proofer(link_with_redirect_filepath, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails on redirects if not following' do
link_with_redirect_filepath = "#{FIXTURES_DIR}/links/link_with_redirect.html"
proofer = run_proofer(link_with_redirect_filepath, :file, typhoeus: { followlocation: false })
expect(proofer.failed_tests.first).to match(/failed: 301/)
end
it "does not fail on redirects we're not following" do
# this test should emit a 301--see above--but we're intentionally suppressing it
link_with_redirect_filepath = "#{FIXTURES_DIR}/links/link_with_redirect.html"
proofer = run_proofer(link_with_redirect_filepath, :file, only_4xx: true, typhoeus: { followlocation: false })
expect(proofer.failed_tests).to eq []
end
it 'should understand https' do
link_with_https_filepath = "#{FIXTURES_DIR}/links/link_with_https.html"
proofer = run_proofer(link_with_https_filepath, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for broken hash links with status code numbers' do
broken_link_with_number_filepath = "#{FIXTURES_DIR}/links/broken_link_with_number.html"
proofer = run_proofer(broken_link_with_number_filepath, :file)
expect(proofer.failed_tests.first).to match(/linking to internal hash #25-method-not-allowed that does not exist/)
end
it 'properly resolves implicit /index.html in link paths' do
link_to_folder = "#{FIXTURES_DIR}/links/link_to_folder.html"
proofer = run_proofer(link_to_folder, :file)
expect(proofer.failed_tests).to eq []
end
it 'properly checks links to root' do
root_link = "#{FIXTURES_DIR}/links/root_link/root_link.html"
proofer = run_proofer(root_link, :file)
expect(proofer.failed_tests).to eq []
end
it 'properly checks relative links' do
relative_links = "#{FIXTURES_DIR}/links/relative_links.html"
proofer = run_proofer(relative_links, :file)
expect(proofer.failed_tests).to eq []
end
it 'properly checks ssl links' do
check_ssl_links = "#{FIXTURES_DIR}/links/checkSSLLinks.html"
proofer = run_proofer(check_ssl_links, :file)
expect(proofer.failed_tests).to eq []
end
it 'ignores links marked as ignore data-proofer-ignore' do
ignorable_links = "#{FIXTURES_DIR}/links/ignorable_links.html"
proofer = run_proofer(ignorable_links, :file)
expect(proofer.failed_tests).to eq []
end
it 'ignores links via url_ignore' do
ignorable_links = "#{FIXTURES_DIR}/links/ignorable_links_via_options.html"
proofer = run_proofer(ignorable_links, :file, url_ignore: [%r{^http://}, /sdadsad/, '../whaadadt.html'])
expect(proofer.failed_tests).to eq []
end
it 'translates links via url_swap' do
translated_link = "#{FIXTURES_DIR}/links/link_translated_via_href_swap.html"
proofer = run_proofer(translated_link, :file, url_swap: { %r{\A/articles/([\w-]+)} => '\\1.html' })
expect(proofer.failed_tests).to eq []
end
it 'translates links via url_swap for list of links' do
proofer = run_proofer(['www.garbalarba.com'], :links, url_swap: { /garbalarba/ => 'github' })
expect(proofer.failed_tests).to eq []
end
it 'finds a mix of broken and unbroken links' do
multiple_problems = "#{FIXTURES_DIR}/links/multiple_problems.html"
proofer = run_proofer(multiple_problems, :file)
expect(proofer.failed_tests.first).to match(/linking to internal hash #anadaasdadsadschor that does not exist/)
end
it 'ignores valid mailto links' do
ignorable_links = "#{FIXTURES_DIR}/links/mailto_link.html"
proofer = run_proofer(ignorable_links, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for blank mailto links' do
blank_mail_to_link = "#{FIXTURES_DIR}/links/blank_mailto_link.html"
proofer = run_proofer(blank_mail_to_link, :file)
expect(proofer.failed_tests.first).to match(/mailto: contains no email address/)
end
it 'fails for invalid mailto links' do
invalid_mail_to_link = "#{FIXTURES_DIR}/links/invalid_mailto_link.html"
proofer = run_proofer(invalid_mail_to_link, :file)
expect(proofer.failed_tests.first).to match(/mailto:octocat contains an invalid email address/)
end
it 'ignores valid tel links' do
ignorable_links = "#{FIXTURES_DIR}/links/tel_link.html"
proofer = run_proofer(ignorable_links, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for blank tel links' do
blank_tel_link = "#{FIXTURES_DIR}/links/blank_tel_link.html"
proofer = run_proofer(blank_tel_link, :file)
expect(proofer.failed_tests.first).to match(/tel: contains no phone number/)
end
it 'ignores javascript links' do
javascript_link = "#{FIXTURES_DIR}/links/javascript_link.html"
proofer = run_proofer(javascript_link, :file)
expect(proofer.failed_tests).to eq []
end
it 'works for valid links missing the protocol' do
missing_protocol_link = "#{FIXTURES_DIR}/links/link_missing_protocol_valid.html"
proofer = run_proofer(missing_protocol_link, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for invalid links missing the protocol' do
missing_protocol_link = "#{FIXTURES_DIR}/links/link_missing_protocol_invalid.html"
proofer = run_proofer(missing_protocol_link, :file)
expect(proofer.failed_tests.first).to match(/failed: response code 0/)
end
it 'works for valid href within link elements' do
head_link = "#{FIXTURES_DIR}/links/head_link_href.html"
proofer = run_proofer(head_link, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for empty href within link elements' do
head_link = "#{FIXTURES_DIR}/links/head_link_href_empty.html"
proofer = run_proofer(head_link, :file)
expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
end
it 'fails for absent href within link elements' do
head_link = "#{FIXTURES_DIR}/links/head_link_href_absent.html"
proofer = run_proofer(head_link, :file)
expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
end
it 'fails for internal linking to a directory without trailing slash' do
options = { typhoeus: { followlocation: false } }
internal = "#{FIXTURES_DIR}/links/link_directory_without_slash.html"
proofer = run_proofer(internal, :file, options)
expect(proofer.failed_tests.first).to match(/without trailing slash/)
end
it 'ignores external links when asked' do
options = { disable_external: true }
external = "#{FIXTURES_DIR}/links/broken_link_external.html"
proofer = run_proofer(external, :file, options)
expect(proofer.failed_tests).to eq []
end
it 'validates links with external characters' do
options = { disable_external: true }
external = "#{FIXTURES_DIR}/links/external_colon_link.html"
proofer = run_proofer(external, :file, options)
expect(proofer.failed_tests).to eq []
end
it 'works for array of links' do
proofer = run_proofer(['www.github.com', 'foofoofoo.biz'], :links)
expect(proofer.failed_tests.first).to match(/failed: response code 0/)
end
it 'works for broken anchors within pre' do
anchor_pre = "#{FIXTURES_DIR}/links/anchors_in_pre.html"
proofer = run_proofer(anchor_pre, :file)
expect(proofer.failed_tests).to eq []
end
it 'works for broken link within pre' do
link_pre = "#{FIXTURES_DIR}/links/links_in_pre.html"
proofer = run_proofer(link_pre, :file)
expect(proofer.failed_tests).to eq []
end
it 'works for pipes in the URL' do
escape_pipes = "#{FIXTURES_DIR}/links/escape_pipes.html"
proofer = run_proofer(escape_pipes, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for broken hash with query' do
broken_hash = "#{FIXTURES_DIR}/links/broken_hash_with_query.html"
proofer = run_proofer(broken_hash, :file)
expect(proofer.failed_tests.first).to match(/linking to internal hash #example that does not exist/)
end
it 'passes when linking to hash on another page' do
hash_on_another_page = "#{FIXTURES_DIR}/links/hash_on_another_page.html"
proofer = run_proofer(hash_on_another_page, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for mismatched hash casing' do
hash_on_another_page = "#{FIXTURES_DIR}/links/hash_mismatched_case.html"
proofer = run_proofer(hash_on_another_page, :file)
expect(proofer.failed_tests.first).to match('internal hash #MainMenu that does not exist')
end
it 'works for directory index file' do
options = { directory_index_file: 'index.php' }
link_pointing_to_directory = "#{FIXTURES_DIR}/links/link_pointing_to_directory.html"
proofer = run_proofer(link_pointing_to_directory, :file, options)
expect(proofer.failed_tests).to eq []
end
it "fails if directory index file doesn't exist" do
options = { directory_index_file: 'README.md' }
link_pointing_to_directory = "#{FIXTURES_DIR}/links/link_pointing_to_directory.html"
proofer = run_proofer(link_pointing_to_directory, :file, options)
expect(proofer.failed_tests.first).to match('internally linking to folder-php/, which does not exist')
end
it 'ensures Typhoeus options are passed' do
options = { typhoeus: { ssl_verifypeer: false } }
typhoeus_options_link = "#{FIXTURES_DIR}/links/ensure_typhoeus_options.html"
proofer = run_proofer(typhoeus_options_link, :file, options)
expect(proofer.failed_tests).to eq []
end
it 'works if subdirectory ends with .html' do
with_subdirectory_html = "#{FIXTURES_DIR}/links/_site"
proofer = run_proofer(with_subdirectory_html, :file)
expect(proofer.failed_tests).to eq []
end
it 'works for hash referring to itself' do
hash_referring_to_self = "#{FIXTURES_DIR}/links/hash_referring_to_self.html"
proofer = run_proofer(hash_referring_to_self, :file)
expect(proofer.failed_tests).to eq []
end
it 'ignores placeholder with name' do
placeholder_with_name = "#{FIXTURES_DIR}/links/placeholder_with_name.html"
proofer = run_proofer(placeholder_with_name, :file)
expect(proofer.failed_tests).to eq []
end
it 'ignores placeholder with id' do
placeholder_with_id = "#{FIXTURES_DIR}/links/placeholder_with_id.html"
proofer = run_proofer(placeholder_with_id, :file)
expect(proofer.failed_tests).to eq []
end
it 'fails for placeholder with empty id' do
empty_id = "#{FIXTURES_DIR}/links/placeholder_with_empty_id.html"
proofer = run_proofer(empty_id, :file)
expect(proofer.failed_tests.first).to match(/anchor has no href attribute/)
end
it 'ignores non-http(s) protocols' do
other_protocols = "#{FIXTURES_DIR}/links/other_protocols.html"
proofer = run_proofer(other_protocols, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes non-standard characters' do
fixture = "#{FIXTURES_DIR}/links/non_standard_characters.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'does not dupe errors' do
fixture = "#{FIXTURES_DIR}/links/nodupe.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests.length).to eq 1
end
it 'allows unicode domains' do
fixture = "#{FIXTURES_DIR}/links/unicode_domain.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'allows punnycode domains' do
fixture = "#{FIXTURES_DIR}/links/punnycode.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes for broken *nix links' do
fixture = "#{FIXTURES_DIR}/links/broken_unix_links.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes for external UTF-8 links' do
fixture = "#{FIXTURES_DIR}/links/utf8_link.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes for urlencoded href' do
fixture = "#{FIXTURES_DIR}/links/urlencoded-href.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'reports failures for the original link, not the redirection' do
skip 'URL seems broken now. Need to find a new one'
fixture = "#{FIXTURES_DIR}/links/redirected_error.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests.first).to match(/failed: 404/)
end
it 'does not complain for files with attributes containing dashes' do
fixture = "#{FIXTURES_DIR}/links/attribute_with_dash.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
it 'passes for links hash-referencing itself' do
fixture = "#{FIXTURES_DIR}/links/self_ref.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests).to eq []
end
context 'automatically adding default extensions to files' do
before :each do
@fixture = "#{FIXTURES_DIR}/links/no_html_extension.html"
@options = { assume_extension: true }
end
it 'is not enabled by default' do
# Default behaviour does not change
proofer = run_proofer(@fixture, :file)
expect(proofer.failed_tests.count).to be >= 3
end
it 'accepts extensionless file links when enabled' do
# With command-line option
proofer = run_proofer(@fixture, :file, @options)
expect(proofer.failed_tests).to eq []
end
end
it 'does not check links with parameters multiple times' do
fixture = "#{FIXTURES_DIR}/links/check_just_once.html"
proofer = run_proofer(fixture, :file)
expect(proofer.external_urls.length).to eq 2
end
it 'does not explode on bad external links in files' do
fixture = "#{FIXTURES_DIR}/links/bad_external_links.html"
proofer = run_proofer(fixture, :file)
expect(proofer.failed_tests.length).to eq 2
expect(proofer.failed_tests.first).to match(/is an invalid URL/)
end
it 'does not explode on bad external links in arrays' do
proofer = run_proofer(['www.github.com', 'http://127.0.0.1:____'], :links)
expect(proofer.failed_tests.first).to match(/is an invalid URL/)
end
it 'passes for non-HTTPS links when not asked' do
non_https = "#{FIXTURES_DIR}/links/non_https.html"
proofer = run_proofer(non_https, :file)
expect(proofer.failed_tests.length).to eq 0
end
it 'fails for non-HTTPS links when asked' do
non_https = "#{FIXTURES_DIR}/links/non_https.html"
proofer = run_proofer(non_https, :file, enforce_https: true)
expect(proofer.failed_tests.first).to match(/ben.balter.com is not an HTTPS link/)
end
it 'passes for hash href when asked' do
hash_href = "#{FIXTURES_DIR}/links/hash_href.html"
proofer = run_proofer(hash_href, :file, allow_hash_href: true)
expect(proofer.failed_tests.length).to eq 0
end
it 'fails for hash href when not asked' do
hash_href = "#{FIXTURES_DIR}/links/hash_href.html"
proofer = run_proofer(hash_href, :file)
expect(proofer.failed_tests.first).to match(/linking to internal hash # that does not exist/)
end
it 'fails for broken IP address links' do
hash_href = "#{FIXTURES_DIR}/links/ip_href.html"
proofer = run_proofer(hash_href, :file)
expect(proofer.failed_tests.first).to match(/response code 0/)
end
it 'works for internal links to weird encoding IDs' do
hash_href = "#{FIXTURES_DIR}/links/encodingLink.html"
proofer = run_proofer(hash_href, :file)
expect(proofer.failed_tests.length).to eq 0
end
it 'does not expect href for anchors in HTML5' do
missing_href = "#{FIXTURES_DIR}/links/blank_href_html5.html"
proofer = run_proofer(missing_href, :file)
expect(proofer.failed_tests).to eq []
end
it 'does expect href for anchors in non-HTML5' do
missing_href = "#{FIXTURES_DIR}/links/blank_href_html4.html"
proofer = run_proofer(missing_href, :file)
expect(proofer.failed_tests.length).to eq 1
missing_href = "#{FIXTURES_DIR}/links/blank_href_htmlunknown.html"
proofer = run_proofer(missing_href, :file)
expect(proofer.failed_tests.length).to eq 1
end
it 'can skip expecting href for anchors in non-HTML5' do
missing_href = "#{FIXTURES_DIR}/links/blank_href_html4.html"
proofer = run_proofer(missing_href, :file, allow_missing_href: true)
expect(proofer.failed_tests.length).to eq 0
missing_href = "#{FIXTURES_DIR}/links/blank_href_htmlunknown.html"
proofer = run_proofer(missing_href, :file, allow_missing_href: true)
expect(proofer.failed_tests.length).to eq 0
end
it 'works with internal_domains' do
translated_link = "#{FIXTURES_DIR}/links/link_translated_internal_domains.html"
proofer = run_proofer(translated_link, :file, internal_domains: ['www.example.com', 'example.com'])
expect(proofer.failed_tests).to eq []
end
it 'passes for relative links with a base' do
relative_links = "#{FIXTURES_DIR}/links/relative_links_with_base.html"
proofer = run_proofer(relative_links, :file)
expect(proofer.failed_tests).to eq []
end
it 'does not bomb on dns-prefetch' do
prefetch = "#{FIXTURES_DIR}/links/dns-prefetch.html"
proofer = run_proofer(prefetch, :file)
expect(proofer.failed_tests).to eq []
end
it 'ignores links when the parent element is ignored' do
parent_ignore = "#{FIXTURES_DIR}/links/ignored_by_parent.html"
proofer = run_proofer(parent_ignore, :file)
expect(proofer.failed_tests).to eq []
end
it 'does not cgi encode link' do
prefetch = "#{FIXTURES_DIR}/links/do_not_cgi_encode.html"
proofer = run_proofer(prefetch, :file)
expect(proofer.failed_tests).to eq []
end
it 'works with quotes in the hash href' do
hash_href = "#{FIXTURES_DIR}/links/quote.html"
proofer = run_proofer(hash_href, :file, allow_hash_href: true)
expect(proofer.failed_tests.length).to eq 0
end
it 'works with base without href' do
base_no_href = "#{FIXTURES_DIR}/links/base_no_href.html"
proofer = run_proofer(base_no_href, :file)
expect(proofer.failed_tests).to eq []
end
it 'complains if SRI and CORS not provided' do
file = "#{FIXTURES_DIR}/links/integrity_and_cors_not_provided.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests.first).to match(/SRI and CORS not provided/)
end
it 'complains if SRI not provided' do
file = "#{FIXTURES_DIR}/links/cors_not_provided.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests.first).to match(/CORS not provided/)
end
it 'complains if CORS not provided' do
file = "#{FIXTURES_DIR}/links/integrity_not_provided.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests.first).to match(/Integrity is missing/)
end
it 'is happy if SRI and CORS provided' do
file = "#{FIXTURES_DIR}/links/integrity_and_cors_provided.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests).to eq []
end
it 'does not check sri for pagination' do
file = "#{FIXTURES_DIR}/links/integrity_and_cors_pagination_rels.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests).to eq []
end
it 'does not check local scripts' do
file = "#{FIXTURES_DIR}/links/local_stylesheet.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests).to eq []
end
it 'handles timeout' do
proofer = run_proofer(['https://www.sdskafnlkn3rl3204uasfilfkmakmefalkm.com:81'], :links)
expect(proofer.failed_tests.first).to match(/got a time out|the request timed out/)
end
it 'correctly handles empty href' do
file = "#{FIXTURES_DIR}/links/empty_href.html"
proofer = run_proofer(file, :file, check_external_hash: true)
expect(proofer.failed_tests.length).to eq 1
end
it 'is not checking SRI and CORS for links with rel canonical or alternate' do
file = "#{FIXTURES_DIR}/links/link_with_rel.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests).to eq []
end
it 'is not checking SRI and CORS for indieweb links with rel "me", "webmention", or "pingback"' do
file = "#{FIXTURES_DIR}/links/link_with_me.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests).to eq []
end
it 'can link to external non-unicode hash' do
file = "#{FIXTURES_DIR}/links/hash_to_unicode_ref.html"
proofer = run_proofer(file, :file, check_external_hash: true)
expect(proofer.failed_tests).to eq []
end
end