Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubocop 0.55 #223

Merged
merged 1 commit into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ AllCops:
- features/**/*
- script/**/*
- spec/**/*

Naming/MemoizedInstanceVariableName:
Exclude:
- lib/jekyll-feed/page-without-a-file.rb
2 changes: 1 addition & 1 deletion jekyll-feed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "nokogiri", "~> 1.6"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "0.51"
spec.add_development_dependency "rubocop", "0.55"
spec.add_development_dependency "typhoeus", "~> 0.7"
end
75 changes: 38 additions & 37 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
require 'spec_helper'
# frozen_string_literal: true

require "spec_helper"

describe(JekyllFeed) do
let(:overrides) { Hash.new }
let(:overrides) { {} }
let(:config) do
Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
"full_rebuild" => true,
"source" => source_dir,
"destination" => dest_dir,
"show_drafts" => true,
"url" => "http://example.org",
"name" => "My awesome site",
"author" => {
"name" => "Dr. Jekyll"
"source" => source_dir,
"destination" => dest_dir,
"show_drafts" => true,
"url" => "http://example.org",
"name" => "My awesome site",
"author" => {
"name" => "Dr. Jekyll",
},
"collections" => {
"collections" => {
"my_collection" => { "output" => true },
"other_things" => { "output" => false }
}
"other_things" => { "output" => false },
},
}, overrides))
end
let(:site) { Jekyll::Site.new(config) }
let(:contents) { File.read(dest_dir("feed.xml")) }
let(:context) { make_context(site: site) }
let(:context) { make_context(:site => site) }
let(:feed_meta) { Liquid::Template.parse("{% feed_meta %}").render!(context, {}) }
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 feed.xml file" do
expect(Pathname.new(dest_dir("feed.xml"))).to exist
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 posts in the feed.xml file" do
Expand All @@ -55,7 +56,7 @@
end

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

it "supports post author name as an object" do
Expand Down Expand Up @@ -87,8 +88,8 @@
end

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

it "includes the item image" do
Expand Down Expand Up @@ -140,7 +141,7 @@

context "with site.lang set" do
lang = "en_US"
let(:overrides) { {"lang" => lang} }
let(:overrides) { { "lang" => lang } }
it "outputs a valid feed" do
expect(feed.feed_type).to eql("atom")
expect(feed.feed_version).to eql("1.0")
Expand All @@ -165,7 +166,7 @@

context "with site.title set" do
let(:site_title) { "My Site Title" }
let(:overrides) { {"title" => site_title} }
let(:overrides) { { "title" => site_title } }

it "uses site.title for the title" do
expect(feed.title.content).to eql(site_title)
Expand All @@ -174,7 +175,7 @@

context "with site.name set" do
let(:site_name) { "My Site Name" }
let(:overrides) { {"name" => site_name} }
let(:overrides) { { "name" => site_name } }

it "uses site.name for the title" do
expect(feed.title.content).to eql(site_name)
Expand All @@ -184,7 +185,7 @@
context "with site.name and site.title set" do
let(:site_title) { "My Site Title" }
let(:site_name) { "My Site Name" }
let(:overrides) { {"title" => site_title, "name" => site_name} }
let(:overrides) { { "title" => site_title, "name" => site_name } }

it "uses site.title for the title, dropping site.name" do
expect(feed.title.content).to eql(site_title)
Expand All @@ -206,20 +207,20 @@
it "validates" do
# See https://validator.w3.org/docs/api.html
url = "https://validator.w3.org/feed/check.cgi?output=soap12"
response = Typhoeus.post(url, body: { rawdata: contents }, accept_encoding: "gzip")
response = Typhoeus.post(url, :body => { :rawdata => contents }, :accept_encoding => "gzip")
pending "Something went wrong with the W3 validator" unless response.success?
result = Nokogiri::XML(response.body)
result = Nokogiri::XML(response.body)
result.remove_namespaces!

result.css("warning").each do |warning|
# Quiet a warning that results from us passing the feed as a string
next if warning.css("text").text =~ /Self reference doesn't match document location/
next if warning.css("text").text =~ %r!Self reference doesn't match document location!

# Quiet expected warning that results from blank summary test case
next if warning.css("text").text =~ /(content|summary) should not be blank/
next if warning.css("text").text =~ %r!(content|summary) should not be blank!

# Quiet expected warning about multiple posts with same updated time
next if warning.css("text").text =~ /Two entries with the same value for atom:updated/
next if warning.css("text").text =~ %r!Two entries with the same value for atom:updated!

warn "Validation warning: #{warning.css("text").text} on line #{warning.css("line").text} column #{warning.css("column").text}"
end
Expand Down Expand Up @@ -260,12 +261,12 @@
Jekyll.configuration({
"source" => source_dir,
"destination" => dest_dir,
"url" => "http://example.org"
"url" => "http://example.org",
})
end

it "does not output blank title" do
expect(feed_meta).not_to include('title=')
expect(feed_meta).not_to include("title=")
end
end
end
Expand All @@ -274,8 +275,8 @@
let(:overrides) do
{
"feed" => {
"path" => "atom.xml"
}
"path" => "atom.xml",
},
}
end

Expand All @@ -299,14 +300,14 @@
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 %r!type="text/html" hreflang="en-US" />!
end
end

context "with post.lang set"do
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 %r!<entry xml:lang="en">!
expect(contents).to match %r!<entry>!
end
end
end
16 changes: 9 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require 'jekyll'
require 'typhoeus'
require 'nokogiri'
require 'rss'
require File.expand_path('../lib/jekyll-feed', __dir__)
# frozen_string_literal: true

require "jekyll"
require "typhoeus"
require "nokogiri"
require "rss"
require File.expand_path("../lib/jekyll-feed", __dir__)

Jekyll.logger.log_level = :error

RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.order = 'random'
config.order = "random"

SOURCE_DIR = File.expand_path("fixtures", __dir__)
DEST_DIR = File.expand_path("dest", __dir__)
Expand All @@ -23,6 +25,6 @@ def dest_dir(*files)
end

def make_context(registers = {})
Liquid::Context.new({}, {}, { site: site }.merge(registers))
Liquid::Context.new({}, {}, { :site => site }.merge(registers))
end
end