File: element_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 (53 lines) | stat: -rw-r--r-- 1,898 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
50
51
52
53
# frozen_string_literal: true

require "spec_helper"

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

  describe "#initialize" do
    it "accepts the xmlns attribute" do
      nokogiri = Nokogiri::HTML5('<a xmlns:cc="http://creativecommons.org/ns#">Creative Commons</a>')
      element = described_class.new(runner, nokogiri.css("a").first)
      expect(element.node["xmlns:cc"]).to(eq("http://creativecommons.org/ns#"))
    end

    it "assignes the text node" do
      nokogiri = Nokogiri::HTML5("<p>One")
      element = described_class.new(runner, nokogiri.css("p").first)
      expect(element.node.text).to(eq("One"))
      expect(element.node.content).to(eq("One"))
    end

    it "accepts the content attribute" do
      nokogiri = Nokogiri::HTML5('<meta name="twitter:card" content="summary">')
      element = described_class.new(runner, nokogiri.css("meta").first)
      expect(element.node["content"]).to(eq("summary"))
    end
  end

  describe "#link_attribute" do
    it "works for src attributes" do
      nokogiri = Nokogiri::HTML5("<img src=image.png />")
      element = described_class.new(runner, nokogiri.css("img").first)
      expect(element.url.to_s).to(eq("image.png"))
    end
  end

  describe "#ignore" do
    it "works for twitter cards" do
      nokogiri = Nokogiri::HTML5('<meta name="twitter:url" data-proofer-ignore content="http://example.com/soon-to-be-published-url">')
      element = described_class.new(runner, nokogiri.css("meta").first)
      expect(element.ignore?).to(be(true))
    end
  end

  describe "ivar setting" do
    it "does not explode if given a bad attribute" do
      broken_attribute = File.join(FIXTURES_DIR, "html", "invalid_attribute.html")
      proofer = run_proofer(broken_attribute, :file)
      expect(proofer.failed_checks.length).to(eq(0))
    end
  end
end