From 642124ba3b8250a5a5cb1b00185f57ef2f1545f2 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Thu, 31 Aug 2017 17:02:04 -0400 Subject: [PATCH] add basic integration tests --- .rspec | 1 + spec/fixtures/Gemfile | 5 + spec/fixtures/_config.yml | 8 + spec/fixtures/_layouts/page.md | 4 + spec/fixtures/_posts/2017-01-10-test.md | 4 + spec/fixtures/index.html | 6 + spec/fixtures/jekyll-avatar.html | 4 + spec/fixtures/jekyll-coffeescript.coffee | 4 + spec/fixtures/jekyll-default-layout.md | 4 + spec/fixtures/jekyll-gist.md | 4 + spec/fixtures/jekyll-github-metadata.html | 4 + spec/fixtures/jekyll-mentions.md | 4 + spec/fixtures/jekyll-optional-front-matter.md | 1 + spec/fixtures/jekyll-readme-index/README.md | 1 + spec/fixtures/jekyll-relative-links.md | 5 + spec/fixtures/jekyll-sass-converter.scss | 8 + spec/fixtures/jekyll-seo-tag.html | 5 + spec/fixtures/jekyll-titles-from-headings.md | 6 + spec/fixtures/jekyll.md | 4 + spec/fixtures/jemoji.md | 4 + spec/fixtures/kramdown.md | 4 + spec/fixtures/liquid.html | 5 + spec/fixtures/redirect_from.html | 3 + spec/fixtures/redirect_to.html | 3 + spec/fixtures/rouge.md | 6 + spec/github-pages/integration_spec.rb | 215 ++++++++++++++++++ spec/spec_helper.rb | 9 +- 27 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/Gemfile create mode 100644 spec/fixtures/_layouts/page.md create mode 100644 spec/fixtures/_posts/2017-01-10-test.md create mode 100644 spec/fixtures/index.html create mode 100644 spec/fixtures/jekyll-avatar.html create mode 100644 spec/fixtures/jekyll-coffeescript.coffee create mode 100644 spec/fixtures/jekyll-default-layout.md create mode 100644 spec/fixtures/jekyll-gist.md create mode 100644 spec/fixtures/jekyll-github-metadata.html create mode 100644 spec/fixtures/jekyll-mentions.md create mode 100644 spec/fixtures/jekyll-optional-front-matter.md create mode 100644 spec/fixtures/jekyll-readme-index/README.md create mode 100644 spec/fixtures/jekyll-relative-links.md create mode 100644 spec/fixtures/jekyll-sass-converter.scss create mode 100644 spec/fixtures/jekyll-seo-tag.html create mode 100644 spec/fixtures/jekyll-titles-from-headings.md create mode 100644 spec/fixtures/jekyll.md create mode 100644 spec/fixtures/jemoji.md create mode 100644 spec/fixtures/kramdown.md create mode 100644 spec/fixtures/liquid.html create mode 100644 spec/fixtures/redirect_from.html create mode 100644 spec/fixtures/redirect_to.html create mode 100644 spec/fixtures/rouge.md create mode 100644 spec/github-pages/integration_spec.rb diff --git a/.rspec b/.rspec index 5f16476..2559e39 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ --color --format progress +--require spec_helper diff --git a/spec/fixtures/Gemfile b/spec/fixtures/Gemfile new file mode 100644 index 0000000..7fe62b2 --- /dev/null +++ b/spec/fixtures/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "github-pages", :group => :jekyll_plugins, :path => "../../" diff --git a/spec/fixtures/_config.yml b/spec/fixtures/_config.yml index f72783a..7222eab 100644 --- a/spec/fixtures/_config.yml +++ b/spec/fixtures/_config.yml @@ -2,5 +2,13 @@ some_key: some_value safe: false gems: - jekyll-sitemap + - jekyll-redirect-from + - jekyll-feed + - jekyll-paginate + - jekyll-seo-tag + - jekyll-avatar + - jemoji + - jekyll-mentions - jekyll_test_plugin_malicious quiet: false +paginate: 5 diff --git a/spec/fixtures/_layouts/page.md b/spec/fixtures/_layouts/page.md new file mode 100644 index 0000000..801832c --- /dev/null +++ b/spec/fixtures/_layouts/page.md @@ -0,0 +1,4 @@ +--- +--- + +{{ content }} diff --git a/spec/fixtures/_posts/2017-01-10-test.md b/spec/fixtures/_posts/2017-01-10-test.md new file mode 100644 index 0000000..2770131 --- /dev/null +++ b/spec/fixtures/_posts/2017-01-10-test.md @@ -0,0 +1,4 @@ +--- +--- + +# test diff --git a/spec/fixtures/index.html b/spec/fixtures/index.html new file mode 100644 index 0000000..74a4fbe --- /dev/null +++ b/spec/fixtures/index.html @@ -0,0 +1,6 @@ +--- +--- + +Page: {{ paginator.page }} + +Total Pages: {{ paginator.total_pages }} diff --git a/spec/fixtures/jekyll-avatar.html b/spec/fixtures/jekyll-avatar.html new file mode 100644 index 0000000..d310099 --- /dev/null +++ b/spec/fixtures/jekyll-avatar.html @@ -0,0 +1,4 @@ +--- +--- + +{% avatar hubot %} diff --git a/spec/fixtures/jekyll-coffeescript.coffee b/spec/fixtures/jekyll-coffeescript.coffee new file mode 100644 index 0000000..40459fa --- /dev/null +++ b/spec/fixtures/jekyll-coffeescript.coffee @@ -0,0 +1,4 @@ +--- +--- + +console.log "hello world" diff --git a/spec/fixtures/jekyll-default-layout.md b/spec/fixtures/jekyll-default-layout.md new file mode 100644 index 0000000..76eca68 --- /dev/null +++ b/spec/fixtures/jekyll-default-layout.md @@ -0,0 +1,4 @@ +--- +--- + +This page's layout is "{{ page.layout }}" diff --git a/spec/fixtures/jekyll-gist.md b/spec/fixtures/jekyll-gist.md new file mode 100644 index 0000000..03e2ee5 --- /dev/null +++ b/spec/fixtures/jekyll-gist.md @@ -0,0 +1,4 @@ +--- +--- + +{% gist parkr/c08ee0f2726fd0e3909d %} diff --git a/spec/fixtures/jekyll-github-metadata.html b/spec/fixtures/jekyll-github-metadata.html new file mode 100644 index 0000000..b323c39 --- /dev/null +++ b/spec/fixtures/jekyll-github-metadata.html @@ -0,0 +1,4 @@ +--- +--- + +Branch: {{ site.github.source.branch }} diff --git a/spec/fixtures/jekyll-mentions.md b/spec/fixtures/jekyll-mentions.md new file mode 100644 index 0000000..26a8061 --- /dev/null +++ b/spec/fixtures/jekyll-mentions.md @@ -0,0 +1,4 @@ +--- +--- + +@jekyll diff --git a/spec/fixtures/jekyll-optional-front-matter.md b/spec/fixtures/jekyll-optional-front-matter.md new file mode 100644 index 0000000..e30c8c0 --- /dev/null +++ b/spec/fixtures/jekyll-optional-front-matter.md @@ -0,0 +1 @@ +# File without front matter diff --git a/spec/fixtures/jekyll-readme-index/README.md b/spec/fixtures/jekyll-readme-index/README.md new file mode 100644 index 0000000..7e59600 --- /dev/null +++ b/spec/fixtures/jekyll-readme-index/README.md @@ -0,0 +1 @@ +# README diff --git a/spec/fixtures/jekyll-relative-links.md b/spec/fixtures/jekyll-relative-links.md new file mode 100644 index 0000000..889348d --- /dev/null +++ b/spec/fixtures/jekyll-relative-links.md @@ -0,0 +1,5 @@ +--- +--- + + +[Jekyll](jekyll.md) diff --git a/spec/fixtures/jekyll-sass-converter.scss b/spec/fixtures/jekyll-sass-converter.scss new file mode 100644 index 0000000..c770df6 --- /dev/null +++ b/spec/fixtures/jekyll-sass-converter.scss @@ -0,0 +1,8 @@ +--- +--- + +$color: #333; + +body { + color: $color; +} diff --git a/spec/fixtures/jekyll-seo-tag.html b/spec/fixtures/jekyll-seo-tag.html new file mode 100644 index 0000000..1e02676 --- /dev/null +++ b/spec/fixtures/jekyll-seo-tag.html @@ -0,0 +1,5 @@ +--- +title: Jekyll SEO Tag +--- + +{% seo %} diff --git a/spec/fixtures/jekyll-titles-from-headings.md b/spec/fixtures/jekyll-titles-from-headings.md new file mode 100644 index 0000000..be0e527 --- /dev/null +++ b/spec/fixtures/jekyll-titles-from-headings.md @@ -0,0 +1,6 @@ +--- +--- + +# First heading + +The page title is "{{ page.title }}" diff --git a/spec/fixtures/jekyll.md b/spec/fixtures/jekyll.md new file mode 100644 index 0000000..fd01db3 --- /dev/null +++ b/spec/fixtures/jekyll.md @@ -0,0 +1,4 @@ +--- +--- + +# Jekyll diff --git a/spec/fixtures/jemoji.md b/spec/fixtures/jemoji.md new file mode 100644 index 0000000..fea9ca7 --- /dev/null +++ b/spec/fixtures/jemoji.md @@ -0,0 +1,4 @@ +--- +--- + +:tada: diff --git a/spec/fixtures/kramdown.md b/spec/fixtures/kramdown.md new file mode 100644 index 0000000..ef355dc --- /dev/null +++ b/spec/fixtures/kramdown.md @@ -0,0 +1,4 @@ +--- +--- + +# Test diff --git a/spec/fixtures/liquid.html b/spec/fixtures/liquid.html new file mode 100644 index 0000000..1b70d69 --- /dev/null +++ b/spec/fixtures/liquid.html @@ -0,0 +1,5 @@ +--- +foo: bar +--- + +Value of foo: {{ page.foo }} diff --git a/spec/fixtures/redirect_from.html b/spec/fixtures/redirect_from.html new file mode 100644 index 0000000..1af61da --- /dev/null +++ b/spec/fixtures/redirect_from.html @@ -0,0 +1,3 @@ +--- +redirect_from: /redirect/ +--- diff --git a/spec/fixtures/redirect_to.html b/spec/fixtures/redirect_to.html new file mode 100644 index 0000000..8c88da7 --- /dev/null +++ b/spec/fixtures/redirect_to.html @@ -0,0 +1,3 @@ +--- +redirect_to: /someplace-else/ +--- diff --git a/spec/fixtures/rouge.md b/spec/fixtures/rouge.md new file mode 100644 index 0000000..ed8569f --- /dev/null +++ b/spec/fixtures/rouge.md @@ -0,0 +1,6 @@ +--- +--- + +```ruby +puts "hello world" +``` diff --git a/spec/github-pages/integration_spec.rb b/spec/github-pages/integration_spec.rb new file mode 100644 index 0000000..c28323f --- /dev/null +++ b/spec/github-pages/integration_spec.rb @@ -0,0 +1,215 @@ +# frozen_string_literal: true + +RSpec.describe "Pages Gem Integration spec" do + def destination_file(file) + File.join tmp_dir, file + end + + def source + @source ||= fixture_dir + end + + def destination + @destination ||= tmp_dir + end + + def env + { "BUNDLE_GEMFILE" => "#{source}/Gemfile" } + end + + def run_or_raise(env, *cmd) + stdout_and_stderr_str, status = Open3.capture2e env, *cmd + raise StandardError, stdout_and_stderr_str if status.exitstatus != 0 + end + + let(:file) { "#{self.class.description}.html" } + let(:path) { destination_file file } + let(:contents) { File.read path } + + before(:all) { FileUtils.rm_rf(destination) } + before(:all) do + Dir.chdir(source) do + run_or_raise env, %w(bundle install) + cmd = %w(bundle exec jekyll build --verbose) + cmd = cmd.concat ["--source", source, "--destination", destination] + run_or_raise env, *cmd + end + end + after(:all) { FileUtils.rm_rf(destination) } + + it "tests all dependencies" do + contents = File.read(__FILE__) + contexts = contents.scan(/context \"(.*?)\"/) + missing = GitHubPages::Dependencies::VERSIONS.keys - contexts.flatten + missing -= %w(listen activesupport github-pages-health-check) + msg = "The following dependencies are missing integration tests: #{missing.join(", ")}" + expect(missing).to be_empty, msg + end + + context "jekyll" do + it "builds" do + expect(path).to be_an_existing_file + end + end + + context "jekyll-sass-converter" do + let(:file) { "jekyll-sass-converter.css" } + + it "Renders SCSS" do + expect(path).to be_an_existing_file + expect(contents).to match("body { color: #333; }") + end + end + + context "kramdown" do + it "converts markdown to HTML" do + expect(contents).to match('

