Skip to content

Commit

Permalink
style: fix offenses in specs (#248)
Browse files Browse the repository at this point in the history
Merge pull request 248
  • Loading branch information
jekyllbot committed Oct 29, 2018
1 parent 3f4f491 commit b00b0bf
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 84 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Expand Up @@ -19,10 +19,7 @@ AllCops:
- LICENSE.txt
- README.md

- features/**/*
- script/**/*
- spec/**/*
- test/**/*
- vendor/**/*

Naming/MemoizedInstanceVariableName:
Expand Down
161 changes: 80 additions & 81 deletions spec/jekyll-feed_spec.rb
Expand Up @@ -43,53 +43,53 @@
end

it "puts all the posts in the feed.xml file" do
expect(contents).to match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(contents).to match /http:\/\/example\.org\/news\/2014\/03\/02\/march-the-second\.html/
expect(contents).to match /http:\/\/example\.org\/news\/2013\/12\/12\/dec-the-second\.html/
expect(contents).to match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(contents).to match "http://example.org/news/2014/03/02/march-the-second.html"
expect(contents).to match "http://example.org/news/2013/12/12/dec-the-second.html"
expect(contents).to match "http://example.org/2015/08/08/stuck-in-the-middle.html"
expect(contents).to_not match /http:\/\/example\.org\/2016\/02\/09\/a-draft\.html/
expect(contents).to_not match "http://example.org/2016/02/09/a-draft.html"
end

it "does not include assets or any static files that aren't .html" do
expect(contents).not_to match /http:\/\/example\.org\/images\/hubot\.png/
expect(contents).not_to match /http:\/\/example\.org\/feeds\/atom\.xml/
expect(contents).not_to match "http://example.org/images/hubot.png"
expect(contents).not_to match "http://example.org/feeds/atom.xml"
end

it "preserves linebreaks in preformatted text in posts" do
expect(contents).to match %r!Line 1\nLine 2\nLine 3!
expect(contents).to match "Line 1\nLine 2\nLine 3"
end

it "supports post author name as an object" do
expect(contents).to match /<author>\s*<name>Ben<\/name>\s*<email>ben@example.com<\/email>\s*<uri>http:\/\/ben.balter.com<\/uri>\s*<\/author>/
expect(contents).to match %r!<author>\s*<name>Ben</name>\s*<email>ben@example\.com</email>\s*<uri>http://ben\.balter\.com</uri>\s*</author>!
end

it "supports post author name as a string" do
expect(contents).to match /<author>\s*<name>Pat<\/name>\s*<\/author>/
expect(contents).to match %r!<author>\s*<name>Pat</name>\s*</author>!
end

it "does not output author tag no author is provided" do
expect(contents).not_to match /<author>\s*<name><\/name>\s*<\/author>/
expect(contents).not_to match %r!<author>\s*<name></name>\s*</author>!
end

it "does use author reference with data from _data/authors.yml" do
expect(contents).to match /<author>\s*<name>Garth<\/name>\s*<email>example@mail.com<\/email>\s*<uri>http:\/\/garthdb.com<\/uri>\s*<\/author>/
expect(contents).to match %r!<author>\s*<name>Garth</name>\s*<email>example@mail\.com</email>\s*<uri>http://garthdb\.com</uri>\s*</author>!
end

it "converts markdown posts to HTML" do
expect(contents).to match /&lt;p&gt;March the second!&lt;\/p&gt;/
expect(contents).to match %r!&lt;p&gt;March the second\!&lt;/p&gt;!
end

it "uses last_modified_at where available" do
expect(contents).to match /<updated>2015-05-12T13:27:59\+00:00<\/updated>/
expect(contents).to match %r!<updated>2015-05-12T13:27:59\+00:00</updated>!
end

it "replaces newlines in posts to spaces" do
expect(contents).to match %r!<title type="html">The plugin will properly strip newlines.</title>!
expect(contents).to match '<title type="html">The plugin will properly strip newlines.</title>'
end

it "renders Liquid inside posts" do
expect(contents).to match %r!Liquid is rendered\.!
expect(contents).not_to match %r!Liquid is not rendered\.!
expect(contents).to match "Liquid is rendered."
expect(contents).not_to match "Liquid is not rendered."
end

it "includes the item image" do
Expand Down Expand Up @@ -239,9 +239,9 @@
end

it "correctly adds the baseurl to the posts" do
expect(contents).to match /http:\/\/example\.org\/bass\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(contents).to match /http:\/\/example\.org\/bass\/news\/2014\/03\/02\/march-the-second\.html/
expect(contents).to match /http:\/\/example\.org\/bass\/news\/2013\/12\/12\/dec-the-second\.html/
expect(contents).to match "http://example.org/bass/updates/2014/03/04/march-the-fourth.html"
expect(contents).to match "http://example.org/bass/news/2014/03/02/march-the-second.html"
expect(contents).to match "http://example.org/bass/news/2013/12/12/dec-the-second.html"
end

it "renders the feed meta" do
Expand All @@ -258,11 +258,11 @@

context "with a blank site name" do
let(:config) do
Jekyll.configuration({
Jekyll.configuration(
"source" => source_dir,
"destination" => dest_dir,
"url" => "http://example.org",
})
"url" => "http://example.org"
)
end

it "does not output blank title" do
Expand Down Expand Up @@ -296,9 +296,9 @@
"feed" => {
"collections" => {
"posts" => {
"path" => "atom.xml"
}
}
"path" => "atom.xml",
},
},
},
}
end
Expand All @@ -323,70 +323,70 @@
let(:overrides) { { "lang" => "en-US" } }

