File: url_spec.rb

package info (click to toggle)
ruby-html-proofer 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,524 kB
  • sloc: ruby: 4,389; sh: 8; makefile: 4; javascript: 1; php: 1
file content (49 lines) | stat: -rw-r--r-- 1,490 bytes parent folder | download
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
# frozen_string_literal: true

require "spec_helper"

describe "Attribute::Url" do
  let(:runner) { HTMLProofer::Runner.new("") }
  let(:described_class) { HTMLProofer::Attribute::Url }

  describe "#ignores_pattern_check" do
    it "works for regex patterns" do
      runner.options[:ignore_urls] = [%r{/assets/.*(js|css|png|svg)}]
      url = described_class.new(runner, "/assets/main.js")
      expect(url.ignore?).to(be(true))
    end

    it "works for string patterns" do
      runner.options[:ignore_urls] = ["/assets/main.js"]
      url = described_class.new(runner, "/assets/main.js")
      expect(url.ignore?).to(be(true))
    end
  end

  describe "#protocol_relative" do
    it "works for protocol relative" do
      url = described_class.new(runner, "//assets/main.js")
      expect(url.protocol_relative?).to(be(true))
    end

    it "works for https://" do
      url = described_class.new(runner, "https://assets/main.js")
      expect(url.protocol_relative?).to(be(false))
    end

    it "works for http://" do
      url = described_class.new(runner, "http://assets/main.js")
      expect(url.protocol_relative?).to(be(false))
    end

    it "works for relative internal link" do
      url = described_class.new(runner, "assets/main.js")
      expect(url.protocol_relative?).to(be(false))
    end

    it "works for absolute internal link" do
      url = described_class.new(runner, "/assets/main.js")
      expect(url.protocol_relative?).to(be(false))
    end
  end
end