Merge branch 'master' into sponsor

This commit is contained in:
olivia 2018-07-17 12:20:54 +02:00
commit 9f05275619
50 changed files with 1177 additions and 1034 deletions

View File

@ -11,6 +11,7 @@ AllCops:
TargetRubyVersion: 2.3 TargetRubyVersion: 2.3
Include: Include:
- lib/**/*.rb - lib/**/*.rb
- test/**/*.rb
Exclude: Exclude:
- bin/**/* - bin/**/*
- exe/**/* - exe/**/*
@ -82,6 +83,9 @@ Metrics/PerceivedComplexity:
Max: 8 Max: 8
Naming/FileName: Naming/FileName:
Enabled: false Enabled: false
Naming/HeredocDelimiterNaming:
Exclude:
- test/**/*.rb
Naming/MemoizedInstanceVariableName: Naming/MemoizedInstanceVariableName:
Exclude: Exclude:
- lib/jekyll/page_without_a_file.rb - lib/jekyll/page_without_a_file.rb
@ -104,6 +108,9 @@ Style/Alias:
EnforcedStyle: prefer_alias_method EnforcedStyle: prefer_alias_method
Style/AndOr: Style/AndOr:
Severity: error Severity: error
Style/ClassAndModuleChildren:
Exclude:
- test/**/*.rb
Style/FrozenStringLiteralComment: Style/FrozenStringLiteralComment:
EnforcedStyle: always EnforcedStyle: always
Style/Documentation: Style/Documentation:

View File

@ -1,49 +1,46 @@
# Code of Conduct # Code of Conduct
As contributors and maintainers of this project, and in the interest of ## Our Pledge
fostering an open and welcoming community, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating
documentation, submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance, ## Our Standards
body size, race, ethnicity, age, religion, or nationality.
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include: Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery * The use of sexualized language or imagery and unwelcome sexual attention or advances
* Personal attacks * Trolling, insulting/derogatory comments, and personal or political attacks
* Trolling or insulting/derogatory comments
* Public or private harassment * Public or private harassment
* Publishing other's private information, such as physical or electronic * Publishing others' private information, such as a physical or electronic address, without explicit permission
addresses, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting
* Other unethical or unprofessional conduct
Project maintainers have the right and responsibility to remove, edit, or ## Our Responsibilities
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
By adopting this Code of Conduct, project maintainers commit themselves to Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
fairly and consistently applying these principles to every aspect of managing
this project. Project maintainers who do not follow or enforce the Code of
Conduct may be permanently removed from the project team.
This Code of Conduct applies both within project spaces and in public spaces Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may be ## Scope
reported by opening an issue or contacting a project maintainer. All complaints
will be reviewed and investigated and will result in a response that is deemed
necessary and appropriate to the circumstances. Maintainers are obligated to
maintain confidentiality with regard to the reporter of an incident.
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
This Code of Conduct is adapted from the [Contributor Covenant][homepage], ## Enforcement
version 1.3.0, available at
[http://contributor-covenant.org/version/1/3/0/][version]
[homepage]: http://contributor-covenant.org Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting a project maintainer. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
[version]: http://contributor-covenant.org/version/1/3/0/
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct.html][version]
[homepage]: https://www.contributor-covenant.org/
[version]: https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

View File

