File: opengraph_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 (77 lines) | stat: -rw-r--r-- 3,152 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
72
73
74
75
76
77
# frozen_string_literal: true

require 'spec_helper'

describe 'Open Graph test' do
  it 'passes for existing external url' do
    url_valid = "#{FIXTURES_DIR}/opengraph/url-valid.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests).to eq []
  end

  it 'fails for missing url content attribute' do
    url_valid = "#{FIXTURES_DIR}/opengraph/url-missing.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/open graph has no content attribute/)
  end

  it 'fails for empty url' do
    url_valid = "#{FIXTURES_DIR}/opengraph/url-empty.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/open graph content attribute is empty/)
  end

  it 'fails for missing external url' do
    url_valid = "#{FIXTURES_DIR}/opengraph/url-broken.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/failed: response code 0/)
  end

  it 'passes for existing external image' do
    url_valid = "#{FIXTURES_DIR}/opengraph/image-valid.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests).to eq []
  end

  it 'fails for missing image content attribute' do
    url_valid = "#{FIXTURES_DIR}/opengraph/image-missing.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/open graph has no content attribute/)
  end

  it 'fails for empty image' do
    url_valid = "#{FIXTURES_DIR}/opengraph/image-empty.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/open graph content attribute is empty/)
  end

  it 'fails for missing external image' do
    url_valid = "#{FIXTURES_DIR}/opengraph/image-broken.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/failed: 404/)
  end

  it 'fails for missing internal images' do
    image_internal_invalid = "#{FIXTURES_DIR}/opengraph/image-internal-broken.html"
    proofer = run_proofer(image_internal_invalid, :file, check_opengraph: true)
    expect(proofer.failed_tests.first).to match(/doesnotexist.png does not exist/)
  end

  it 'passes for missing external url when not asked to check' do
    url_valid = "#{FIXTURES_DIR}/opengraph/url-broken.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: false)
    expect(proofer.failed_tests).to eq []
  end

  it 'passes for missing external image when not asked to check' do
    url_valid = "#{FIXTURES_DIR}/opengraph/image-broken.html"
    proofer = run_proofer(url_valid, :file, check_opengraph: false)
    expect(proofer.failed_tests).to eq []
  end

  it 'passes for internal domains' do
    translated_link = "#{FIXTURES_DIR}/opengraph/translated-internal.html"
    proofer = run_proofer(translated_link, :file, check_opengraph: true, internal_domains: ['www.example.com', 'example.com'])
    expect(proofer.failed_tests).to eq []
  end
end