File: favicon_spec.rb

package info (click to toggle)
ruby-html-proofer 3.19.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,040 kB
  • sloc: ruby: 3,203; sh: 9; makefile: 4; javascript: 1; php: 1
file content (71 lines) | stat: -rw-r--r-- 2,931 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require 'spec_helper'

describe 'Favicons test' do
  it 'ignores for absent favicon by default' do
    absent = "#{FIXTURES_DIR}/favicon/favicon_absent.html"
    expect(run_proofer(absent, :file).failed_tests).to eq []
  end

  it 'fails for absent favicon' do
    absent = "#{FIXTURES_DIR}/favicon/favicon_absent.html"
    proofer = run_proofer(absent, :file, check_favicon: true)
    expect(proofer.failed_tests.first).to match(/no favicon specified/)
  end

  it 'fails for absent favicon but present apple touch icon' do
    absent = "#{FIXTURES_DIR}/favicon/favicon_absent_apple.html"
    proofer = run_proofer(absent, :file, check_favicon: true)
    # Travis gives a different error message here for some reason
    expect(proofer.failed_tests.last).to match(/(internally linking to gpl.png, which does not exist|no favicon specified)/)
  end

  it 'fails for broken favicon' do
    broken = "#{FIXTURES_DIR}/favicon/favicon_broken.html"
    proofer = run_proofer(broken, :file, check_favicon: true)
    expect(proofer.failed_tests.first).to match(/internally linking to asdadaskdalsdk.png/)
  end

  it 'fails for ignored with url_ignore' do
    ignored = "#{FIXTURES_DIR}/favicon/favicon_broken.html"
    proofer = run_proofer(ignored, :file, check_favicon: true, url_ignore: [/asdadaskdalsdk/])
    expect(proofer.failed_tests.first).to match(/no favicon specified/)
  end

  it 'translates links via url_swap' do
    translated_link = "#{FIXTURES_DIR}/favicon/favicon_broken.html"
    proofer = run_proofer(translated_link, :file, check_favicon: true, url_swap: { /^asdadaskdalsdk.+/ => '../resources/gpl.png' })
    expect(proofer.failed_tests).to eq []
  end

  it 'passes for present favicon' do
    present = "#{FIXTURES_DIR}/favicon/favicon_present.html"
    proofer = run_proofer(present, :file, check_favicon: true)
    expect(proofer.failed_tests).to eq []
  end

  it 'passes for present favicon with shortcut notation' do
    present = "#{FIXTURES_DIR}/favicon/favicon_present_shortcut.html"
    proofer = run_proofer(present, :file, check_favicon: true)
    expect(proofer.failed_tests).to eq []
  end

  it 'fails for broken favicon with data-proofer-ignore' do
    broken_but_ignored = "#{FIXTURES_DIR}/favicon/favicon_broken_but_ignored.html"
    proofer = run_proofer(broken_but_ignored, :file, check_favicon: true)
    expect(proofer.failed_tests.first).to match(/no favicon specified/)
  end

  it 'specifically ignores jekyll redirect_from template' do
    broken_but_ignored = "#{FIXTURES_DIR}/favicon/jekyll_redirect_from.html"
    proofer = run_proofer(broken_but_ignored, :file, check_favicon: true)
    expect(proofer.failed_tests).to eq []
  end

  it 'ignores SRI/CORS requirements for favicons' do
    file = "#{FIXTURES_DIR}/favicon/cors_not_needed.html"
    proofer = run_proofer(file, :file, check_sri: true)
    expect(proofer.failed_tests).to eq []
  end
end