@ -28,6 +28,15 @@
* Added plugin json-get. (#7086) * Added plugin json-get. (#7086)
* Update travis-ci.md to point out "this is an example Gemfile" (#7089) * Update travis-ci.md to point out "this is an example Gemfile" (#7089)
* Adding `jekyll-info` plugin (#7091) * Adding `jekyll-info` plugin (#7091)
* GitHub enables you to use themes from other repos (#7112)
* Updates to CODE OF CONDUCT (v1.4.0) (#7105)
* Instructions to view themes files under Linux (#7095)
* add jekyll-xml-source (#7114)
* Add the jekyll-firstimage filter plugin (#7127)
* Use a real theme in the example (#7125)
* Update docs about post creation (#7138)
* Add DEV Community's Jekyll tag to community page (#7139)
* Initialize upgrading doc for v4.0 (#7140)
### Minor Enhancements ### Minor Enhancements
@ -35,6 +44,9 @@
* Memoize computing excerpt's relative_path (#6951) * Memoize computing excerpt's relative_path (#6951)
* Liquefied link tag (#6269) * Liquefied link tag (#6269)
* Suggest re-running command with --trace on fail (#6551) * Suggest re-running command with --trace on fail (#6551)
* Update item_property to return numbers as numbers instead of strings (#6608)
* Use .markdown for page templates (#7126)
* Fix custom 404 page for GitHub pages (#7132)
### Major Enhancements ### Major Enhancements
@ -59,7 +71,19 @@
* Update Rubocop's config (#7050) * Update Rubocop's config (#7050)
* Remember to release docs gem (#7066) * Remember to release docs gem (#7066)
* Use assert_include (#7093) * Use assert_include (#7093)
* Update rubocop version to 0.57.x (#7078) * Update rubocop version to 0.57.x ### -docs (#7078)
* Example of CircleCI deployment through CircleCI v2 (#7024)
* Fix Rubocop offences in test files (#7128)
* fix up refute_equal call (#7133)
* Fix incorrectly passed arguments to assert_equal (#7134)
### Bug Fixes
* Add call to unused method `validate_options` in `commands/serve.rb` (#7122)
### feature
* Disable Liquid via front matter (#6824)
## 3.8.3 / 2018-06-05 ## 3.8.3 / 2018-06-05

View File

@ -61,7 +61,7 @@ test:
## Complete Example circle.yml File ## Complete Example circle.yml File
When you put it all together, here's an example of what that `circle.yml` file could look like: When you put it all together, here's an example of what that `circle.yml` file could look like in v1:
```yaml ```yaml
machine: machine:
@ -83,6 +83,75 @@ deployment:
- rsync -va --delete ./_site username@my-website:/var/html - rsync -va --delete ./_site username@my-website:/var/html
``` ```
for CircleCI v2, a Docker-based system which new projects will follow, set the `S3_BUCKET_NAME` environment variable (an example of the required config file is shown below).
```yaml
defaults: &defaults
working_directory: ~/repo
version: 2
jobs:
build:
<<: *defaults
docker:
- image: circleci/ruby:2.5
environment:
BUNDLE_PATH: ~/repo/vendor/bundle
steps:
- checkout
- restore_cache:
keys:
- rubygems-v1-{% raw %}{{ checksum "Gemfile.lock" }}{% endraw %}
- rubygems-v1-fallback
- run:
name: Bundle Install
command: bundle check || bundle install
- run:
name: HTMLProofer tests
command: |
bundle exec htmlproofer ./_site \
--allow-hash-href \
--check-favicon \
--check-html \
--disable-external
- save_cache:
key: rubygems-v1-{% raw %}{{ checksum "Gemfile.lock" }}{% endraw %}
paths:
- vendor/bundle
- run:
name: Jekyll build
command: bundle exec jekyll build
- persist_to_workspace:
root: ./
paths:
- _site
deploy:
<<: *defaults
docker:
- image: circleci/python:3.6.3
environment:
S3_BUCKET_NAME: <<YOUR BUCKET NAME HERE>>
steps:
- attach_workspace:
at: ./
- run:
name: Install AWS CLI
command: pip install awscli --upgrade --user
- run:
name: Upload to s3
command: ~/.local/bin/aws s3 sync ./_site s3://$S3_BUCKET_NAME/ --delete --acl public-read
workflows:
version: 2
test-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master
```
## Questions? ## Questions?
This entire guide is open-source. Go ahead and [edit it][7] if you have a fix or [ask for help][8] if you run into trouble and need some help. CircleCI also has an [online community][9] for help. This entire guide is open-source. Go ahead and [edit it][7] if you have a fix or [ask for help][8] if you run into trouble and need some help. CircleCI also has an [online community][9] for help.

View File

@ -828,6 +828,7 @@ You can find a few useful plugins at the following locations:
- [replace_regex](https://github.com/sparanoid/replace_regex): A Liquid filter to perform regex replace. - [replace_regex](https://github.com/sparanoid/replace_regex): A Liquid filter to perform regex replace.
- [Jekyll Money](https://rubygems.org/gems/jekyll-money): A Jekyll plugin for dealing with money. Because we all have to at some point. - [Jekyll Money](https://rubygems.org/gems/jekyll-money): A Jekyll plugin for dealing with money. Because we all have to at some point.
- [jekyll-random](https://github.com/codecalm/jekyll-random) by [codecalm](https://nodecalm.net): A Jekyll plugin that generates pseudo-random data. Very useful when you want to generate a large amount of random data. - [jekyll-random](https://github.com/codecalm/jekyll-random) by [codecalm](https://nodecalm.net): A Jekyll plugin that generates pseudo-random data. Very useful when you want to generate a large amount of random data.
- [jekyll-firstimage](https://github.com/nhoizey/jekyll-firstimage) adds a Liquid filter finding the first image in a HTML content string, including responsive images srcset.
#### Tags #### Tags
@ -940,6 +941,7 @@ You can find a few useful plugins at the following locations:
- [jekyll-pwa-plugin](https://github.com/lavas-project/jekyll-pwa): A plugin provides PWA support for Jekyll. It generates a service worker in Jekyll build process and makes precache and runtime cache available in the runtime with Google Workbox. - [jekyll-pwa-plugin](https://github.com/lavas-project/jekyll-pwa): A plugin provides PWA support for Jekyll. It generates a service worker in Jekyll build process and makes precache and runtime cache available in the runtime with Google Workbox.
- [jekyll-algolia](https://community.algolia.com/jekyll-algolia/): Add fast and relevant search to your Jekyll site through the Algolia API. - [jekyll-algolia](https://community.algolia.com/jekyll-algolia/): Add fast and relevant search to your Jekyll site through the Algolia API.
- [jekyll-get](https://github.com/18F/jekyll-get): Download data from external JSON API sources to use in generating a site. - [jekyll-get](https://github.com/18F/jekyll-get): Download data from external JSON API sources to use in generating a site.
- [jekyll-xml-source](https://github.com/mcred/jekyll-xml-source): Download XML and RSS from external sites for use in site data.
<div class="note info"> <div class="note info">
<h5>Submit your gem plugins</h5> <h5>Submit your gem plugins</h5>

View File

@ -19,8 +19,8 @@ In the case of Minima, you see only the following files in your Jekyll site dire
├── _config.yml ├── _config.yml
├── _posts ├── _posts
│ └── 2016-12-04-welcome-to-jekyll.markdown │ └── 2016-12-04-welcome-to-jekyll.markdown
├── about.md ├── about.markdown
└── index.md └── index.markdown
``` ```
The `Gemfile` and `Gemfile.lock` files are used by Bundler to keep track of the required gems and gem versions you need to build your Jekyll site. The `Gemfile` and `Gemfile.lock` files are used by Bundler to keep track of the required gems and gem versions you need to build your Jekyll site.
@ -52,6 +52,8 @@ To locate a theme's files on your computer:
open $(bundle show minima) open $(bundle show minima)
# On Windows # On Windows
explorer /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0 explorer /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0
# On Linux
xdg-open $(bundle show minima)
``` ```
A Finder or Explorer window opens showing the theme's files and directories. The Minima theme gem contains these files: A Finder or Explorer window opens showing the theme's files and directories. The Minima theme gem contains these files:
@ -164,20 +166,21 @@ For example, search for [jekyll theme on RubyGems](https://rubygems.org/search?u
To install a gem-based theme: To install a gem-based theme:
1. Add the theme to your site's `Gemfile`: 1. Add the theme gem to your site's `Gemfile`:
```ruby ```ruby
# ./Gemfile # ./Gemfile
gem "jekyll-theme-awesome" # This is an example, declare the theme gem you want to use here
gem "jekyll-theme-minimal"
``` ```
Or if you've started with the `jekyll new` command, replace `gem "minima", "~> 2.0"` with your theme-gem: Or if you've started with the `jekyll new` command, replace `gem "minima", "~> 2.0"` with the gem you want, e.g:
```diff ```diff
# ./Gemfile # ./Gemfile
- gem "minima", "~> 2.0" - gem "minima", "~> 2.0"
+ gem "jekyll-theme-awesome" + gem "jekyll-theme-minimal"
``` ```
2. Install the theme: 2. Install the theme:
@ -189,7 +192,7 @@ To install a gem-based theme:
3. Add the following to your site's `_config.yml` to activate the theme: 3. Add the following to your site's `_config.yml` to activate the theme:
```yaml ```yaml
theme: jekyll-theme-awesome theme: jekyll-theme-minimal
``` ```
4. Build your site: 4. Build your site:
@ -201,7 +204,7 @@ To install a gem-based theme:
You can have multiple themes listed in your site's `Gemfile`, but only one theme can be selected in your site's `_config.yml`. You can have multiple themes listed in your site's `Gemfile`, but only one theme can be selected in your site's `_config.yml`.
{: .note .info } {: .note .info }
If you're publishing your Jekyll site on [GitHub Pages](https://pages.github.com/), note that GitHub Pages supports only some gem-based themes. See [Supported Themes](https://pages.github.com/themes/) in GitHub's documentation to see which themes are supported. If you're publishing your Jekyll site on [GitHub Pages](https://pages.github.com/), note that GitHub Pages supports only [some gem-based themes](https://pages.github.com/themes/). GitHub Pages also supports [using any theme hosted on GitHub](https://help.github.com/articles/adding-a-jekyll-theme-to-your-github-pages-site/#adding-a-jekyll-theme-in-your-sites-_configyml-file) using the `remote_theme` configuration as if it were a gem-based theme.
## Creating a gem-based theme ## Creating a gem-based theme

View File

@ -0,0 +1,28 @@
---
title: Upgrading from 3.x to 4.x
permalink: /docs/upgrading/3-to-4/
---
Upgrading from an older version of Jekyll? A few things have changed in Jekyll 4
that you'll want to know about.
Before we dive in, you need to have at least Ruby 2.3.0 installed. Run the following
in your terminal to check
```sh
ruby -v
```
If you're using Ruby >= 2.3.0, go ahead and fetch the latest version of Jekyll:
```sh
gem update jekyll
```
---
*Insert sections here*
---
*Did we miss something? Please click "Improve this page" above and add a section. Thanks!*

View File

@ -26,6 +26,10 @@ question!
Get live support at **#jekyll** on **irc.freenode.net**, the official Get live support at **#jekyll** on **irc.freenode.net**, the official
Jekyll IRC channel. Jekyll IRC channel.
### [The Dev community](https://dev.to/)
[DEVs jekyll tag](https://dev.to/t/jekyll) is a place to share Jekyll projects, articles and tutorials as well as start discussions and ask for feedback on Jekyll-related topics. Developers of all skill-levels are welcome to take part.
### View source ### View source
Learn from the source of others, you'll find plenty of [jekyll sites](https://github.com/topics/jekyll-site) and [jekyll themes](https://github.com/topics/jekyll-themes) carefully handcrafted on GitHub. Learn from the source of others, you'll find plenty of [jekyll sites](https://github.com/topics/jekyll-site) and [jekyll themes](https://github.com/topics/jekyll-themes) carefully handcrafted on GitHub.

View File

@ -251,6 +251,19 @@ Feature: Post data
And I should see "Post categories: scifi and Movies" in "_site/scifi/movies/2009/03/27/star-wars.html" And I should see "Post categories: scifi and Movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
And I should see "Post categories: SciFi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html" And I should see "Post categories: SciFi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html"
Scenario: Use page.render_with_liquid variable
Given I have a _posts directory
And I have the following posts:
| title | render_with_liquid | date | content |
| Unrendered Post | false | 2017-07-06 | Hello {{ page.title }} |
| Rendered Post | true | 2017-07-06 | Hello {{ page.title }} |
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should not see "Hello Unrendered Post" in "_site/2017/07/06/unrendered-post.html"
But I should see "Hello {{ page.title }}" in "_site/2017/07/06/unrendered-post.html"
And I should see "Hello Rendered Post" in "_site/2017/07/06/rendered-post.html"
Scenario Outline: Use page.path variable Scenario Outline: Use page.path variable
Given I have a <dir>/_posts directory Given I have a <dir>/_posts directory
And I have the following post in "<dir>": And I have the following post in "<dir>":

View File

@ -91,7 +91,10 @@ module Jekyll
def process(opts) def process(opts)
opts = configuration_from_options(opts) opts = configuration_from_options(opts)
destination = opts["destination"] destination = opts["destination"]
register_reload_hooks(opts) if opts["livereload"] if opts["livereload"]
validate_options(opts)
register_reload_hooks(opts)
end
setup(destination) setup(destination)
start_up_webrick(opts, destination) start_up_webrick(opts, destination)

View File

@ -160,6 +160,7 @@ module Jekyll
# #
# Returns true if the file has Liquid Tags or Variables, false otherwise. # Returns true if the file has Liquid Tags or Variables, false otherwise.
def render_with_liquid? def render_with_liquid?
return false if data["render_with_liquid"] == false
Jekyll::Utils.has_liquid_construct?(content) Jekyll::Utils.has_liquid_construct?(content)
end end

View File

@ -159,6 +159,7 @@ module Jekyll
# or if the document doesn't contain any Liquid Tags or Variables, # or if the document doesn't contain any Liquid Tags or Variables,
# true otherwise. # true otherwise.
def render_with_liquid? def render_with_liquid?
return false if data["render_with_liquid"] == false
!(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content)) !(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content))
end end

View File

@ -299,16 +299,16 @@ module Jekyll
# We also utilize the Schwartzian transform to make this more efficient. # We also utilize the Schwartzian transform to make this more efficient.
def sort_input(input, property, order) def sort_input(input, property, order)
input.map { |item| [item_property(item, property), item] } input.map { |item| [item_property(item, property), item] }
.sort! do |apple_info, orange_info| .sort! do |a_info, b_info|
apple_property = apple_info.first a_property = a_info.first
orange_property = orange_info.first b_property = b_info.first
if !apple_property.nil? && orange_property.nil? if !a_property.nil? && b_property.nil?
- order - order
elsif apple_property.nil? && !orange_property.nil? elsif a_property.nil? && !b_property.nil?
+ order + order
else else
apple_property <=> orange_property a_property <=> b_property || a_property.to_s <=> b_property.to_s
end end
end end
.map!(&:last) .map!(&:last)
@ -317,15 +317,22 @@ module Jekyll
def item_property(item, property) def item_property(item, property)
if item.respond_to?(:to_liquid) if item.respond_to?(:to_liquid)
property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute| property.to_s.split(".").reduce(item.to_liquid) do |subvalue, attribute|
subvalue[attribute] parse_sort_input(subvalue[attribute])
end end
elsif item.respond_to?(:data) elsif item.respond_to?(:data)
item.data[property.to_s] parse_sort_input(item.data[property.to_s])
else else
item[property.to_s] parse_sort_input(item[property.to_s])
end end
end end
# return numeric values as numbers for proper sorting
def parse_sort_input(property)
number_like = %r!\A\s*-?(?:\d+\.?\d*|\.\d+)\s*\Z!
return property.to_f if property =~ number_like
property
end
def as_liquid(item) def as_liquid(item)
case item case item
when Hash when Hash

View File

@ -1,4 +1,5 @@
--- ---
permalink: /404.html
layout: default layout: default
--- ---

View File

@ -6,7 +6,11 @@ categories: jekyll update
--- ---
Youll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated. Youll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated.
To add new posts, simply add a file in the `_posts` directory that follows the convention `YYYY-MM-DD-name-of-post.ext` and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works. Jekyll requires blog post files to be named according to the following format:
`YEAR-MONTH-DAY-title.MARKUP`
Where `YEAR` is a four-digit number, `MONTH` and `DAY` are both two-digit numbers, and `MARKUP` is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.
Jekyll also offers powerful support for code snippets: Jekyll also offers powerful support for code snippets:

4
test/fixtures/no_liquid.erb vendored Normal file
View File

@ -0,0 +1,4 @@
---
render_with_liquid: false
---
{% raw %}{% endraw %}

View File

@ -111,13 +111,13 @@ class JekyllUnitTest < Minitest::Test
end end
def fixture_document(relative_path) def fixture_document(relative_path)
site = fixture_site({ site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"output" => true, "output" => true,
}, },
}, }
}) )
site.read site.read
matching_doc = site.collections["methods"].docs.find do |doc| matching_doc = site.collections["methods"].docs.find do |doc|
doc.relative_path == relative_path doc.relative_path == relative_path
@ -138,13 +138,13 @@ class JekyllUnitTest < Minitest::Test
end end
def site_configuration(overrides = {}) def site_configuration(overrides = {})
full_overrides = build_configs(overrides, build_configs({ full_overrides = build_configs(overrides, build_configs(
"destination" => dest_dir, "destination" => dest_dir,
"incremental" => false, "incremental" => false
})) ))
Configuration.from(full_overrides.merge({ Configuration.from(full_overrides.merge(
"source" => source_dir, "source" => source_dir
})) ))
end end
def clear_dest def clear_dest
@ -197,7 +197,6 @@ class FakeLogger
end end
module TestWEBrick module TestWEBrick
module_function module_function
def mount_server(&block) def mount_server(&block)
@ -235,11 +234,11 @@ module TestWEBrick
end end
def document_root_options def document_root_options
WEBrick::Config::FileHandler.merge({ WEBrick::Config::FileHandler.merge(
:FancyIndexing => true, :FancyIndexing => true,
:NondisclosureName => [ :NondisclosureName => [
".ht*", "~*", ".ht*", "~*",
], ]
}) )
end end
end end

View File

@ -15,7 +15,7 @@ class TestAnsi < JekyllUnitTest
end end
should "be able to strip colors" do should "be able to strip colors" do
assert_equal @subject.strip(@subject.yellow(@subject.red("hello"))), "hello" assert_equal "hello", @subject.strip(@subject.yellow(@subject.red("hello")))
end end
should "be able to detect colors" do should "be able to detect colors" do

View File

@ -9,7 +9,7 @@ class TestCoffeeScript < JekyllUnitTest
@site = fixture_site @site = fixture_site
@site.process @site.process
@test_coffeescript_file = dest_dir("js/coffeescript.js") @test_coffeescript_file = dest_dir("js/coffeescript.js")
@js_output = <<-JS @js_output = <<~JS
(function() { (function() {
$(function() { $(function() {
var cube, cubes, list, num, square; var cube, cubes, list, num, square;

View File

@ -9,11 +9,11 @@ class TestCollections < JekyllUnitTest
end end
should "sanitize the label name" do should "sanitize the label name" do
assert_equal @collection.label, "....etcpassword" assert_equal "....etcpassword", @collection.label
end end
should "have a sanitized relative path name" do should "have a sanitized relative path name" do
assert_equal @collection.relative_directory, "_....etcpassword" assert_equal "_....etcpassword", @collection.relative_directory
end end
should "have a sanitized full path" do should "have a sanitized full path" do
@ -27,11 +27,11 @@ class TestCollections < JekyllUnitTest
end end
should "sanitize the label name" do should "sanitize the label name" do
assert_equal @collection.label, "methods" assert_equal "methods", @collection.label
end end
should "have default URL template" do should "have default URL template" do
assert_equal @collection.url_template, "/:collection/:path:output_ext" assert_equal "/:collection/:path:output_ext", @collection.url_template
end end
should "contain no docs when initialized" do should "contain no docs when initialized" do
@ -39,7 +39,7 @@ class TestCollections < JekyllUnitTest
end end
should "know its relative directory" do should "know its relative directory" do
assert_equal @collection.relative_directory, "_methods" assert_equal "_methods", @collection.relative_directory
end end
should "know the full path to itself on the filesystem" do should "know the full path to itself on the filesystem" do
@ -48,15 +48,15 @@ class TestCollections < JekyllUnitTest
context "when turned into Liquid" do context "when turned into Liquid" do
should "have a label attribute" do should "have a label attribute" do
assert_equal @collection.to_liquid["label"], "methods" assert_equal "methods", @collection.to_liquid["label"]
end end
should "have a docs attribute" do should "have a docs attribute" do
assert_equal @collection.to_liquid["docs"], [] assert_equal [], @collection.to_liquid["docs"]
end end
should "have a files attribute" do should "have a files attribute" do
assert_equal @collection.to_liquid["files"], [] assert_equal [], @collection.to_liquid["files"]
end end
should "have a directory attribute" do should "have a directory attribute" do
@ -64,18 +64,18 @@ class TestCollections < JekyllUnitTest
end end
should "have a relative_directory attribute" do should "have a relative_directory attribute" do
assert_equal @collection.to_liquid["relative_directory"], "_methods" assert_equal "_methods", @collection.to_liquid["relative_directory"]
end end
should "have a output attribute" do should "have a output attribute" do
assert_equal @collection.to_liquid["output"], false assert_equal false, @collection.to_liquid["output"]
end end
end end
should "know whether it should be written or not" do should "know whether it should be written or not" do
assert_equal @collection.write?, false assert_equal false, @collection.write?
@collection.metadata["output"] = true @collection.metadata["output"] = true
assert_equal @collection.write?, true assert_equal true, @collection.write?
@collection.metadata.delete "output" @collection.metadata.delete "output"
end end
end end
@ -87,34 +87,35 @@ class TestCollections < JekyllUnitTest
end end
should "contain only the default collections" do should "contain only the default collections" do
refute_equal @site.collections, {} expected = {}
refute_equal expected, @site.collections
refute_nil @site.collections refute_nil @site.collections
end end
end end
context "a collection with permalink" do context "a collection with permalink" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"permalink" => "/awesome/:path/", "permalink" => "/awesome/:path/",
}, },
}, }
}) )
@site.process @site.process
@collection = @site.collections["methods"] @collection = @site.collections["methods"]
end end
should "have custom URL template" do should "have custom URL template" do
assert_equal @collection.url_template, "/awesome/:path/" assert_equal "/awesome/:path/", @collection.url_template
end end
end end
context "with a collection" do context "with a collection" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["methods"], "collections" => ["methods"]
}) )
@site.process @site.process
@collection = @site.collections["methods"] @collection = @site.collections["methods"]
end end
@ -160,29 +161,30 @@ class TestCollections < JekyllUnitTest
context "with a collection with metadata" do context "with a collection with metadata" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"foo" => "bar", "foo" => "bar",
"baz" => "whoo", "baz" => "whoo",
}, },
}, }
}) )
@site.process @site.process
@collection = @site.collections["methods"] @collection = @site.collections["methods"]
end end
should "extract the configuration collection information as metadata" do should "extract the configuration collection information as metadata" do
assert_equal @collection.metadata, { "foo" => "bar", "baz" => "whoo" } expected = { "foo" => "bar", "baz" => "whoo" }
assert_equal expected, @collection.metadata
end end
end end
context "in safe mode" do context "in safe mode" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["methods"], "collections" => ["methods"],
"safe" => true, "safe" => true
}) )
@site.process @site.process
@collection = @site.collections["methods"] @collection = @site.collections["methods"]
end end
@ -202,10 +204,10 @@ class TestCollections < JekyllUnitTest
context "with dots in the filenames" do context "with dots in the filenames" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["with.dots"], "collections" => ["with.dots"],
"safe" => true, "safe" => true
}) )
@site.process @site.process
@collection = @site.collections["with.dots"] @collection = @site.collections["with.dots"]
end end
@ -231,14 +233,14 @@ class TestCollections < JekyllUnitTest
context "a collection with included dotfiles" do context "a collection with included dotfiles" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"permalink" => "/awesome/:path/", "permalink" => "/awesome/:path/",
}, },
}, },
"include" => %w(.htaccess .gitignore), "include" => %w(.htaccess .gitignore)
}) )
@site.process @site.process
@collection = @site.collections["methods"] @collection = @site.collections["methods"]
end end

View File

@ -15,7 +15,9 @@ class TestCommand < JekyllUnitTest
context "when fatal error occurs" do context "when fatal error occurs" do
should "exit with non-zero error code" do should "exit with non-zero error code" do
site = Object.new site = Object.new
def site.process; raise Jekyll::Errors::FatalException; end def site.process
raise Jekyll::Errors::FatalException
end
error = assert_raises(SystemExit) { Command.process_site(site) } error = assert_raises(SystemExit) { Command.process_site(site) }
refute_equal 0, error.status refute_equal 0, error.status
end end

View File

@ -5,7 +5,6 @@ require "mercenary"
require "helper" require "helper"
require "httpclient" require "httpclient"
require "openssl" require "openssl"
require "thread"
require "tmpdir" require "tmpdir"
class TestCommandsServe < JekyllUnitTest class TestCommandsServe < JekyllUnitTest
@ -155,9 +154,7 @@ class TestCommandsServe < JekyllUnitTest
end end
should "label itself" do should "label itself" do
assert_equal( assert_equal :serve, @merc.name
@merc.name, :serve
)
end end
should "have aliases" do should "have aliases" do
@ -191,14 +188,14 @@ class TestCommandsServe < JekyllUnitTest
end end
should "use user destinations" do should "use user destinations" do
assert_equal "foo", custom_opts({ "destination" => "foo" })[ assert_equal "foo", custom_opts("destination" => "foo")[
:DocumentRoot :DocumentRoot
] ]
end end
should "use user port" do should "use user port" do
# WHAT?!?!1 Over 9000? That's impossible. # WHAT?!?!1 Over 9000? That's impossible.
assert_equal 9001, custom_opts({ "port" => 9001 })[ assert_equal 9001, custom_opts("port" => 9001)[
:Port :Port
] ]
end end
@ -237,21 +234,20 @@ class TestCommandsServe < JekyllUnitTest
expect(Jekyll::Commands::Serve).to receive(:start_up_webrick) expect(Jekyll::Commands::Serve).to receive(:start_up_webrick)
end end
should "set the site url by default to `http://localhost:4000`" do should "set the site url by default to `http://localhost:4000`" do
@merc.execute(:serve, { "watch" => false, "url" => "https://jekyllrb.com/" }) @merc.execute(:serve, "watch" => false, "url" => "https://jekyllrb.com/")
assert_equal 1, Jekyll.sites.count assert_equal 1, Jekyll.sites.count
assert_equal "http://localhost:4000", Jekyll.sites.first.config["url"] assert_equal "http://localhost:4000", Jekyll.sites.first.config["url"]
end end
should "take `host`, `port` and `ssl` into consideration if set" do should "take `host`, `port` and `ssl` into consideration if set" do
@merc.execute(:serve, { @merc.execute(:serve,
"watch" => false, "watch" => false,
"host" => "example.com", "host" => "example.com",
"port" => "9999", "port" => "9999",
"url" => "https://jekyllrb.com/", "url" => "https://jekyllrb.com/",
"ssl_cert" => "foo", "ssl_cert" => "foo",
"ssl_key" => "bar", "ssl_key" => "bar")
})
assert_equal 1, Jekyll.sites.count assert_equal 1, Jekyll.sites.count
assert_equal "https://example.com:9999", Jekyll.sites.first.config["url"] assert_equal "https://example.com:9999", Jekyll.sites.first.config["url"]
@ -262,7 +258,7 @@ class TestCommandsServe < JekyllUnitTest
should "not update the site url" do should "not update the site url" do
expect(Jekyll).to receive(:env).and_return("production") expect(Jekyll).to receive(:env).and_return("production")
expect(Jekyll::Commands::Serve).to receive(:start_up_webrick) expect(Jekyll::Commands::Serve).to receive(:start_up_webrick)
@merc.execute(:serve, { "watch" => false, "url" => "https://jekyllrb.com/" }) @merc.execute(:serve, "watch" => false, "url" => "https://jekyllrb.com/")
assert_equal 1, Jekyll.sites.count assert_equal 1, Jekyll.sites.count
assert_equal "https://jekyllrb.com/", Jekyll.sites.first.config["url"] assert_equal "https://jekyllrb.com/", Jekyll.sites.first.config["url"]
@ -271,26 +267,26 @@ class TestCommandsServe < JekyllUnitTest
context "verbose" do context "verbose" do
should "debug when verbose" do should "debug when verbose" do
assert_equal custom_opts({ "verbose" => true })[:Logger].level, 5 assert_equal 5, custom_opts("verbose" => true)[:Logger].level
end end
should "warn when not verbose" do should "warn when not verbose" do
assert_equal custom_opts({})[:Logger].level, 3 assert_equal 3, custom_opts({})[:Logger].level
end end
end end
context "enabling SSL" do context "enabling SSL" do
should "raise if enabling without key or cert" do should "raise if enabling without key or cert" do
assert_raises RuntimeError do assert_raises RuntimeError do
custom_opts({ custom_opts(
"ssl_key" => "foo", "ssl_key" => "foo"
}) )
end end
assert_raises RuntimeError do assert_raises RuntimeError do
custom_opts({ custom_opts(
"ssl_key" => "foo", "ssl_key" => "foo"
}) )
end end
end end
@ -299,16 +295,16 @@ class TestCommandsServe < JekyllUnitTest
expect(OpenSSL::X509::Certificate).to receive(:new).and_return("c1") expect(OpenSSL::X509::Certificate).to receive(:new).and_return("c1")
allow(File).to receive(:read).and_return("foo") allow(File).to receive(:read).and_return("foo")
result = custom_opts({ result = custom_opts(
"ssl_cert" => "foo", "ssl_cert" => "foo",
"source" => "bar", "source" => "bar",
"enable_ssl" => true, "enable_ssl" => true,
"ssl_key" => "bar", "ssl_key" => "bar"
}) )
assert result[:SSLEnable] assert result[:SSLEnable]
assert_equal result[:SSLPrivateKey], "c2" assert_equal "c2", result[:SSLPrivateKey]
assert_equal result[:SSLCertificate], "c1" assert_equal "c1", result[:SSLCertificate]
end end
end end
end end
@ -317,7 +313,7 @@ class TestCommandsServe < JekyllUnitTest
allow(Jekyll::Commands::Serve).to receive(:start_up_webrick) allow(Jekyll::Commands::Serve).to receive(:start_up_webrick)
expect(Jekyll).to receive(:configuration).once.and_call_original expect(Jekyll).to receive(:configuration).once.and_call_original
@merc.execute(:serve, { "watch" => false }) @merc.execute(:serve, "watch" => false)
end end
end end
end end

View File

@ -15,9 +15,9 @@ class TestConfiguration < JekyllUnitTest
end end
should "merge input over defaults" do should "merge input over defaults" do
result = Configuration.from({ "source" => "blah" }) result = Configuration.from("source" => "blah")
refute_equal result["source"], Configuration::DEFAULTS["source"] refute_equal result["source"], Configuration::DEFAULTS["source"]
assert_equal result["source"], "blah" assert_equal "blah", result["source"]
end end
should "return a valid Configuration instance" do should "return a valid Configuration instance" do
@ -26,15 +26,11 @@ class TestConfiguration < JekyllUnitTest
should "add default collections" do should "add default collections" do
result = Configuration.from({}) result = Configuration.from({})
assert_equal( expected = { "posts" => {
result["collections"],
{
"posts" => {
"output" => true, "output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext", "permalink" => "/:categories/:year/:month/:day/:title:output_ext",
}, }, }
} assert_equal expected, result["collections"]
)
end end
should "NOT backwards-compatibilize" do should "NOT backwards-compatibilize" do
@ -70,34 +66,29 @@ class TestConfiguration < JekyllUnitTest
should "turn an array into a hash" do should "turn an array into a hash" do
result = Configuration[{ "collections" => %w(methods) }].add_default_collections result = Configuration[{ "collections" => %w(methods) }].add_default_collections
assert_instance_of Hash, result["collections"] assert_instance_of Hash, result["collections"]
assert_equal( expected = { "posts" => { "output" => true }, "methods" => {} }
result["collections"], assert_equal expected, result["collections"]
{ "posts" => { "output" => true }, "methods" => {} }
)
end end
should "only assign collections.posts.permalink if a permalink is specified" do should "only assign collections.posts.permalink if a permalink is specified" do
result = Configuration[{ "permalink" => "pretty", "collections" => {} }] result = Configuration[{ "permalink" => "pretty", "collections" => {} }]
.add_default_collections .add_default_collections
assert_equal( expected = { "posts" => {
result["collections"],
{
"posts" => {
"output" => true, "output" => true,
"permalink" => "/:categories/:year/:month/:day/:title/", "permalink" => "/:categories/:year/:month/:day/:title/",
}, }, }
} assert_equal expected, result["collections"]
)
result = Configuration[{ "permalink" => nil, "collections" => {} }] result = Configuration[{ "permalink" => nil, "collections" => {} }]
.add_default_collections .add_default_collections
assert_equal result["collections"], { "posts" => { "output" => true } } expected = { "posts" => { "output" => true } }
assert_equal expected, result["collections"]
end end
should "forces posts to output" do should "forces posts to output" do
result = Configuration[{ "collections" => { "posts" => { "output" => false } } }] result = Configuration[{ "collections" => { "posts" => { "output" => false } } }]
.add_default_collections .add_default_collections
assert_equal result["collections"]["posts"]["output"], true assert_equal true, result["collections"]["posts"]["output"]
end end
end end
@ -186,7 +177,7 @@ class TestConfiguration < JekyllUnitTest
allow(SafeYAML) allow(SafeYAML)
.to receive(:load_file) .to receive(:load_file)
.with("not_empty.yml") .with("not_empty.yml")
.and_return({ "foo" => "bar", "include" => "", "exclude" => "" }) .and_return("foo" => "bar", "include" => "", "exclude" => "")
Jekyll.logger.log_level = :warn Jekyll.logger.log_level = :warn
read_config = @config.read_config_files(["empty.yml", "not_empty.yml"]) read_config = @config.read_config_files(["empty.yml", "not_empty.yml"])
Jekyll.logger.log_level = :info Jekyll.logger.log_level = :info
@ -220,23 +211,19 @@ class TestConfiguration < JekyllUnitTest
should "transform string exclude into an array" do should "transform string exclude into an array" do
assert @config.key?("exclude") assert @config.key?("exclude")
assert @config.backwards_compatibilize.key?("exclude") assert @config.backwards_compatibilize.key?("exclude")
assert_equal( expected = %w(READ-ME.md Gemfile CONTRIBUTING.hello.markdown)
@config.backwards_compatibilize["exclude"], assert_equal expected, @config.backwards_compatibilize["exclude"]
%w(READ-ME.md Gemfile CONTRIBUTING.hello.markdown)
)
end end
should "transform string include into an array" do should "transform string include into an array" do
assert @config.key?("include") assert @config.key?("include")
assert @config.backwards_compatibilize.key?("include") assert @config.backwards_compatibilize.key?("include")
assert_equal( expected = %w(STOP_THE_PRESSES.txt .heloses .git)
@config.backwards_compatibilize["include"], assert_equal expected, @config.backwards_compatibilize["include"]
%w(STOP_THE_PRESSES.txt .heloses .git)
)
end end
should "set highlighter to pygments" do should "set highlighter to pygments" do
assert @config.key?("pygments") assert @config.key?("pygments")
assert !@config.backwards_compatibilize.key?("pygments") assert !@config.backwards_compatibilize.key?("pygments")
assert_equal @config.backwards_compatibilize["highlighter"], "pygments" assert_equal "pygments", @config.backwards_compatibilize["highlighter"]
end end
should "adjust directory names" do should "adjust directory names" do
assert @config.key?("layouts") assert @config.key?("layouts")
@ -305,7 +292,7 @@ class TestConfiguration < JekyllUnitTest
"The configuration file '#{@user_config}' could not be found." "The configuration file '#{@user_config}' could not be found."
)) ))
assert_raises LoadError do assert_raises LoadError do
Jekyll.configuration({ "config" => [@user_config] }) Jekyll.configuration("config" => [@user_config])
end end
end end
@ -334,14 +321,14 @@ class TestConfiguration < JekyllUnitTest
allow(SafeYAML) allow(SafeYAML)
.to receive(:load_file) .to receive(:load_file)
.with(@paths[:other]) .with(@paths[:other])
.and_return({ "baseurl" => "http://example.com" }) .and_return("baseurl" => "http://example.com")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal \ assert_equal \
site_configuration({ site_configuration(
"baseurl" => "http://example.com", "baseurl" => "http://example.com",
"config" => @paths[:other], "config" => @paths[:other]
}), ),
Jekyll.configuration(test_config.merge({ "config" => @paths[:other] })) Jekyll.configuration(test_config.merge("config" => @paths[:other]))
end end
should "load different config if specified with symbol key" do should "load different config if specified with symbol key" do
@ -349,33 +336,33 @@ class TestConfiguration < JekyllUnitTest
allow(SafeYAML) allow(SafeYAML)
.to receive(:load_file) .to receive(:load_file)
.with(@paths[:other]) .with(@paths[:other])
.and_return({ "baseurl" => "http://example.com" }) .and_return("baseurl" => "http://example.com")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal \ assert_equal \
site_configuration({ site_configuration(
"baseurl" => "http://example.com", "baseurl" => "http://example.com",
"config" => @paths[:other], "config" => @paths[:other]
}), ),
Jekyll.configuration(test_config.merge({ :config => @paths[:other] })) Jekyll.configuration(test_config.merge(:config => @paths[:other]))
end end
should "load default config if path passed is empty" do should "load default config if path passed is empty" do
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({}) allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
assert_equal \ assert_equal \
site_configuration({ "config" => [@paths[:empty]] }), site_configuration("config" => [@paths[:empty]]),
Jekyll.configuration(test_config.merge({ "config" => [@paths[:empty]] })) Jekyll.configuration(test_config.merge("config" => [@paths[:empty]]))
end end
should "successfully load a TOML file" do should "successfully load a TOML file" do
Jekyll.logger.log_level = :warn Jekyll.logger.log_level = :warn
assert_equal \ assert_equal \
site_configuration({ site_configuration(
"baseurl" => "/you-beautiful-blog-you", "baseurl" => "/you-beautiful-blog-you",
"title" => "My magnificent site, wut", "title" => "My magnificent site, wut",
"config" => [@paths[:toml]], "config" => [@paths[:toml]]
}), ),
Jekyll.configuration(test_config.merge({ "config" => [@paths[:toml]] })) Jekyll.configuration(test_config.merge("config" => [@paths[:toml]]))
Jekyll.logger.log_level = :info Jekyll.logger.log_level = :info
end end
@ -389,12 +376,12 @@ class TestConfiguration < JekyllUnitTest
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
assert_equal( assert_equal(
site_configuration({ site_configuration(
"config" => [@paths[:default], @paths[:other], @paths[:toml]], "config" => [@paths[:default], @paths[:other], @paths[:toml]]
}), ),
Jekyll.configuration( Jekyll.configuration(
test_config.merge( test_config.merge(
{ "config" => [@paths[:default], @paths[:other], @paths[:toml]] } "config" => [@paths[:default], @paths[:other], @paths[:toml]]
) )
) )
) )
@ -404,11 +391,11 @@ class TestConfiguration < JekyllUnitTest
allow(SafeYAML) allow(SafeYAML)
.to receive(:load_file) .to receive(:load_file)
.with(@paths[:default]) .with(@paths[:default])
.and_return({ "baseurl" => "http://example.dev" }) .and_return("baseurl" => "http://example.dev")
allow(SafeYAML) allow(SafeYAML)
.to receive(:load_file) .to receive(:load_file)
.with(@paths[:other]) .with(@paths[:other])
.and_return({ "baseurl" => "http://example.com" }) .and_return("baseurl" => "http://example.com")
allow($stdout) allow($stdout)
.to receive(:puts) .to receive(:puts)
.with("Configuration file: #{@paths[:default]}") .with("Configuration file: #{@paths[:default]}")
@ -416,12 +403,12 @@ class TestConfiguration < JekyllUnitTest
.to receive(:puts) .to receive(:puts)
.with("Configuration file: #{@paths[:other]}") .with("Configuration file: #{@paths[:other]}")
assert_equal \ assert_equal \
site_configuration({ site_configuration(
"baseurl" => "http://example.com", "baseurl" => "http://example.com",
"config" => [@paths[:default], @paths[:other]], "config" => [@paths[:default], @paths[:other]]
}), ),
Jekyll.configuration( Jekyll.configuration(
test_config.merge({ "config" => [@paths[:default], @paths[:other]] }) test_config.merge("config" => [@paths[:default], @paths[:other]])
) )
end end
end end
@ -437,41 +424,41 @@ class TestConfiguration < JekyllUnitTest
conf = Configuration[default_configuration].tap do |c| conf = Configuration[default_configuration].tap do |c|
c["collections"] = ["docs"] c["collections"] = ["docs"]
end end
assert_equal conf.add_default_collections, conf.merge({ assert_equal conf.add_default_collections, conf.merge(
"collections" => { "collections" => {
"docs" => {}, "docs" => {},
"posts" => { "posts" => {
"output" => true, "output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext", "permalink" => "/:categories/:year/:month/:day/:title:output_ext",
}, },
}, }
}) )
end end
should "force collections.posts.output = true" do should "force collections.posts.output = true" do
conf = Configuration[default_configuration].tap do |c| conf = Configuration[default_configuration].tap do |c|
c["collections"] = { "posts" => { "output" => false } } c["collections"] = { "posts" => { "output" => false } }
end end
assert_equal conf.add_default_collections, conf.merge({ assert_equal conf.add_default_collections, conf.merge(
"collections" => { "collections" => {
"posts" => { "posts" => {
"output" => true, "output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext", "permalink" => "/:categories/:year/:month/:day/:title:output_ext",
}, },
}, }
}) )
end end
should "set collections.posts.permalink if it's not set" do should "set collections.posts.permalink if it's not set" do
conf = Configuration[default_configuration] conf = Configuration[default_configuration]
assert_equal conf.add_default_collections, conf.merge({ assert_equal conf.add_default_collections, conf.merge(
"collections" => { "collections" => {
"posts" => { "posts" => {
"output" => true, "output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext", "permalink" => "/:categories/:year/:month/:day/:title:output_ext",
}, },
}, }
}) )
end end
should "leave collections.posts.permalink alone if it is set" do should "leave collections.posts.permalink alone if it is set" do
@ -481,14 +468,14 @@ class TestConfiguration < JekyllUnitTest
"posts" => { "permalink" => posts_permalink }, "posts" => { "permalink" => posts_permalink },
} }
end end
assert_equal conf.add_default_collections, conf.merge({ assert_equal conf.add_default_collections, conf.merge(
"collections" => { "collections" => {
"posts" => { "posts" => {
"output" => true, "output" => true,
"permalink" => posts_permalink, "permalink" => posts_permalink,
}, },
}, }
}) )
end end
end end
@ -504,12 +491,13 @@ class TestConfiguration < JekyllUnitTest
) )
) )
assert_equal( assert_equal(
config["folded_string"], "This string of text will ignore newlines till the next key.\n",
"This string of text will ignore newlines till the next key.\n" config["folded_string"]
) )
assert_equal( assert_equal(
config["clean_folded_string"], "This string of text will ignore newlines till the next key.",
"This string of text will ignore newlines till the next key." config["clean_folded_string"]
) )
end end

