Jekyll Testing

Jekyll is a static site generator framework built in Ruby. Below are notes on testing Jekyll sites.

Table of contents

  1. Manual Testing
  2. Automated Testing
    1. Setup
    2. Writing Tests
    3. Running Tests

Manual Testing

Jekyll doesn’t come with any nifty testing capabilities out of the box. The only thing you get out of the box is the ability to deploy your site locally and manually test the site.

Naturally, this isn’t sufficient for complex web apps, so this guide will go in depth on how to setup automated tests for a Jekyll site.

Automated Testing

In order to build automated tests for our Jekyll site, we’ll need to assemble an ensemble of Ruby web testing frameworks. Hat tip to @deanmarano for the setup guide.

Setup

Writing automated tests for our Jekyll site involves string together a few common types of tech:

  1. RSpec - A test framework to define and execute test suites in Ruby
  2. Capybara - A web test middleware that defines a web interaction DSL and integration point for a web driver
  3. Selenium - A web driver to automate a browser a report back to Capybara
  4. Puma
  5. rack-jekyll - A Ruby Gem that will serve our static site during testing using Ruby
  6. Puma - A web server to serve requests made by Capybara and pass the request to Rack.

Let’s setup our Gemfile to add those dependencies:

Run bundle install && rbenv rehash to install the new Gems and add any new executables to your executable path.

Next, we’re going to configure RSpec to use Capybara, Selenium, and Rack to orchestrate web tests in our RSpec tests.

Initialize RSpec:

Two files are produced: .rspec and spec/spec_helper.rb. .rspec configures the output for rspec and spec/spec_helper.rb loads tests and configures the testing environment. Let’s configure rspec to use Capybara, Selenium, and Rack.

Writing Tests

Now that we have RSpec configured to run our web testing frameworks, we can write RSpec tests with Capybara DSL to verify our website behavior.

Here’s an example test for a new Jekyll site:

Running Tests

To run the tests using RSpec, execute bundle exec rspec.