Jekyll Testing
Jekyll is a static site generator framework built in Ruby. Below are notes on testing Jekyll sites.
Table of contents
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:
- RSpec - A test framework to define and execute test suites in Ruby
- Capybara - A web test middleware that defines a web interaction DSL and integration point for a web driver
- Selenium - A web driver to automate a browser a report back to Capybara
- Puma
- rack-jekyll - A Ruby Gem that will serve our static site during testing using Ruby
- 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
.