View File

@ -73,5 +73,12 @@ class TestConvertible < JekyllUnitTest
end end
refute_match(%r!Invalid permalink!, out) refute_match(%r!Invalid permalink!, out)
end end
should "not parse Liquid if disabled in front matter" do
name = "no_liquid.erb"
@convertible.read_yaml(@base, name)
ret = @convertible.content.strip
assert_equal("{% raw %}{% endraw %}", ret)
end
end end
end end

View File

@ -10,10 +10,10 @@ class TestDoctorCommand < JekyllUnitTest
end end
should "return success on a valid site/page" do should "return success on a valid site/page" do
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => File.join(source_dir, "/_urls_differ_by_case_valid"), "source" => File.join(source_dir, "/_urls_differ_by_case_valid"),
"destination" => dest_dir, "destination" => dest_dir
})) ))
@site.process @site.process
output = capture_stderr do output = capture_stderr do
ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site) ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site)
@ -23,10 +23,10 @@ class TestDoctorCommand < JekyllUnitTest
end end
should "return warning for pages only differing by case" do should "return warning for pages only differing by case" do
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => File.join(source_dir, "/_urls_differ_by_case_invalid"), "source" => File.join(source_dir, "/_urls_differ_by_case_invalid"),
"destination" => dest_dir, "destination" => dest_dir
})) ))
@site.process @site.process
output = capture_stderr do output = capture_stderr do
ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site) ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site)