it "should set the language" do
expect(contents).to match %r!type="text/html" hreflang="en-US" />!
expect(contents).to match 'type="text/html" hreflang="en-US" />'
end
end

context "with post.lang set" do
it "should set the language for that entry" do
expect(contents).to match %r!<entry xml:lang="en">!
expect(contents).to match %r!<entry>!
expect(contents).to match '<entry xml:lang="en">'
expect(contents).to match '<entry>'
end
end

context "categories" do
context "with top-level post categories" do
let(:overrides) {
let(:overrides) do
{
"feed" => { "categories" => ["news"] }
"feed" => { "categories" => ["news"] },
}
}
end
let(:news_feed) { File.read(dest_dir("feed/news.xml")) }

it "outputs the primary feed" do
expect(contents).to match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(contents).to match /http:\/\/example\.org\/news\/2014\/03\/02\/march-the-second\.html/
expect(contents).to match /http:\/\/example\.org\/news\/2013\/12\/12\/dec-the-second\.html/
expect(contents).to match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(contents).to match "http://example.org/news/2014/03/02/march-the-second.html"
expect(contents).to match "http://example.org/news/2013/12/12/dec-the-second.html"
expect(contents).to match "http://example.org/2015/08/08/stuck-in-the-middle.html"
expect(contents).to_not match /http:\/\/example\.org\/2016\/02\/09\/a-draft\.html/
expect(contents).to_not match "http://example.org/2016/02/09/a-draft.html"
end

it "outputs the category feed" do
expect(news_feed).to match "<title type=\"html\">My awesome site | News</title>"
expect(news_feed).to match /http:\/\/example\.org\/news\/2014\/03\/02\/march-the-second\.html/
expect(news_feed).to match /http:\/\/example\.org\/news\/2013\/12\/12\/dec-the-second\.html/
expect(news_feed).to_not match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(news_feed).to match '<title type="html">My awesome site | News</title>'
expect(news_feed).to match "http://example.org/news/2014/03/02/march-the-second.html"
expect(news_feed).to match "http://example.org/news/2013/12/12/dec-the-second.html"
expect(news_feed).to_not match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(news_feed).to_not match "http://example.org/2015/08/08/stuck-in-the-middle.html"
end
end

context "with collection-level post categories" do
let(:overrides) {
let(:overrides) do
{
"feed" => {
"collections" => {
"posts" => {
"categories" => ["news"]
}
}
}
"categories" => ["news"],
},
},
},
}
}
end
let(:news_feed) { File.read(dest_dir("feed/news.xml")) }

