зеркало из https://github.com/github/pages-gem.git
add basic integration tests
This commit is contained in:
Родитель
8b2250d6d6
Коммит
642124ba3b
1
.rspec
1
.rspec
|
@ -1,2 +1,3 @@
|
|||
--color
|
||||
--format progress
|
||||
--require spec_helper
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "github-pages", :group => :jekyll_plugins, :path => "../../"
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
{{ content }}
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
# test
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
---
|
||||
|
||||
Page: {{ paginator.page }}
|
||||
|
||||
Total Pages: {{ paginator.total_pages }}
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
{% avatar hubot %}
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
console.log "hello world"
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
This page's layout is "{{ page.layout }}"
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
{% gist parkr/c08ee0f2726fd0e3909d %}
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
Branch: {{ site.github.source.branch }}
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
@jekyll
|
|
@ -0,0 +1 @@
|
|||
# File without front matter
|
|
@ -0,0 +1 @@
|
|||
# README
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
---
|
||||
|
||||
|
||||
[Jekyll](jekyll.md)
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
---
|
||||
|
||||
$color: #333;
|
||||
|
||||
body {
|
||||
color: $color;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Jekyll SEO Tag
|
||||
---
|
||||
|
||||
{% seo %}
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
---
|
||||
|
||||
# First heading
|
||||
|
||||
The page title is "{{ page.title }}"
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
# Jekyll
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
:tada:
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
# Test
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
foo: bar
|
||||
---
|
||||
|
||||
Value of foo: {{ page.foo }}
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
redirect_from: /redirect/
|
||||
---
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
redirect_to: /someplace-else/
|
||||
---
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
---
|
||||
|
||||
```ruby
|
||||
puts "hello world"
|
||||
```
|
|
@ -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('<h1 id="test">Test</h1>')
|
||||
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 = '<div class="language-ruby highlighter-rouge">'.dup
|
||||
expected << '<pre class="highlight"><code><span class="nb">'
|
||||
expected << 'puts</span> <span class="s2">"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 = '<meta http-equiv="refresh" content="0; url=/redirect_from.html">'
|
||||
expect(contents).to match(expected)
|
||||
end
|
||||
end
|
||||
|
||||
context "redirect_to" do
|
||||
it "redirects to" do
|
||||
expect(path).to be_an_existing_file
|
||||
expected = '<meta http-equiv="refresh" content="0; url=/someplace-else/">'
|
||||
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("<loc>/jekyll.html</loc>")
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-feed" do
|
||||
let(:file) { "feed.xml" }
|
||||
|
||||
it "builds the feed" do
|
||||
expect(path).to be_an_existing_file
|
||||
expected = '<title type="html">Test</title><link href="/2017/01/10/test.html"'
|
||||
expect(contents).to match(expected)
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-gist" do
|
||||
it "creates the script tag" do
|
||||
expected = '<script src="https://gist.github.com/parkr/c08ee0f2726fd0e3909d.js">'
|
||||
expect(contents).to match(expected)
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-paginate" do
|
||||
let(:file) { "index.html" }
|
||||
|
||||
it "paginates" do
|
||||
expect(contents).to match("Page: 1")
|
||||
expect(contents).to match("Total Pages: 1")
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-coffeescript" do
|
||||
let(:file) { "jekyll-coffeescript.js" }
|
||||
|
||||
it "converts to JS" do
|
||||
expect(path).to be_an_existing_file
|
||||
expected = Regexp.escape 'console.log("hello world");'
|
||||
expect(contents).to match(expected)
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-seo-tag" do
|
||||
it "outputs the tag" do
|
||||
expect(contents).to match("<title>Jekyll SEO Tag | pages-gem</title>")
|
||||
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('<img class="emoji" title=":tada:" alt=":tada:"')
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-mentions" do
|
||||
it "renderse mentions" do
|
||||
expect(contents).to match('<a href="https://github.com/jekyll" class="user-mention">@jekyll</a>')
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-relative-links" do
|
||||
it "converts relative links" do
|
||||
expect(contents).to match('<a href="/jekyll.html">Jekyll</a>')
|
||||
end
|
||||
end
|
||||
|
||||
context "jekyll-optional-front-matter" do
|
||||
it "renders pages without front matter" do
|
||||
expect(path).to be_an_existing_file
|
||||
expected = '<h1 id="file-without-front-matter">File without front matter</h1>'
|
||||
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
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче