spec/jekyll-sitemap_spec.rb in jekyll-sitemap-1.1.1 vs spec/jekyll-sitemap_spec.rb in jekyll-sitemap-1.2.0
- old
+ new
@@ -1,19 +1,19 @@
-# encoding: UTF-8
+# frozen_string_literal: true
-require 'spec_helper'
+require "spec_helper"
describe(Jekyll::JekyllSitemap) do
let(:overrides) do
{
"source" => source_dir,
"destination" => dest_dir,
"url" => "http://example.org",
"collections" => {
"my_collection" => { "output" => true },
- "other_things" => { "output" => false }
- }
+ "other_things" => { "output" => false },
+ },
}
end
let(:config) do
Jekyll.configuration(overrides)
end
@@ -22,20 +22,20 @@
before(:each) do
site.process
end
it "has no layout" do
- expect(contents).not_to match(/\ATHIS IS MY LAYOUT/)
+ expect(contents).not_to match(%r!\ATHIS IS MY LAYOUT!)
end
it "creates a sitemap.xml file" do
expect(File.exist?(dest_dir("sitemap.xml"))).to be_truthy
end
it "doesn't have multiple new lines or trailing whitespace" do
- expect(contents).to_not match /\s+\n/
- expect(contents).to_not match /\n{2,}/
+ expect(contents).to_not match %r!\s+\n!
+ expect(contents).to_not match %r!\n{2,}!
end
it "puts all the pages in the sitemap.xml file" do
expect(contents).to match /<loc>http:\/\/example\.org\/<\/loc>/
expect(contents).to match /<loc>http:\/\/example\.org\/some-subfolder\/this-is-a-subpage\.html<\/loc>/
@@ -86,10 +86,14 @@
it "does not include assets or any static files that aren't .html" do
expect(contents).not_to match /<loc>http:\/\/example\.org\/images\/hubot\.png<\/loc>/
expect(contents).not_to match /<loc>http:\/\/example\.org\/feeds\/atom\.xml<\/loc>/
end
+ it "converts static index.html files to permalink version" do
+ expect(contents).to match /<loc>http:\/\/example\.org\/some-subfolder\/<\/loc>/
+ end
+
it "does include assets or any static files with .xhtml and .htm extensions" do
expect(contents).to match /\/some-subfolder\/xhtml\.xhtml/
expect(contents).to match /\/some-subfolder\/htm\.htm/
end
@@ -99,10 +103,20 @@
it "does not include any static files named 404.html" do
expect(contents).not_to match %r!/static_files/404.html!
end
+ if Gem::Version.new(Jekyll::VERSION) >= Gem::Version.new("3.4.2")
+ it "does not include any static files that have set 'sitemap: false'" do
+ expect(contents).not_to match %r!/static_files/excluded\.pdf!
+ end
+
+ it "does not include any static files that have set 'sitemap: false'" do
+ expect(contents).not_to match %r!/static_files/html_file\.html!
+ end
+ end
+
it "does not include posts that have set 'sitemap: false'" do
expect(contents).not_to match /\/exclude-this-post\.html<\/loc>/
end
it "does not include pages that have set 'sitemap: false'" do
@@ -116,16 +130,21 @@
it "correctly formats timestamps of static files" do
expect(contents).to match /\/this-is-a-subfile\.html<\/loc>\s+<lastmod>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(-|\+)\d{2}:\d{2}<\/lastmod>/
end
it "includes the correct number of items" do
- expect(contents.scan(/(?=<url>)/).count).to eql 19
+ # static_files/excluded.pdf is excluded on Jekyll 3.4.2 and above
+ if Gem::Version.new(Jekyll::VERSION) >= Gem::Version.new("3.4.2")
+ expect(contents.scan(%r!(?=<url>)!).count).to eql 20
+ else
+ expect(contents.scan(%r!(?=<url>)!).count).to eql 21
+ end
end
context "with a baseurl" do
let(:config) do
- Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, {"baseurl" => "/bass"}))
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, { "baseurl" => "/bass" }))
end
it "correctly adds the baseurl to the static files" do
expect(contents).to match /<loc>http:\/\/example\.org\/bass\/some-subfolder\/this-is-a-subfile\.html<\/loc>/
end
@@ -151,11 +170,11 @@
end
end
context "with urls that needs URI encoding" do
let(:config) do
- Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, {"url" => "http://ümlaut.example.org"}))
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(overrides, { "url" => "http://ümlaut.example.org" }))
end
it "performs URI encoding of site url" do
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/some-subfolder/this-is-a-subpage.html</loc>!
@@ -164,17 +183,17 @@
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/02/%E9%94%99%E8%AF%AF.html</loc>!
expect(contents).to match %r!<loc>http://xn--mlaut-jva.example.org/2016/04/03/%E9%94%99%E8%AF%AF.html</loc>!
end
it "does not double-escape urls" do
- expect(contents).to_not match /%25/
+ expect(contents).to_not match %r!%25!
end
context "readme" do
let(:contents) { File.read(dest_dir("robots.txt")) }
it "has no layout" do
- expect(contents).not_to match(/\ATHIS IS MY LAYOUT/)
+ expect(contents).not_to match(%r!\ATHIS IS MY LAYOUT!)
end
it "creates a sitemap.xml file" do
expect(File.exist?(dest_dir("robots.txt"))).to be_truthy
end