View File

@ -10,10 +10,9 @@ class TestDocument < JekyllUnitTest
def setup_encoded_document(filename) def setup_encoded_document(filename)
site = fixture_site("collections" => ["encodings"]) site = fixture_site("collections" => ["encodings"])
site.process site.process
Document.new(site.in_source_dir(File.join("_encodings", filename)), { Document.new(site.in_source_dir(File.join("_encodings", filename)),
:site => site, :site => site,
:collection => site.collections["encodings"], :collection => site.collections["encodings"]).tap(&:read)
}).tap(&:read)
end end
def setup_document_with_dates(filename) def setup_document_with_dates(filename)
@ -21,19 +20,18 @@ class TestDocument < JekyllUnitTest
site.process site.process
docs = nil docs = nil
with_env("TZ", "UTC") do with_env("TZ", "UTC") do
docs = Document.new(site.in_source_dir(File.join("_dates", filename)), { docs = Document.new(site.in_source_dir(File.join("_dates", filename)),
:site => site, :site => site,
:collection => site.collections["dates"], :collection => site.collections["dates"]).tap(&:read)
}).tap(&:read)
end end
docs docs
end end
context "a document in a collection" do context "a document in a collection" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["methods"], "collections" => ["methods"]
}) )
@site.process @site.process
@document = @site.collections["methods"].docs.detect do |d| @document = @site.collections["methods"].docs.detect do |d|
d.relative_path == "_methods/configuration.md" d.relative_path == "_methods/configuration.md"
@ -112,7 +110,7 @@ class TestDocument < JekyllUnitTest
context "with YAML ending in three dots" do context "with YAML ending in three dots" do
setup do setup do
@site = fixture_site({ "collections" => ["methods"] }) @site = fixture_site("collections" => ["methods"])
@site.process @site.process
@document = @site.collections["methods"].docs.detect do |d| @document = @site.collections["methods"].docs.detect do |d|
d.relative_path == "_methods/yaml_with_dots.md" d.relative_path == "_methods/yaml_with_dots.md"
@ -126,17 +124,17 @@ class TestDocument < JekyllUnitTest
end end
should "output the collection name in the #to_liquid method" do should "output the collection name in the #to_liquid method" do
assert_equal @document.to_liquid["collection"], "methods" assert_equal "methods", @document.to_liquid["collection"]
end end
should "output its relative path as path in Liquid" do should "output its relative path as path in Liquid" do
assert_equal @document.to_liquid["path"], "_methods/configuration.md" assert_equal "_methods/configuration.md", @document.to_liquid["path"]
end end
end end
context "a document as part of a collection with front matter defaults" do context "a document as part of a collection with front matter defaults" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["slides"], "collections" => ["slides"],
"defaults" => [{ "defaults" => [{
"scope" => { "path" => "", "type" => "slides" }, "scope" => { "path" => "", "type" => "slides" },
@ -145,8 +143,8 @@ class TestDocument < JekyllUnitTest
"key" => "myval", "key" => "myval",
}, },
}, },
},], },]
}) )
@site.process @site.process
@document = @site.collections["slides"].docs.select { |d| d.is_a?(Document) }.first @document = @site.collections["slides"].docs.select { |d| d.is_a?(Document) }.first
end end
@ -166,7 +164,7 @@ class TestDocument < JekyllUnitTest
context "a document as part of a collection with overridden default values" do context "a document as part of a collection with overridden default values" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["slides"], "collections" => ["slides"],
"defaults" => [{ "defaults" => [{
"scope" => { "path" => "", "type" => "slides" }, "scope" => { "path" => "", "type" => "slides" },
@ -176,8 +174,8 @@ class TestDocument < JekyllUnitTest
"test2" => "default1", "test2" => "default1",
}, },
}, },
},], },]
}) )
@site.process @site.process
@document = @site.collections["slides"].docs[1] @document = @site.collections["slides"].docs[1]
end end
@ -194,7 +192,7 @@ class TestDocument < JekyllUnitTest
context "a document as part of a collection with valid path" do context "a document as part of a collection with valid path" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["slides"], "collections" => ["slides"],
"defaults" => [{ "defaults" => [{
"scope" => { "path" => "_slides", "type" => "slides" }, "scope" => { "path" => "_slides", "type" => "slides" },
@ -203,8 +201,8 @@ class TestDocument < JekyllUnitTest
"key" => "value123", "key" => "value123",
}, },
}, },
},], },]
}) )
@site.process @site.process
@document = @site.collections["slides"].docs.first @document = @site.collections["slides"].docs.first
end end
@ -218,7 +216,7 @@ class TestDocument < JekyllUnitTest
context "a document as part of a collection with invalid path" do context "a document as part of a collection with invalid path" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["slides"], "collections" => ["slides"],
"defaults" => [{ "defaults" => [{
"scope" => { "path" => "somepath", "type" => "slides" }, "scope" => { "path" => "somepath", "type" => "slides" },
@ -227,8 +225,8 @@ class TestDocument < JekyllUnitTest
"key" => "myval", "key" => "myval",
}, },
}, },
},], },]
}) )
@site.process @site.process
@document = @site.collections["slides"].docs.first @document = @site.collections["slides"].docs.first
end end
@ -242,9 +240,9 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with a custom permalink" do context "a document in a collection with a custom permalink" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["slides"], "collections" => ["slides"]
}) )
@site.process @site.process
@document = @site.collections["slides"].docs[2] @document = @site.collections["slides"].docs[2]
@dest_file = dest_dir("slide/3/index.html") @dest_file = dest_dir("slide/3/index.html")
@ -261,15 +259,15 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with custom filename permalinks" do context "a document in a collection with custom filename permalinks" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
"permalink" => "/slides/test/:name", "permalink" => "/slides/test/:name",
}, },
}, },
"permalink" => "pretty", "permalink" => "pretty"
}) )
@site.process @site.process
@document = @site.collections["slides"].docs[0] @document = @site.collections["slides"].docs[0]
@dest_file = dest_dir("slides/test/example-slide-1.html") @dest_file = dest_dir("slides/test/example-slide-1.html")
@ -290,13 +288,13 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with pretty permalink style" do context "a document in a collection with pretty permalink style" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.permalink_style = :pretty @site.permalink_style = :pretty
@site.process @site.process
@document = @site.collections["slides"].docs[0] @document = @site.collections["slides"].docs[0]
@ -314,13 +312,13 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with cased file name" do context "a document in a collection with cased file name" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.permalink_style = :pretty @site.permalink_style = :pretty
@site.process @site.process
@document = @site.collections["slides"].docs[7] @document = @site.collections["slides"].docs[7]
@ -334,13 +332,13 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with cased file name" do context "a document in a collection with cased file name" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.process @site.process
@document = @site.collections["slides"].docs[6] @document = @site.collections["slides"].docs[6]
@dest_file = dest_dir("slides/example-slide-7.php") @dest_file = dest_dir("slides/example-slide-7.php")
@ -365,14 +363,14 @@ class TestDocument < JekyllUnitTest
context "documents in a collection with custom title permalinks" do context "documents in a collection with custom title permalinks" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
"permalink" => "/slides/:title", "permalink" => "/slides/:title",
}, },
}, }
}) )
@site.process @site.process
@document = @site.collections["slides"].docs[3] @document = @site.collections["slides"].docs[3]
@document_without_slug = @site.collections["slides"].docs[4] @document_without_slug = @site.collections["slides"].docs[4]
@ -410,9 +408,9 @@ class TestDocument < JekyllUnitTest
context "document with a permalink with dots & a trailing slash" do context "document with a permalink with dots & a trailing slash" do
setup do setup do
@site = fixture_site({ "collections" => { @site = fixture_site("collections" => {
"with.dots" => { "output" => true }, "with.dots" => { "output" => true },
}, }) })
@site.process @site.process
@document = @site.collections["with.dots"].docs.last @document = @site.collections["with.dots"].docs.last
@dest_file = dest_dir("with.dots", "permalink.with.slash.tho", "index.html") @dest_file = dest_dir("with.dots", "permalink.with.slash.tho", "index.html")
@ -433,13 +431,13 @@ class TestDocument < JekyllUnitTest
context "documents in a collection" do context "documents in a collection" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.process @site.process
@files = @site.collections["slides"].docs @files = @site.collections["slides"].docs
end end
@ -465,13 +463,13 @@ class TestDocument < JekyllUnitTest
context "a static file in a collection" do context "a static file in a collection" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"slides" => { "slides" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.process @site.process
@document = @site.collections["slides"].files.find do |doc| @document = @site.collections["slides"].files.find do |doc|
doc.relative_path == "_slides/octojekyll.png" doc.relative_path == "_slides/octojekyll.png"
@ -498,13 +496,13 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with non-alphabetic file name" do context "a document in a collection with non-alphabetic file name" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.process @site.process
@document = @site.collections["methods"].docs.find do |doc| @document = @site.collections["methods"].docs.find do |doc|
doc.relative_path == "_methods/escape-+ #%20[].md" doc.relative_path == "_methods/escape-+ #%20[].md"
@ -527,13 +525,13 @@ class TestDocument < JekyllUnitTest
context "a document in a collection with dash-separated numeric file name" do context "a document in a collection with dash-separated numeric file name" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"output" => true, "output" => true,
}, },
}, }
}) )
@site.process @site.process
@document = @site.collections["methods"].docs.find do |doc| @document = @site.collections["methods"].docs.find do |doc|
doc.relative_path == "_methods/3940394-21-9393050-fifif1323-test.md" doc.relative_path == "_methods/3940394-21-9393050-fifif1323-test.md"

View File

@ -17,9 +17,9 @@ end
class TestDrop < JekyllUnitTest class TestDrop < JekyllUnitTest
context "Drops" do context "Drops" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["methods"], "collections" => ["methods"]
}) )
@site.process @site.process
@document = @site.collections["methods"].docs.detect do |d| @document = @site.collections["methods"].docs.detect do |d|
d.relative_path == "_methods/configuration.md" d.relative_path == "_methods/configuration.md"

View File

@ -4,10 +4,9 @@ require "helper"
class TestExcerpt < JekyllUnitTest class TestExcerpt < JekyllUnitTest
def setup_post(file) def setup_post(file)
Document.new(@site.in_source_dir(File.join("_posts", file)), { Document.new(@site.in_source_dir(File.join("_posts", file)),
:site => @site, :site => @site,
:collection => @site.posts, :collection => @site.posts).tap(&:read)
}).tap(&:read)
end end
def do_render(document) def do_render(document)

View File

@ -28,7 +28,7 @@ class TestExcerptDrop < JekyllUnitTest
should "inherit the layout for the drop but not the excerpt" do should "inherit the layout for the drop but not the excerpt" do
assert_nil @excerpt.data["layout"] assert_nil @excerpt.data["layout"]
assert_equal @excerpt_drop["layout"], @doc_drop["layout"] assert_equal @doc_drop["layout"], @excerpt_drop["layout"]
end end
should "be inspectable" do should "be inspectable" do
@ -36,7 +36,7 @@ class TestExcerptDrop < JekyllUnitTest
end end
should "inherit values from the document" do should "inherit values from the document" do
assert_equal @excerpt_drop.keys.sort, @doc_drop.keys.sort assert_equal @doc_drop.keys.sort, @excerpt_drop.keys.sort
end end
end end
end end

View File