Test

') + end + end + + context "liquid" do + it "renders liquid templates" do + expect(contents).to match("Value of foo: bar") + end + end + + context "rouge" do + it "syntax highlights" do + expected = '
'.dup + expected << '
'
+      expected << 'puts "hello world"'
+      expect(contents).to match(expected)
+    end
+  end
+
+  context "jekyll-redirect-from" do
+    context "redirect_from" do
+      let(:file) { "redirect/index.html" }
+
+      it "redirects from" do
+        expect(path).to be_an_existing_file
+        expected = ''
+        expect(contents).to match(expected)
+      end
+    end
+
+    context "redirect_to" do
+      it "redirects to" do
+        expect(path).to be_an_existing_file
+        expected = ''
+        expect(contents).to match(expected)
+      end
+    end
+  end
+
+  context "jekyll-sitemap" do
+    let(:file) { "sitemap.xml" }
+
+    it "builds the sitemap" do
+      expect(path).to be_an_existing_file
+      expect(contents).to match("/jekyll.html")
+    end
+  end
+
+  context "jekyll-feed" do
+    let(:file) { "feed.xml" }
+
+    it "builds the feed" do
+      expect(path).to be_an_existing_file
+      expected = 'TestJekyll SEO Tag | pages-gem")
+    end
+  end
+
+  context "jekyll-github-metadata" do
+    it "builds the site.github namespace" do
+      expect(contents).to match("Branch: gh-pages")
+    end
+  end
+
+  context "jekyll-avatar" do
+    it "renders the avatar" do
+      expected = %r{https://avatars\d\.githubusercontent\.com/hubot\?v=3&s=40}
+      expect(contents).to match(expected)
+    end
+  end
+
+  context "jemoji" do
+    it "renders emoji" do
+      expect(contents).to match(':tada:@jekyll')
+    end
+  end
+
+  context "jekyll-relative-links" do
+    it "converts relative links" do
+      expect(contents).to match('Jekyll')
+    end
+  end
+
+  context "jekyll-optional-front-matter" do
+    it "renders pages without front matter" do
+      expect(path).to be_an_existing_file
+      expected = '

File without front matter

' + expect(contents).to match(expected) + end + end + + context "jekyll-titles-from-headings" do + it "pulls titles from headings" do + expect(contents).to match("The page title is “First heading”") + end + end + + context "jekyll-default-layout" do + it "sets the default layout" do + expect(contents).to match("This page’s layout is “page”") + end + end + + context "jekyll-readme-index" do + let(:file) { "jekyll-readme-index/index.html" } + + it "uses the README as the index" do + expect(path).to be_an_existing_file + expect(contents).to match("README") + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 30feab4..8b92e07 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require File.expand_path("../../lib/github-pages.rb", __FILE__) +require "open3" RSpec.configure do |config| config.run_all_when_everything_filtered = true @@ -14,9 +15,13 @@ RSpec.configure do |config| end def fixture_dir - File.expand_path "./fixtures", File.dirname(__FILE__) + File.expand_path "./fixtures", __dir__ end def tmp_dir - File.expand_path "./test-site", File.dirname(__FILE__) + File.expand_path "../tmp", __dir__ +end + +RSpec::Matchers.define :be_an_existing_file do + match { |path| File.exist?(path) } end