it "outputs the primary feed" do
expect(contents).to match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(contents).to match /http:\/\/example\.org\/news\/2014\/03\/02\/march-the-second\.html/
expect(contents).to match /http:\/\/example\.org\/news\/2013\/12\/12\/dec-the-second\.html/
expect(contents).to match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(contents).to match "http://example.org/news/2014/03/02/march-the-second.html"
expect(contents).to match "http://example.org/news/2013/12/12/dec-the-second.html"
expect(contents).to match "http://example.org/2015/08/08/stuck-in-the-middle.html"
expect(contents).to_not match /http:\/\/example\.org\/2016\/02\/09\/a-draft\.html/
expect(contents).to_not match "http://example.org/2016/02/09/a-draft.html"
end

it "outputs the category feed" do
expect(news_feed).to match "<title type=\"html\">My awesome site | News</title>"
expect(news_feed).to match /http:\/\/example\.org\/news\/2014\/03\/02\/march-the-second\.html/
expect(news_feed).to match /http:\/\/example\.org\/news\/2013\/12\/12\/dec-the-second\.html/
expect(news_feed).to_not match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(news_feed).to match '<title type="html">My awesome site | News</title>'
expect(news_feed).to match "http://example.org/news/2014/03/02/march-the-second.html"
expect(news_feed).to match "http://example.org/news/2013/12/12/dec-the-second.html"
expect(news_feed).to_not match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(news_feed).to_not match "http://example.org/2015/08/08/stuck-in-the-middle.html"
end
end
Expand All @@ -396,73 +396,72 @@
let(:collection_feed) { File.read(dest_dir("feed/collection.xml")) }

context "when initialized as an array" do
let(:overrides) {
let(:overrides) do
{
"collections" => {
"collection" => {
"output" => true
}
"output" => true,
},
},
"feed" => { "collections" => ["collection"] }
"feed" => { "collections" => ["collection"] },
}
}

end

it "outputs the collection feed" do
expect(collection_feed).to match "<title type=\"html\">My awesome site | Collection</title>"
expect(collection_feed).to match '<title type="html">My awesome site | Collection</title>'
expect(collection_feed).to match "http://example.org/collection/2018-01-01-collection-doc.html"
expect(collection_feed).to match "http://example.org/collection/2018-01-02-collection-category-doc.html"
expect(collection_feed).to_not match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(collection_feed).to_not match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(collection_feed).to_not match "http://example.org/2015/08/08/stuck-in-the-middle.html"
end
end

context "with categories" do
let(:overrides) {
let(:overrides) do
{
"collections" => {
"collection" => {
"output" => true
}
"output" => true,
},
},
"feed" => {
"feed" => {
"collections" => {
"collection" => {
"categories" => ["news"]
}
}
}
"categories" => ["news"],
},
},
},
}
}
end
let(:news_feed) { File.read(dest_dir("feed/collection/news.xml")) }

it "outputs the collection category feed" do
expect(news_feed).to match "<title type=\"html\">My awesome site | Collection | News</title>"
expect(news_feed).to match '<title type="html">My awesome site | Collection | News</title>'
expect(news_feed).to match "http://example.org/collection/2018-01-02-collection-category-doc.html"
expect(news_feed).to_not match "http://example.org/collection/2018-01-01-collection-doc.html"
expect(news_feed).to_not match /http:\/\/example\.org\/updates\/2014\/03\/04\/march-the-fourth\.html/
expect(news_feed).to_not match "http://example.org/updates/2014/03/04/march-the-fourth.html"
expect(news_feed).to_not match "http://example.org/2015/08/08/stuck-in-the-middle.html"
end
end

context "with a custom path" do
let(:overrides) {
let(:overrides) do
{
"collections" => {
"collection" => {
"output" => true
}
"output" => true,
},
},
"feed" => {
"feed" => {
"collections" => {
"collection" => {
"categories" => ["news"],
"path" => "custom.xml"
}
}
}
"path" => "custom.xml",
},
},
},
}
}
end

it "should write to the custom path" do
expect(Pathname.new(dest_dir("custom.xml"))).to exist
Expand Down

0 comments on commit b00b0bf

Please sign in to comment.