@ -9,7 +9,7 @@ class TestFilters < JekyllUnitTest
def initialize(opts = {}) def initialize(opts = {})
@site = Jekyll::Site.new(opts.merge("skip_config_files" => true)) @site = Jekyll::Site.new(opts.merge("skip_config_files" => true))
@context = Liquid::Context.new(@site.site_payload, {}, { :site => @site }) @context = Liquid::Context.new(@site.site_payload, {}, :site => @site)
end end
end end
@ -37,12 +37,12 @@ class TestFilters < JekyllUnitTest
context "filters" do context "filters" do
setup do setup do
@sample_time = Time.utc(2013, 3, 27, 11, 22, 33) @sample_time = Time.utc(2013, 3, 27, 11, 22, 33)
@filter = make_filter_mock({ @filter = make_filter_mock(
"timezone" => "UTC", "timezone" => "UTC",
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base", "baseurl" => "/base",
"dont_show_posts_before" => @sample_time, "dont_show_posts_before" => @sample_time
}) )
@sample_date = Date.parse("2013-03-02") @sample_date = Date.parse("2013-03-02")
@time_as_string = "September 11, 2001 12:46:30 -0000" @time_as_string = "September 11, 2001 12:46:30 -0000"
@time_as_numeric = 1_399_680_607 @time_as_numeric = 1_399_680_607
@ -88,7 +88,7 @@ class TestFilters < JekyllUnitTest
end end
should "escapes special characters when configured to do so" do should "escapes special characters when configured to do so" do
kramdown = make_filter_mock({ :kramdown => { :entity_output => :symbolic } }) kramdown = make_filter_mock(:kramdown => { :entity_output => :symbolic })
assert_equal( assert_equal(
"&ldquo;This filter&rsquo;s test&hellip;&rdquo;", "&ldquo;This filter&rsquo;s test&hellip;&rdquo;",
kramdown.smartify(%q{"This filter's test..."}) kramdown.smartify(%q{"This filter's test..."})
@ -406,82 +406,82 @@ class TestFilters < JekyllUnitTest
should "ensure the leading slash for the baseurl" do should "ensure the leading slash for the baseurl" do
page_url = "about/my_favorite_page/" page_url = "about/my_favorite_page/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "base", "baseurl" => "base"
}) )
assert_equal "http://example.com/base/#{page_url}", filter.absolute_url(page_url) assert_equal "http://example.com/base/#{page_url}", filter.absolute_url(page_url)
end end
should "be ok with a blank but present 'url'" do should "be ok with a blank but present 'url'" do
page_url = "about/my_favorite_page/" page_url = "about/my_favorite_page/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "", "url" => "",
"baseurl" => "base", "baseurl" => "base"
}) )
assert_equal "/base/#{page_url}", filter.absolute_url(page_url) assert_equal "/base/#{page_url}", filter.absolute_url(page_url)
end end
should "be ok with a nil 'url'" do should "be ok with a nil 'url'" do
page_url = "about/my_favorite_page/" page_url = "about/my_favorite_page/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => nil, "url" => nil,
"baseurl" => "base", "baseurl" => "base"
}) )
assert_equal "/base/#{page_url}", filter.absolute_url(page_url) assert_equal "/base/#{page_url}", filter.absolute_url(page_url)
end end
should "be ok with a nil 'baseurl'" do should "be ok with a nil 'baseurl'" do
page_url = "about/my_favorite_page/" page_url = "about/my_favorite_page/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => nil, "baseurl" => nil
}) )
assert_equal "http://example.com/#{page_url}", filter.absolute_url(page_url) assert_equal "http://example.com/#{page_url}", filter.absolute_url(page_url)
end end
should "not prepend a forward slash if input is empty" do should "not prepend a forward slash if input is empty" do
page_url = "" page_url = ""
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base", "baseurl" => "/base"
}) )
assert_equal "http://example.com/base", filter.absolute_url(page_url) assert_equal "http://example.com/base", filter.absolute_url(page_url)
end end
should "not append a forward slash if input is '/'" do should "not append a forward slash if input is '/'" do
page_url = "/" page_url = "/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base", "baseurl" => "/base"
}) )
assert_equal "http://example.com/base/", filter.absolute_url(page_url) assert_equal "http://example.com/base/", filter.absolute_url(page_url)
end end
should "not append a forward slash if input is '/' and nil 'baseurl'" do should "not append a forward slash if input is '/' and nil 'baseurl'" do
page_url = "/" page_url = "/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => nil, "baseurl" => nil
}) )
assert_equal "http://example.com/", filter.absolute_url(page_url) assert_equal "http://example.com/", filter.absolute_url(page_url)
end end
should "not append a forward slash if both input and baseurl are simply '/'" do should "not append a forward slash if both input and baseurl are simply '/'" do
page_url = "/" page_url = "/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/", "baseurl" => "/"
}) )
assert_equal "http://example.com/", filter.absolute_url(page_url) assert_equal "http://example.com/", filter.absolute_url(page_url)
end end
should "normalize international URLs" do should "normalize international URLs" do
page_url = "" page_url = ""
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://ümlaut.example.org/", "url" => "http://ümlaut.example.org/",
"baseurl" => nil, "baseurl" => nil
}) )
assert_equal "http://xn--mlaut-jva.example.org/", filter.absolute_url(page_url) assert_equal "http://xn--mlaut-jva.example.org/", filter.absolute_url(page_url)
end end
@ -492,19 +492,19 @@ class TestFilters < JekyllUnitTest
should "transform the input URL to a string" do should "transform the input URL to a string" do
page_url = "/my-page.html" page_url = "/my-page.html"
filter = make_filter_mock({ "url" => Value.new(proc { "http://example.org" }) }) filter = make_filter_mock("url" => Value.new(proc { "http://example.org" }))
assert_equal "http://example.org#{page_url}", filter.absolute_url(page_url) assert_equal "http://example.org#{page_url}", filter.absolute_url(page_url)
end end
should "not raise a TypeError when passed a hash" do should "not raise a TypeError when passed a hash" do
assert @filter.absolute_url({ "foo" => "bar" }) assert @filter.absolute_url("foo" => "bar")
end end
context "with a document" do context "with a document" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["methods"], "collections" => ["methods"]
}) )
@site.process @site.process
@document = @site.collections["methods"].docs.detect do |d| @document = @site.collections["methods"].docs.detect do |d|
d.relative_path == "_methods/configuration.md" d.relative_path == "_methods/configuration.md"
@ -531,7 +531,7 @@ class TestFilters < JekyllUnitTest
should "ensure the leading slash for the baseurl" do should "ensure the leading slash for the baseurl" do
page_url = "about/my_favorite_page/" page_url = "about/my_favorite_page/"
filter = make_filter_mock({ "baseurl" => "base" }) filter = make_filter_mock("baseurl" => "base")
assert_equal "/base/#{page_url}", filter.relative_url(page_url) assert_equal "/base/#{page_url}", filter.relative_url(page_url)
end end
@ -542,51 +542,51 @@ class TestFilters < JekyllUnitTest
should "be ok with a nil 'baseurl'" do should "be ok with a nil 'baseurl'" do
page_url = "about/my_favorite_page/" page_url = "about/my_favorite_page/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => nil, "baseurl" => nil
}) )
assert_equal "/#{page_url}", filter.relative_url(page_url) assert_equal "/#{page_url}", filter.relative_url(page_url)
end end
should "not prepend a forward slash if input is empty" do should "not prepend a forward slash if input is empty" do
page_url = "" page_url = ""
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base", "baseurl" => "/base"
}) )
assert_equal "/base", filter.relative_url(page_url) assert_equal "/base", filter.relative_url(page_url)
end end
should "not prepend a forward slash if baseurl ends with a single '/'" do should "not prepend a forward slash if baseurl ends with a single '/'" do
page_url = "/css/main.css" page_url = "/css/main.css"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base/", "baseurl" => "/base/"
}) )
assert_equal "/base/css/main.css", filter.relative_url(page_url) assert_equal "/base/css/main.css", filter.relative_url(page_url)
end end
should "not return valid URI if baseurl ends with multiple '/'" do should "not return valid URI if baseurl ends with multiple '/'" do
page_url = "/css/main.css" page_url = "/css/main.css"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base//", "baseurl" => "/base//"
}) )
refute_equal "/base/css/main.css", filter.relative_url(page_url) refute_equal "/base/css/main.css", filter.relative_url(page_url)
end end
should "not prepend a forward slash if both input and baseurl are simply '/'" do should "not prepend a forward slash if both input and baseurl are simply '/'" do
page_url = "/" page_url = "/"
filter = make_filter_mock({ filter = make_filter_mock(
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/", "baseurl" => "/"
}) )
assert_equal "/", filter.relative_url(page_url) assert_equal "/", filter.relative_url(page_url)
end end
should "not return the url by reference" do should "not return the url by reference" do
filter = make_filter_mock({ :baseurl => nil }) filter = make_filter_mock(:baseurl => nil)
page = Page.new(filter.site, test_dir("fixtures"), "", "front_matter.erb") page = Page.new(filter.site, test_dir("fixtures"), "", "front_matter.erb")
assert_equal "/front_matter.erb", page.url assert_equal "/front_matter.erb", page.url
url = filter.relative_url(page.url) url = filter.relative_url(page.url)
@ -596,7 +596,7 @@ class TestFilters < JekyllUnitTest
should "transform the input baseurl to a string" do should "transform the input baseurl to a string" do
page_url = "/my-page.html" page_url = "/my-page.html"
filter = make_filter_mock({ "baseurl" => Value.new(proc { "/baseurl/" }) }) filter = make_filter_mock("baseurl" => Value.new(proc { "/baseurl/" }))
assert_equal "/baseurl#{page_url}", filter.relative_url(page_url) assert_equal "/baseurl#{page_url}", filter.relative_url(page_url)
end end
@ -640,7 +640,7 @@ class TestFilters < JekyllUnitTest
context "jsonify filter" do context "jsonify filter" do
should "convert hash to json" do should "convert hash to json" do
assert_equal "{\"age\":18}", @filter.jsonify({ :age => 18 }) assert_equal "{\"age\":18}", @filter.jsonify(:age => 18)
end end
should "convert array to json" do should "convert array to json" do
@ -687,10 +687,11 @@ class TestFilters < JekyllUnitTest
should "convert drop with drops to json" do should "convert drop with drops to json" do
@filter.site.read @filter.site.read
actual = @filter.jsonify(@filter.site.to_liquid) actual = @filter.jsonify(@filter.site.to_liquid)
assert_equal JSON.parse(actual)["jekyll"], { expected = {
"environment" => "development", "environment" => "development",
"version" => Jekyll::VERSION, "version" => Jekyll::VERSION,
} }
assert_equal expected, JSON.parse(actual)["jekyll"]
end end
# rubocop:disable Style/StructInheritance # rubocop:disable Style/StructInheritance
@ -704,7 +705,7 @@ class TestFilters < JekyllUnitTest
{ {
"name" => name, "name" => name,
:v => 1, :v => 1,
:thing => M.new({ :kay => "jewelers" }), :thing => M.new(:kay => "jewelers"),
:stuff => true, :stuff => true,
} }
end end
@ -1074,10 +1075,6 @@ class TestFilters < JekyllUnitTest
end end
should "return sorted strings" do should "return sorted strings" do
assert_equal %w(10 2), @filter.sort(%w(10 2)) assert_equal %w(10 2), @filter.sort(%w(10 2))
assert_equal(
[{ "a" => "10" }, { "a" => "2" }],
@filter.sort([{ "a" => "10" }, { "a" => "2" }], "a")
)
assert_equal %w(FOO Foo foo), @filter.sort(%w(foo Foo FOO)) assert_equal %w(FOO Foo foo), @filter.sort(%w(foo Foo FOO))
assert_equal %w(_foo foo foo_), @filter.sort(%w(foo_ _foo foo)) assert_equal %w(_foo foo foo_), @filter.sort(%w(foo_ _foo foo))
# Cyrillic # Cyrillic
@ -1090,6 +1087,18 @@ class TestFilters < JekyllUnitTest
assert_equal [{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }], assert_equal [{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }],
@filter.sort([{ "a" => 4 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a") @filter.sort([{ "a" => 4 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a")
end end
should "return sorted by property array with numeric strings sorted as numbers" do
assert_equal([{ "a" => ".5" }, { "a" => "0.65" }, { "a" => "10" }],
@filter.sort([{ "a" => "10" }, { "a" => ".5" }, { "a" => "0.65" }], "a"))
end
should "return sorted by property array with numeric strings first" do
assert_equal([{ "a" => ".5" }, { "a" => "0.6" }, { "a" => "twelve" }],
@filter.sort([{ "a" => "twelve" }, { "a" => ".5" }, { "a" => "0.6" }], "a"))
end
should "return sorted by property array with numbers and strings " do
assert_equal([{ "a" => "1" }, { "a" => "1abc" }, { "a" => "20" }],
@filter.sort([{ "a" => "20" }, { "a" => "1" }, { "a" => "1abc" }], "a"))
end
should "return sorted by property array with nils first" do should "return sorted by property array with nils first" do
ary = [{ "a" => 2 }, { "b" => 1 }, { "a" => 1 }] ary = [{ "a" => 2 }, { "b" => 1 }, { "a" => 1 }]
assert_equal [{ "b" => 1 }, { "a" => 1 }, { "a" => 2 }], @filter.sort(ary, "a") assert_equal [{ "b" => 1 }, { "a" => 1 }, { "a" => 2 }], @filter.sort(ary, "a")
@ -1131,7 +1140,7 @@ class TestFilters < JekyllUnitTest
context "inspect filter" do context "inspect filter" do
should "return a HTML-escaped string representation of an object" do should "return a HTML-escaped string representation of an object" do
assert_equal "{&quot;&lt;a&gt;&quot;=&gt;1}", @filter.inspect({ "<a>" => 1 }) assert_equal "{&quot;&lt;a&gt;&quot;=&gt;1}", @filter.inspect("<a>" => 1)
end end
should "quote strings" do should "quote strings" do

View File

@ -5,7 +5,7 @@ require "helper"
class TestFrontMatterDefaults < JekyllUnitTest class TestFrontMatterDefaults < JekyllUnitTest
context "A site with full front matter defaults" do context "A site with full front matter defaults" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "contacts", "path" => "contacts",
@ -14,15 +14,15 @@ class TestFrontMatterDefaults < JekyllUnitTest
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@output = capture_output { @site.process } @output = capture_output { @site.process }
@affected = @site.pages.find { |page| page.relative_path == "contacts/bar.html" } @affected = @site.pages.find { |page| page.relative_path == "contacts/bar.html" }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" } @not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
end end
should "affect only the specified path and type" do should "affect only the specified path and type" do
assert_equal @affected.data["key"], "val" assert_equal "val", @affected.data["key"]
assert_nil @not_affected.data["key"] assert_nil @not_affected.data["key"]
end end
@ -33,7 +33,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with full front matter defaults (glob)" do context "A site with full front matter defaults (glob)" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "contacts/*.html", "path" => "contacts/*.html",
@ -42,15 +42,15 @@ class TestFrontMatterDefaults < JekyllUnitTest
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@output = capture_output { @site.process } @output = capture_output { @site.process }
@affected = @site.pages.find { |page| page.relative_path == "contacts/bar.html" } @affected = @site.pages.find { |page| page.relative_path == "contacts/bar.html" }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" } @not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
end end
should "affect only the specified path and type" do should "affect only the specified path and type" do
assert_equal @affected.data["key"], "val" assert_equal "val", @affected.data["key"]
assert_nil @not_affected.data["key"] assert_nil @not_affected.data["key"]
end end
@ -61,7 +61,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter type pages and an extension" do context "A site with front matter type pages and an extension" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "index.html", "path" => "index.html",
@ -69,8 +69,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@site.process @site.process
@affected = @site.pages.find { |page| page.relative_path == "index.html" } @affected = @site.pages.find { |page| page.relative_path == "index.html" }
@ -78,14 +78,14 @@ class TestFrontMatterDefaults < JekyllUnitTest
end end
should "affect only the specified path" do should "affect only the specified path" do
assert_equal @affected.data["key"], "val" assert_equal "val", @affected.data["key"]
assert_nil @not_affected.data["key"] assert_nil @not_affected.data["key"]
end end
end end
context "A site with front matter defaults with no type" do context "A site with front matter defaults with no type" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"path" => "win", "path" => "win",
@ -93,8 +93,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@site.process @site.process
@affected = @site.posts.docs.find { |page| page.relative_path =~ %r!win\/! } @affected = @site.posts.docs.find { |page| page.relative_path =~ %r!win\/! }
@ -102,14 +102,14 @@ class TestFrontMatterDefaults < JekyllUnitTest
end end
should "affect only the specified path and all types" do should "affect only the specified path and all types" do
assert_equal @affected.data["key"], "val" assert_equal "val", @affected.data["key"]
assert_nil @not_affected.data["key"] assert_nil @not_affected.data["key"]
end end
end end
context "A site with front matter defaults with no path and a deprecated type" do context "A site with front matter defaults with no path and a deprecated type" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"type" => "page", "type" => "page",
@ -117,8 +117,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@ -134,7 +134,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path" do context "A site with front matter defaults with no path" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
"type" => "pages", "type" => "pages",
@ -142,8 +142,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts.docs @not_affected = @site.posts.docs
@ -158,15 +158,15 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path or type" do context "A site with front matter defaults with no path or type" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"scope" => { "scope" => {
}, },
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts @not_affected = @site.posts
@ -180,13 +180,13 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no scope" do context "A site with front matter defaults with no scope" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"defaults" => [{ "defaults" => [{
"values" => { "values" => {
"key" => "val", "key" => "val",
}, },
},], },]
}) )
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts @not_affected = @site.posts
@ -200,15 +200,15 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with quoted date" do context "A site with front matter defaults with quoted date" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"defaults" => [{ "defaults" => [{
"values" => { "values" => {
"date" => "2015-01-01 00:00:01", "date" => "2015-01-01 00:00:01",
}, },
},], },]
})) ))
end end
should "not raise error" do should "not raise error" do

View File

@ -70,7 +70,7 @@ class TestGeneratedSite < JekyllUnitTest
time_regexp = "\\d+:\\d+" time_regexp = "\\d+:\\d+"
# #
# adding a pipe character at the beginning preserves formatting with newlines # adding a pipe character at the beginning preserves formatting with newlines
expected_output = Regexp.new <<-OUTPUT expected_output = Regexp.new <<~OUTPUT
| - /css/screen.css last edited at #{time_regexp} with extname .css | - /css/screen.css last edited at #{time_regexp} with extname .css
- /pgp.key last edited at #{time_regexp} with extname .key - /pgp.key last edited at #{time_regexp} with extname .key
- /products.yml last edited at #{time_regexp} with extname .yml - /products.yml last edited at #{time_regexp} with extname .yml

View File

@ -142,7 +142,8 @@ class TestKramdown < JekyllUnitTest
should "move coderay to syntax_highlighter_opts" do should "move coderay to syntax_highlighter_opts" do
original = Kramdown::Document.method(:new) original = Kramdown::Document.method(:new)
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, { markdown = Converters::Markdown.new(
Utils.deep_merge_hashes(@config,
"higlighter" => nil, "higlighter" => nil,
"markdown" => "kramdown", "markdown" => "kramdown",
"kramdown" => { "kramdown" => {
@ -150,11 +151,11 @@ class TestKramdown < JekyllUnitTest
"coderay" => { "coderay" => {
"hello" => "world", "hello" => "world",
}, },
}, })
})) )
expect(Kramdown::Document).to receive(:new) do |arg1, hash| expect(Kramdown::Document).to receive(:new) do |arg1, hash|
assert_equal hash["syntax_highlighter_opts"]["hello"], "world" assert_equal "world", hash["syntax_highlighter_opts"]["hello"]
original.call(arg1, hash) original.call(arg1, hash)
end end

View File

@ -5,8 +5,8 @@ require "helper"
class TestLayoutReader < JekyllUnitTest class TestLayoutReader < JekyllUnitTest
context "reading layouts" do context "reading layouts" do
setup do setup do
config = Jekyll::Configuration::DEFAULTS.merge({ "source" => source_dir, config = Jekyll::Configuration::DEFAULTS.merge("source" => source_dir,
"destination" => dest_dir, }) "destination" => dest_dir)
@site = fixture_site(config) @site = fixture_site(config)
end end

View File

@ -22,11 +22,11 @@ class TestLiquidExtensions < JekyllUnitTest
end end
should "extract the var properly" do should "extract the var properly" do
assert_equal @template.render({ "page" => { "name" => "tobi" } }), "hi tobi" assert_equal "hi tobi", @template.render("page" => { "name" => "tobi" })
end end
should "return the variable name if the value isn't there" do should "return the variable name if the value isn't there" do
assert_equal @template.render({ "page" => { "title" => "tobi" } }), "hi page.name" assert_equal "hi page.name", @template.render("page" => { "title" => "tobi" })
end end
end end
end end

View File

@ -57,7 +57,7 @@ class TestNewCommand < JekyllUnitTest
capture_output { Jekyll::Commands::New.process(@args) } capture_output { Jekyll::Commands::New.process(@args) }
new_site_files = dir_contents(@full_path).reject do |f| new_site_files = dir_contents(@full_path).reject do |f|
File.extname(f) == ".markdown" f.end_with?("welcome-to-jekyll.markdown")
end end
assert_same_elements static_template_files, new_site_files assert_same_elements static_template_files, new_site_files

View File

@ -22,11 +22,11 @@ class TestPage < JekyllUnitTest
context "A Page" do context "A Page" do
setup do setup do
clear_dest clear_dest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"skip_config_files" => true, "skip_config_files" => true
})) ))
end end
context "processing pages" do context "processing pages" do

View File

@ -21,11 +21,11 @@ class TestPageWithoutAFile < JekyllUnitTest
context "A PageWithoutAFile" do context "A PageWithoutAFile" do
setup do setup do
clear_dest clear_dest
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"skip_config_files" => true, "skip_config_files" => true
})) ))
end end
context "with default site configuration" do context "with default site configuration" do
@ -41,6 +41,10 @@ class TestPageWithoutAFile < JekyllUnitTest
should "have basic attributes defined in it" do should "have basic attributes defined in it" do
regular_page = setup_page("properties.html", :klass => Page) regular_page = setup_page("properties.html", :klass => Page)
# assert a couple of attributes accessible in a regular Jekyll::Page instance
assert_equal "All the properties.\n", regular_page["content"]
assert_equal "properties.html", regular_page["name"]
basic_attrs = %w(dir name path url) basic_attrs = %w(dir name path url)
attrs = { attrs = {
"content" => "All the properties.\n", "content" => "All the properties.\n",
@ -56,13 +60,13 @@ class TestPageWithoutAFile < JekyllUnitTest
"url" => "/properties.html", "url" => "/properties.html",
} }
attrs.each do |prop, value| attrs.each do |prop, value|
# assert the props being accessible in a Jekyll::Page instance # assert that all attributes (of a Jekyll::PageWithoutAFile instance) other than
assert_equal "All the properties.\n", regular_page["content"] # "dir", "name", "path", "url" are `nil`.
assert_equal "properties.html", regular_page["name"] # For example, @page[dir] should be "/" but @page[content] or @page[layout], should
# simply be nil.
# assert differences with Jekyll::PageWithoutAFile instance #
if basic_attrs.include?(prop) if basic_attrs.include?(prop)
assert_equal @page[prop], value, "For <page[\"#{prop}\"]>:" assert_equal value, @page[prop], "For Jekyll::PageWithoutAFile attribute '#{prop}':"
else else
assert_nil @page[prop] assert_nil @page[prop]
end end

View File

@ -68,9 +68,9 @@ class TestPluginManager < JekyllUnitTest
end end
should "require plugin files" do should "require plugin files" do
site = double({ :safe => false, site = double(:safe => false,
:config => { "plugins_dir" => "_plugins" }, :config => { "plugins_dir" => "_plugins" },
:in_source_dir => "/tmp/", }) :in_source_dir => "/tmp/")
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(Jekyll::External).to receive(:require_with_graceful_fail) expect(Jekyll::External).to receive(:require_with_graceful_fail)
@ -80,7 +80,7 @@ class TestPluginManager < JekyllUnitTest
context "site is marked as safe" do context "site is marked as safe" do
should "allow plugins if they are whitelisted" do should "allow plugins if they are whitelisted" do
site = double({ :safe => true, :config => { "whitelist" => ["jemoji"] } }) site = double(:safe => true, :config => { "whitelist" => ["jemoji"] })
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
assert plugin_manager.plugin_allowed?("jemoji") assert plugin_manager.plugin_allowed?("jemoji")
@ -88,7 +88,7 @@ class TestPluginManager < JekyllUnitTest
end end
should "not require plugin files" do should "not require plugin files" do
site = double({ :safe => true }) site = double(:safe => true)
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(Jekyll::External).to_not receive(:require_with_graceful_fail) expect(Jekyll::External).to_not receive(:require_with_graceful_fail)
@ -98,12 +98,12 @@ class TestPluginManager < JekyllUnitTest
context "plugins_dir is set to the default" do context "plugins_dir is set to the default" do
should "call site's in_source_dir" do should "call site's in_source_dir" do
site = double({ site = double(
:config => { :config => {
"plugins_dir" => Jekyll::Configuration::DEFAULTS["plugins_dir"], "plugins_dir" => Jekyll::Configuration::DEFAULTS["plugins_dir"],
}, },
:in_source_dir => "/tmp/", :in_source_dir => "/tmp/"
}) )
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(site).to receive(:in_source_dir).with("_plugins") expect(site).to receive(:in_source_dir).with("_plugins")
@ -113,7 +113,7 @@ class TestPluginManager < JekyllUnitTest
context "plugins_dir is set to a different dir" do context "plugins_dir is set to a different dir" do
should "expand plugin path" do should "expand plugin path" do
site = double({ :config => { "plugins_dir" => "some_other_plugins_path" } }) site = double(:config => { "plugins_dir" => "some_other_plugins_path" })
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(File).to receive(:expand_path).with("some_other_plugins_path") expect(File).to receive(:expand_path).with("some_other_plugins_path")
@ -123,7 +123,7 @@ class TestPluginManager < JekyllUnitTest
context "`paginate` config is activated" do context "`paginate` config is activated" do
should "print deprecation warning if jekyll-paginate is not present" do should "print deprecation warning if jekyll-paginate is not present" do
site = double({ :config => { "paginate" => true } }) site = double(:config => { "paginate" => true })
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(Jekyll::Deprecator).to( expect(Jekyll::Deprecator).to(
@ -133,9 +133,9 @@ class TestPluginManager < JekyllUnitTest
end end
should "print no deprecation warning if jekyll-paginate is present" do should "print no deprecation warning if jekyll-paginate is present" do
site = double({ site = double(
:config => { "paginate" => true, "plugins" => ["jekyll-paginate"] }, :config => { "paginate" => true, "plugins" => ["jekyll-paginate"] }
}) )
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(Jekyll::Deprecator).to_not receive(:deprecation_message) expect(Jekyll::Deprecator).to_not receive(:deprecation_message)
@ -144,10 +144,10 @@ class TestPluginManager < JekyllUnitTest
end end
should "conscientious require" do should "conscientious require" do
site = double({ site = double(
:config => { "theme" => "test-dependency-theme" }, :config => { "theme" => "test-dependency-theme" },
:in_dest_dir => "/tmp/_site/", :in_dest_dir => "/tmp/_site/"
}) )
plugin_manager = PluginManager.new(site) plugin_manager = PluginManager.new(site)
expect(site).to receive(:theme).and_return(true) expect(site).to receive(:theme).and_return(true)

View File

@ -7,14 +7,14 @@ class TestRegenerator < JekyllUnitTest
setup do setup do
FileUtils.rm_rf(source_dir(".jekyll-metadata")) FileUtils.rm_rf(source_dir(".jekyll-metadata"))
@site = fixture_site({ @site = fixture_site(
"collections" => { "collections" => {
"methods" => { "methods" => {
"output" => true, "output" => true,
}, },
}, },
"incremental" => true, "incremental" => true
}) )
@site.read @site.read
@page = @site.pages.first @page = @site.pages.first
@ -93,9 +93,9 @@ class TestRegenerator < JekyllUnitTest
context "The site regenerator" do context "The site regenerator" do
setup do setup do
FileUtils.rm_rf(source_dir(".jekyll-metadata")) FileUtils.rm_rf(source_dir(".jekyll-metadata"))
@site = fixture_site({ @site = fixture_site(
"incremental" => true, "incremental" => true
}) )
@site.read @site.read
@post = @site.posts.first @post = @site.posts.first
@ -128,11 +128,11 @@ class TestRegenerator < JekyllUnitTest
setup do setup do
FileUtils.rm_rf(source_dir(".jekyll-metadata")) FileUtils.rm_rf(source_dir(".jekyll-metadata"))
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"incremental" => true, "incremental" => true
})) ))
@site.process @site.process
@path = @site.in_source_dir(@site.pages.first.path) @path = @site.in_source_dir(@site.pages.first.path)
@ -153,7 +153,8 @@ class TestRegenerator < JekyllUnitTest
assert @regenerator.cache[@path] assert @regenerator.cache[@path]
@regenerator.clear_cache @regenerator.clear_cache
assert_equal @regenerator.cache, {} expected = {}
assert_equal expected, @regenerator.cache
end end
should "write to the metadata file" do should "write to the metadata file" do
@ -183,7 +184,7 @@ class TestRegenerator < JekyllUnitTest
should "not crash when reading corrupted marshal file" do should "not crash when reading corrupted marshal file" do
metadata_file = source_dir(".jekyll-metadata") metadata_file = source_dir(".jekyll-metadata")
File.open(metadata_file, "w") do |file| File.open(metadata_file, "w") do |file|
file.puts Marshal.dump({ :foo => "bar" })[0, 5] file.puts Marshal.dump(:foo => "bar")[0, 5]
end end
@regenerator = Regenerator.new(@site) @regenerator = Regenerator.new(@site)
@ -310,11 +311,11 @@ class TestRegenerator < JekyllUnitTest
context "when incremental regeneration is disabled" do context "when incremental regeneration is disabled" do
setup do setup do
FileUtils.rm_rf(source_dir(".jekyll-metadata")) FileUtils.rm_rf(source_dir(".jekyll-metadata"))
@site = Site.new(Jekyll.configuration({ @site = Site.new(Jekyll.configuration(
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"incremental" => false, "incremental" => false
})) ))
@site.process @site.process
@path = @site.in_source_dir(@site.pages.first.path) @path = @site.in_source_dir(@site.pages.first.path)

View File

@ -29,9 +29,9 @@ class TestRelatedPosts < JekyllUnitTest
end end
allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display) allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display)
@site = fixture_site({ @site = fixture_site(
"lsi" => true, "lsi" => true
}) )
@site.reset @site.reset
@site.read @site.read

View File

@ -5,10 +5,10 @@ require "helper"
class TestSass < JekyllUnitTest class TestSass < JekyllUnitTest
context "importing partials" do context "importing partials" do
setup do setup do
@site = Jekyll::Site.new(Jekyll.configuration({ @site = Jekyll::Site.new(Jekyll.configuration(
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir
})) ))
@site.process @site.process
@test_css_file = dest_dir("css/main.css") @test_css_file = dest_dir("css/main.css")
end end

View File

@ -15,7 +15,7 @@ class TestSite < JekyllUnitTest
@site.posts.docs.concat(PostReader.new(@site).read_posts("")) @site.posts.docs.concat(PostReader.new(@site).read_posts(""))
posts = Dir[source_dir("_posts", "**", "*")] posts = Dir[source_dir("_posts", "**", "*")]
posts.delete_if do |post| posts.delete_if do |post|
File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) File.directory?(post) && post !~ Document::DATE_FILENAME_MATCHER
end end
end end
@ -31,15 +31,15 @@ class TestSite < JekyllUnitTest
end end
should "have an array for plugins if passed as a string" do should "have an array for plugins if passed as a string" do
site = Site.new(site_configuration({ "plugins_dir" => "/tmp/plugins" })) site = Site.new(site_configuration("plugins_dir" => "/tmp/plugins"))
array = Utils::Platforms.windows? ? ["C:/tmp/plugins"] : ["/tmp/plugins"] array = Utils::Platforms.windows? ? ["C:/tmp/plugins"] : ["/tmp/plugins"]
assert_equal array, site.plugins assert_equal array, site.plugins
end end
should "have an array for plugins if passed as an array" do should "have an array for plugins if passed as an array" do
site = Site.new(site_configuration({ site = Site.new(site_configuration(
"plugins_dir" => ["/tmp/plugins", "/tmp/otherplugins"], "plugins_dir" => ["/tmp/plugins", "/tmp/otherplugins"]
})) ))
array = if Utils::Platforms.windows? array = if Utils::Platforms.windows?
["C:/tmp/plugins", "C:/tmp/otherplugins"] ["C:/tmp/plugins", "C:/tmp/otherplugins"]
else else
@ -49,12 +49,12 @@ class TestSite < JekyllUnitTest
end end
should "have an empty array for plugins if nothing is passed" do should "have an empty array for plugins if nothing is passed" do
site = Site.new(site_configuration({ "plugins_dir" => [] })) site = Site.new(site_configuration("plugins_dir" => []))
assert_equal [], site.plugins assert_equal [], site.plugins
end end
should "have the default for plugins if nil is passed" do should "have the default for plugins if nil is passed" do
site = Site.new(site_configuration({ "plugins_dir" => nil })) site = Site.new(site_configuration("plugins_dir" => nil))
assert_equal [source_dir("_plugins")], site.plugins assert_equal [source_dir("_plugins")], site.plugins
end end
@ -64,19 +64,19 @@ class TestSite < JekyllUnitTest
end end
should "expose baseurl passed in from config" do should "expose baseurl passed in from config" do
site = Site.new(site_configuration({ "baseurl" => "/blog" })) site = Site.new(site_configuration("baseurl" => "/blog"))
assert_equal "/blog", site.baseurl assert_equal "/blog", site.baseurl
end end
should "only include theme includes_path if the path exists" do should "only include theme includes_path if the path exists" do
site = fixture_site({ "theme" => "test-theme" }) site = fixture_site("theme" => "test-theme")
assert_equal [source_dir("_includes"), theme_dir("_includes")], assert_equal [source_dir("_includes"), theme_dir("_includes")],
site.includes_load_paths site.includes_load_paths
allow(File).to receive(:directory?).with(theme_dir("_sass")).and_return(true) allow(File).to receive(:directory?).with(theme_dir("_sass")).and_return(true)
allow(File).to receive(:directory?).with(theme_dir("_layouts")).and_return(true) allow(File).to receive(:directory?).with(theme_dir("_layouts")).and_return(true)
allow(File).to receive(:directory?).with(theme_dir("_includes")).and_return(false) allow(File).to receive(:directory?).with(theme_dir("_includes")).and_return(false)
site = fixture_site({ "theme" => "test-theme" }) site = fixture_site("theme" => "test-theme")
assert_equal [source_dir("_includes")], site.includes_load_paths assert_equal [source_dir("_includes")], site.includes_load_paths
end end
end end
@ -87,9 +87,7 @@ class TestSite < JekyllUnitTest
end end
teardown do teardown do
if defined?(MyGenerator) self.class.send(:remove_const, :MyGenerator) if defined?(MyGenerator)
self.class.send(:remove_const, :MyGenerator)
end
end end
should "have an empty tag hash by default" do should "have an empty tag hash by default" do
@ -279,7 +277,7 @@ class TestSite < JekyllUnitTest
posts = Dir[source_dir("**", "_posts", "**", "*")] posts = Dir[source_dir("**", "_posts", "**", "*")]
posts.delete_if do |post| posts.delete_if do |post|
File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) File.directory?(post) && post !~ Document::DATE_FILENAME_MATCHER
end end
categories = %w( categories = %w(
2013 bar baz category foo z_category MixedCase Mixedcase publish_test win 2013 bar baz category foo z_category MixedCase Mixedcase publish_test win
@ -536,9 +534,9 @@ class TestSite < JekyllUnitTest
context "manipulating the Jekyll environment" do context "manipulating the Jekyll environment" do
setup do setup do
@site = Site.new(site_configuration({ @site = Site.new(site_configuration(
"incremental" => false, "incremental" => false
})) ))
@site.process @site.process
@page = @site.pages.find { |p| p.name == "environment.html" } @page = @site.pages.find { |p| p.name == "environment.html" }
end end
@ -550,9 +548,9 @@ class TestSite < JekyllUnitTest
context "in production" do context "in production" do
setup do setup do
ENV["JEKYLL_ENV"] = "production" ENV["JEKYLL_ENV"] = "production"
@site = Site.new(site_configuration({ @site = Site.new(site_configuration(
"incremental" => false, "incremental" => false
})) ))
@site.process @site.process
@page = @site.pages.find { |p| p.name == "environment.html" } @page = @site.pages.find { |p| p.name == "environment.html" }
end end
@ -571,13 +569,13 @@ class TestSite < JekyllUnitTest
should "set no theme if config is not set" do should "set no theme if config is not set" do
expect($stderr).not_to receive(:puts) expect($stderr).not_to receive(:puts)
expect($stdout).not_to receive(:puts) expect($stdout).not_to receive(:puts)
site = fixture_site({ "theme" => nil }) site = fixture_site("theme" => nil)
assert_nil site.theme assert_nil site.theme
end end
should "set no theme if config is a hash" do should "set no theme if config is a hash" do
output = capture_output do output = capture_output do
site = fixture_site({ "theme" => {} }) site = fixture_site("theme" => {})
assert_nil site.theme assert_nil site.theme
end end
expected_msg = "Theme: value of 'theme' in config should be String " \ expected_msg = "Theme: value of 'theme' in config should be String " \
@ -589,7 +587,7 @@ class TestSite < JekyllUnitTest
[:debug, :info, :warn, :error].each do |level| [:debug, :info, :warn, :error].each do |level|
expect(Jekyll.logger.writer).not_to receive(level) expect(Jekyll.logger.writer).not_to receive(level)
end end
site = fixture_site({ "theme" => "test-theme" }) site = fixture_site("theme" => "test-theme")
assert_instance_of Jekyll::Theme, site.theme assert_instance_of Jekyll::Theme, site.theme
assert_equal "test-theme", site.theme.name assert_equal "test-theme", site.theme.name
end end
@ -616,9 +614,9 @@ class TestSite < JekyllUnitTest
context "incremental build" do context "incremental build" do
setup do setup do
@site = Site.new(site_configuration({ @site = Site.new(site_configuration(
"incremental" => true, "incremental" => true
})) ))
@site.read @site.read
end end

View File

@ -5,9 +5,9 @@ require "helper"
class TestSiteDrop < JekyllUnitTest class TestSiteDrop < JekyllUnitTest
context "a site drop" do context "a site drop" do
setup do setup do
@site = fixture_site({ @site = fixture_site(
"collections" => ["thanksgiving"], "collections" => ["thanksgiving"]
}) )
@site.process @site.process
@drop = @site.to_liquid.site @drop = @site.to_liquid.site
end end

View File

@ -70,7 +70,7 @@ class TestStaticFile < JekyllUnitTest
"root", "root",
"_foo/dir/subdir", "_foo/dir/subdir",
"file.html", "file.html",
{ "output" => true } "output" => true
) )
assert_equal :foo, static_file.type assert_equal :foo, static_file.type
assert_equal "/foo/dir/subdir/file.html", static_file.url assert_equal "/foo/dir/subdir/file.html", static_file.url
@ -82,7 +82,7 @@ class TestStaticFile < JekyllUnitTest
"root", "root",
"_foo/dir/subdir", "_foo/dir/subdir",
"file.html", "file.html",
{ "output" => true, "permalink" => "/:path/" } "output" => true, "permalink" => "/:path/"
) )
assert_equal :foo, static_file.type assert_equal :foo, static_file.type
assert_equal "/dir/subdir/file.html", static_file.url assert_equal "/dir/subdir/file.html", static_file.url

View File

@ -26,7 +26,7 @@ class TestTags < JekyllUnitTest
# rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/AbcSize
def fill_post(code, override = {}) def fill_post(code, override = {})
content = <<CONTENT content = <<~CONTENT
--- ---
title: This is a test title: This is a test
--- ---
@ -176,7 +176,7 @@ CONTENT
context "post content has highlight tag" do context "post content has highlight tag" do
setup do setup do
fill_post("test", { "highlighter" => "pygments" }) fill_post("test", "highlighter" => "pygments")
end end
should "not cause a markdown error" do should "not cause a markdown error" do
@ -202,7 +202,7 @@ CONTENT
context "post content has highlight with file reference" do context "post content has highlight with file reference" do
setup do setup do
fill_post("./jekyll.gemspec", { "highlighter" => "pygments" }) fill_post("./jekyll.gemspec", "highlighter" => "pygments")
end end
should "not embed the file" do should "not embed the file" do
@ -216,7 +216,7 @@ CONTENT
context "post content has highlight tag with UTF character" do context "post content has highlight tag with UTF character" do
setup do setup do
fill_post("Æ", { "highlighter" => "pygments" }) fill_post("Æ", "highlighter" => "pygments")
end end
should "render markdown with pygments line handling" do should "render markdown with pygments line handling" do
@ -230,14 +230,14 @@ CONTENT
context "post content has highlight tag with preceding spaces & lines" do context "post content has highlight tag with preceding spaces & lines" do
setup do setup do
code = <<-EOS code = <<~EOS
[,1] [,2] [,1] [,2]
[1,] FALSE TRUE [1,] FALSE TRUE
[2,] FALSE TRUE [2,] FALSE TRUE
EOS EOS
fill_post(code, { "highlighter" => "pygments" }) fill_post(code, "highlighter" => "pygments")
end end
should "only strip the preceding newlines" do should "only strip the preceding newlines" do
@ -252,7 +252,7 @@ EOS
context "post content has highlight tag " \ context "post content has highlight tag " \
"with preceding spaces & lines in several places" do "with preceding spaces & lines in several places" do
setup do setup do
code = <<-EOS code = <<~EOS
[,1] [,2] [,1] [,2]
@ -263,7 +263,7 @@ EOS
EOS EOS
fill_post(code, { "highlighter" => "pygments" }) fill_post(code, "highlighter" => "pygments")
end end
should "only strip the newlines which precede and succeed the entire block" do should "only strip the newlines which precede and succeed the entire block" do
@ -278,7 +278,7 @@ EOS
context "post content has highlight tag with " \ context "post content has highlight tag with " \
"preceding spaces & Windows-style newlines" do "preceding spaces & Windows-style newlines" do
setup do setup do
fill_post "\r\n\r\n\r\n [,1] [,2]", { "highlighter" => "pygments" } fill_post "\r\n\r\n\r\n [,1] [,2]", "highlighter" => "pygments"
end end
should "only strip the preceding newlines" do should "only strip the preceding newlines" do
@ -292,12 +292,12 @@ EOS
context "post content has highlight tag with only preceding spaces" do context "post content has highlight tag with only preceding spaces" do
setup do setup do
code = <<-EOS code = <<~EOS
[,1] [,2] [,1] [,2]
[1,] FALSE TRUE [1,] FALSE TRUE
[2,] FALSE TRUE [2,] FALSE TRUE
EOS EOS
fill_post(code, { "highlighter" => "pygments" }) fill_post(code, "highlighter" => "pygments")
end end
should "only strip the preceding newlines" do should "only strip the preceding newlines" do
@ -337,7 +337,7 @@ EOS
context "post content has raw tag" do context "post content has raw tag" do
setup do setup do
content = <<-CONTENT content = <<~CONTENT
--- ---
title: This is a test title: This is a test
--- ---
@ -389,7 +389,7 @@ CONTENT
context "post content has highlight tag with preceding spaces & lines" do context "post content has highlight tag with preceding spaces & lines" do
setup do setup do
fill_post <<-EOS fill_post <<~EOS
[,1] [,2] [,1] [,2]
@ -409,7 +409,7 @@ EOS
context "post content has highlight tag with " \ context "post content has highlight tag with " \
"preceding spaces & lines in several places" do "preceding spaces & lines in several places" do
setup do setup do
fill_post <<-EOS fill_post <<~EOS
[,1] [,2] [,1] [,2]
@ -433,7 +433,7 @@ EOS
context "post content has highlight tag with linenumbers" do context "post content has highlight tag with linenumbers" do
setup do setup do
create_post <<-EOS create_post <<~EOS
--- ---
title: This is a test title: This is a test
--- ---
@ -448,7 +448,7 @@ EOS
end end
should "should stop highlighting at boundary with rouge" do should "should stop highlighting at boundary with rouge" do
expected = <<-EOS expected = <<~EOS
<p>This is not yet highlighted</p>\n <p>This is not yet highlighted</p>\n
<figure class="highlight"><pre><code class="language-php" data-lang="php"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1 <figure class="highlight"><pre><code class="language-php" data-lang="php"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">1
</pre></td><td class="code"><pre><span class="nx">test</span></pre></td></tr></tbody></table></code></pre></figure>\n </pre></td><td class="code"><pre><span class="nx">test</span></pre></td></tr></tbody></table></code></pre></figure>\n
@ -474,7 +474,7 @@ EOS
context "post content has highlight tag with only preceding spaces" do context "post content has highlight tag with only preceding spaces" do
setup do setup do
fill_post <<-EOS fill_post <<~EOS
[,1] [,2] [,1] [,2]
[1,] FALSE TRUE [1,] FALSE TRUE
[2,] FALSE TRUE [2,] FALSE TRUE
@ -492,7 +492,7 @@ EOS
context "simple post with markdown and pre tags" do context "simple post with markdown and pre tags" do
setup do setup do
@content = <<CONTENT @content = <<~CONTENT
--- ---
title: Kramdown post with pre title: Kramdown post with pre
--- ---
@ -521,19 +521,18 @@ CONTENT
context "simple page with post linking" do context "simple page with post linking" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Post linking title: Post linking
--- ---
{% post_url 2008-11-21-complex %} {% post_url 2008-11-21-complex %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -547,19 +546,18 @@ CONTENT
context "simple page with post linking containing special characters" do context "simple page with post linking containing special characters" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Post linking title: Post linking
--- ---
{% post_url 2016-11-26-special-chars-(+) %} {% post_url 2016-11-26-special-chars-(+) %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -573,7 +571,7 @@ CONTENT
context "simple page with nested post linking" do context "simple page with nested post linking" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Post linking title: Post linking
--- ---
@ -583,12 +581,11 @@ title: Post linking
- 3 {% post_url es/2008-11-21-nested %} - 3 {% post_url es/2008-11-21-nested %}
- 4 {% post_url /es/2008-11-21-nested %} - 4 {% post_url /es/2008-11-21-nested %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -608,19 +605,18 @@ CONTENT
context "simple page with nested post linking and path not used in `post_url`" do context "simple page with nested post linking and path not used in `post_url`" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Deprecated Post linking title: Deprecated Post linking
--- ---
- 1 {% post_url 2008-11-21-nested %} - 1 {% post_url 2008-11-21-nested %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -642,7 +638,7 @@ CONTENT
context "simple page with invalid post name linking" do context "simple page with invalid post name linking" do
should "cause an error" do should "cause an error" do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Invalid post name linking title: Invalid post name linking
--- ---
@ -651,17 +647,16 @@ title: Invalid post name linking
CONTENT CONTENT
assert_raises Jekyll::Errors::PostURLError do assert_raises Jekyll::Errors::PostURLError do
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
end end
should "cause an error with a bad date" do should "cause an error with a bad date" do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Invalid post name linking title: Invalid post name linking
--- ---
@ -670,19 +665,18 @@ title: Invalid post name linking
CONTENT CONTENT
assert_raises Jekyll::Errors::InvalidDateError do assert_raises Jekyll::Errors::InvalidDateError do
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
end end
end end
context "simple page with linking to a page" do context "simple page with linking to a page" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: linking title: linking
--- ---
@ -691,11 +685,10 @@ title: linking
{% link info.md %} {% link info.md %}
{% link /css/screen.css %} {% link /css/screen.css %}
CONTENT CONTENT
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_all" => true, "read_all" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -717,7 +710,7 @@ CONTENT
context "simple page with dynamic linking to a page" do context "simple page with dynamic linking to a page" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: linking title: linking
--- ---
@ -730,11 +723,10 @@ title: linking
{% assign screen_css_path = '/css' %} {% assign screen_css_path = '/css' %}
{% link {{ screen_css_path }}/screen.css %} {% link {{ screen_css_path }}/screen.css %}
CONTENT CONTENT
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_all" => true, "read_all" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -756,19 +748,18 @@ CONTENT
context "simple page with linking" do context "simple page with linking" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: linking title: linking
--- ---
{% link _methods/yaml_with_dots.md %} {% link _methods/yaml_with_dots.md %}
CONTENT CONTENT
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"collections" => { "methods" => { "output" => true } }, "collections" => { "methods" => { "output" => true } },
"read_collections" => true, "read_collections" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -782,7 +773,7 @@ CONTENT
context "simple page with dynamic linking" do context "simple page with dynamic linking" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: linking title: linking
--- ---
@ -790,12 +781,11 @@ title: linking
{% assign yaml_with_dots_path = '_methods/yaml_with_dots.md' %} {% assign yaml_with_dots_path = '_methods/yaml_with_dots.md' %}
{% link {{yaml_with_dots_path}} %} {% link {{yaml_with_dots_path}} %}
CONTENT CONTENT
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"collections" => { "methods" => { "output" => true } }, "collections" => { "methods" => { "output" => true } },
"read_collections" => true, "read_collections" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -809,7 +799,7 @@ CONTENT
context "simple page with nested linking" do context "simple page with nested linking" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: linking title: linking
--- ---
@ -817,12 +807,11 @@ title: linking
- 1 {% link _methods/sanitized_path.md %} - 1 {% link _methods/sanitized_path.md %}
- 2 {% link _methods/site/generate.md %} - 2 {% link _methods/site/generate.md %}
CONTENT CONTENT
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"collections" => { "methods" => { "output" => true } }, "collections" => { "methods" => { "output" => true } },
"read_collections" => true, "read_collections" => true)
})
end end
should "not cause an error" do should "not cause an error" do
@ -840,7 +829,7 @@ CONTENT
context "simple page with invalid linking" do context "simple page with invalid linking" do
should "cause an error" do should "cause an error" do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Invalid linking title: Invalid linking
--- ---
@ -849,19 +838,18 @@ title: Invalid linking
CONTENT CONTENT
assert_raises ArgumentError do assert_raises ArgumentError do
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"collections" => { "methods" => { "output" => true } }, "collections" => { "methods" => { "output" => true } },
"read_collections" => true, "read_collections" => true)
})
end end
end end
end end
context "simple page with invalid dynamic linking" do context "simple page with invalid dynamic linking" do
should "cause an error" do should "cause an error" do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Invalid linking title: Invalid linking
--- ---
@ -871,12 +859,11 @@ title: Invalid linking
CONTENT CONTENT
assert_raises ArgumentError do assert_raises ArgumentError do
create_post(content, { create_post(content,
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"collections" => { "methods" => { "output" => true } }, "collections" => { "methods" => { "output" => true } },
"read_collections" => true, "read_collections" => true)
})
end end
end end
end end
@ -886,7 +873,7 @@ CONTENT
should "not allow symlink includes" do should "not allow symlink includes" do
File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") } File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") }
assert_raises IOError do assert_raises IOError do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include symlink title: Include symlink
--- ---
@ -894,13 +881,12 @@ title: Include symlink
{% include tmp/pages-test %} {% include tmp/pages-test %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true,
"safe" => true, "safe" => true)
})
end end
@result ||= "" @result ||= ""
refute_match(%r!SYMLINK TEST!, @result) refute_match(%r!SYMLINK TEST!, @result)
@ -908,7 +894,7 @@ CONTENT
should "not expose the existence of symlinked files" do should "not expose the existence of symlinked files" do
ex = assert_raises IOError do ex = assert_raises IOError do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include symlink title: Include symlink
--- ---
@ -916,13 +902,12 @@ title: Include symlink
{% include tmp/pages-test-does-not-exist %} {% include tmp/pages-test-does-not-exist %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true,
"safe" => true, "safe" => true)
})
end end
assert_match( assert_match(
"Could not locate the included file 'tmp/pages-test-does-not-exist' " \ "Could not locate the included file 'tmp/pages-test-does-not-exist' " \
@ -936,7 +921,7 @@ CONTENT
context "with one parameter" do context "with one parameter" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include tag parameters title: Include tag parameters
--- ---
@ -945,12 +930,11 @@ title: Include tag parameters
{% include params.html param="value" %} {% include params.html param="value" %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "correctly output include variable" do should "correctly output include variable" do
@ -964,7 +948,7 @@ CONTENT
context "with simple syntax but multiline markup" do context "with simple syntax but multiline markup" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include tag parameters title: Include tag parameters
--- ---
@ -974,12 +958,11 @@ title: Include tag parameters
{% include params.html {% include params.html
param="value" %} param="value" %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "correctly output include variable" do should "correctly output include variable" do
@ -993,7 +976,7 @@ CONTENT
context "with variable syntax but multiline markup" do context "with variable syntax but multiline markup" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include tag parameters title: Include tag parameters
--- ---
@ -1003,12 +986,11 @@ title: Include tag parameters
{% include {{ path }} {% include {{ path }}
param="value" %} param="value" %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "correctly output include variable" do should "correctly output include variable" do
@ -1022,7 +1004,7 @@ CONTENT
context "with invalid parameter syntax" do context "with invalid parameter syntax" do
should "throw a ArgumentError" do should "throw a ArgumentError" do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Invalid parameter syntax title: Invalid parameter syntax
--- ---
@ -1031,15 +1013,14 @@ title: Invalid parameter syntax
CONTENT CONTENT
assert_raises ArgumentError, "Did not raise exception on invalid " \ assert_raises ArgumentError, "Did not raise exception on invalid " \
'"include" syntax' do '"include" syntax' do
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
content = <<CONTENT content = <<~CONTENT
--- ---
title: Invalid parameter syntax title: Invalid parameter syntax
--- ---
@ -1048,31 +1029,29 @@ title: Invalid parameter syntax
CONTENT CONTENT
assert_raises ArgumentError, "Did not raise exception on invalid " \ assert_raises ArgumentError, "Did not raise exception on invalid " \
'"include" syntax' do '"include" syntax' do
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
end end
end end
context "with several parameters" do context "with several parameters" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: multiple include parameters title: multiple include parameters
--- ---
{% include params.html param1="new_value" param2="another" %} {% include params.html param1="new_value" param2="another" %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "list all parameters" do should "list all parameters" do
@ -1087,19 +1066,18 @@ CONTENT
context "without parameters" do context "without parameters" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: without parameters title: without parameters
--- ---
{% include params.html %} {% include params.html %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "include file with empty parameters" do should "include file with empty parameters" do
@ -1109,20 +1087,19 @@ CONTENT
context "with custom includes directory" do context "with custom includes directory" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: custom includes directory title: custom includes directory
--- ---
{% include custom.html %} {% include custom.html %}
CONTENT CONTENT
create_post(content, { create_post(content,
"includes_dir" => "_includes_custom", "includes_dir" => "_includes_custom",
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "include file from custom directory" do should "include file from custom directory" do
@ -1132,19 +1109,18 @@ CONTENT
context "without parameters within if statement" do context "without parameters within if statement" do
setup do setup do
content = <<CONTENT content = <<~CONTENT
--- ---
title: without parameters within if statement title: without parameters within if statement
--- ---
{% if true %}{% include params.html %}{% endif %} {% if true %}{% include params.html %}{% endif %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
should "include file with empty parameters within if statement" do should "include file with empty parameters within if statement" do
@ -1154,7 +1130,7 @@ CONTENT
context "include missing file" do context "include missing file" do
setup do setup do
@content = <<CONTENT @content = <<~CONTENT
--- ---
title: missing file title: missing file
--- ---
@ -1165,12 +1141,11 @@ CONTENT
should "raise error relative to source directory" do should "raise error relative to source directory" do
exception = assert_raises IOError do exception = assert_raises IOError do
create_post(@content, { create_post(@content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
assert_match( assert_match(
"Could not locate the included file 'missing.html' in any of " \ "Could not locate the included file 'missing.html' in any of " \
@ -1182,7 +1157,7 @@ CONTENT
context "include tag with variable and liquid filters" do context "include tag with variable and liquid filters" do
setup do setup do
site = fixture_site({ "pygments" => true }).tap(&:read).tap(&:render) site = fixture_site("pygments" => true).tap(&:read).tap(&:render)
post = site.posts.docs.find do |p| post = site.posts.docs.find do |p|
p.basename.eql? "2013-12-17-include-variable-filters.markdown" p.basename.eql? "2013-12-17-include-variable-filters.markdown"
end end
@ -1214,7 +1189,7 @@ CONTENT
context "relative include tag with variable and liquid filters" do context "relative include tag with variable and liquid filters" do
setup do setup do
site = fixture_site({ "pygments" => true }).tap(&:read).tap(&:render) site = fixture_site("pygments" => true).tap(&:read).tap(&:render)
post = site.posts.docs.find do |p| post = site.posts.docs.find do |p|
p.basename.eql? "2014-09-02-relative-includes.markdown" p.basename.eql? "2014-09-02-relative-includes.markdown"
end end
@ -1249,7 +1224,7 @@ CONTENT
context "trying to do bad stuff" do context "trying to do bad stuff" do
context "include missing file" do context "include missing file" do
setup do setup do
@content = <<CONTENT @content = <<~CONTENT
--- ---
title: missing file title: missing file
--- ---
@ -1260,12 +1235,11 @@ CONTENT
should "raise error relative to source directory" do should "raise error relative to source directory" do
exception = assert_raises IOError do exception = assert_raises IOError do
create_post(@content, { create_post(@content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
assert_match "Could not locate the included file 'missing.html' in any of " \ assert_match "Could not locate the included file 'missing.html' in any of " \
"[\"#{source_dir}\"].", exception.message "[\"#{source_dir}\"].", exception.message
@ -1274,7 +1248,7 @@ CONTENT
context "include existing file above you" do context "include existing file above you" do
setup do setup do
@content = <<CONTENT @content = <<~CONTENT
--- ---
title: higher file title: higher file
--- ---
@ -1285,12 +1259,11 @@ CONTENT
should "raise error relative to source directory" do should "raise error relative to source directory" do
exception = assert_raises ArgumentError do exception = assert_raises ArgumentError do
create_post(@content, { create_post(@content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true)
})
end end
assert_equal( assert_equal(
"Invalid syntax for include tag. File contains invalid characters or " \ "Invalid syntax for include tag. File contains invalid characters or " \
@ -1306,7 +1279,7 @@ CONTENT
should "not allow symlink includes" do should "not allow symlink includes" do
File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") } File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") }
assert_raises IOError do assert_raises IOError do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include symlink title: Include symlink
--- ---
@ -1314,13 +1287,12 @@ title: Include symlink
{% include_relative tmp/pages-test %} {% include_relative tmp/pages-test %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true,
"safe" => true, "safe" => true)
})
end end
@result ||= "" @result ||= ""
refute_match(%r!SYMLINK TEST!, @result) refute_match(%r!SYMLINK TEST!, @result)
@ -1328,7 +1300,7 @@ CONTENT
should "not expose the existence of symlinked files" do should "not expose the existence of symlinked files" do
ex = assert_raises IOError do ex = assert_raises IOError do
content = <<CONTENT content = <<~CONTENT
--- ---
title: Include symlink title: Include symlink
--- ---
@ -1336,13 +1308,12 @@ title: Include symlink
{% include_relative tmp/pages-test-does-not-exist %} {% include_relative tmp/pages-test-does-not-exist %}
CONTENT CONTENT
create_post(content, { create_post(content,
"permalink" => "pretty", "permalink" => "pretty",
"source" => source_dir, "source" => source_dir,
"destination" => dest_dir, "destination" => dest_dir,
"read_posts" => true, "read_posts" => true,
"safe" => true, "safe" => true)
})
end end
assert_match( assert_match(
"Ensure it exists in one of those directories and is not a symlink "\ "Ensure it exists in one of those directories and is not a symlink "\