2
votes

I am developing a plugin for Jekyll and want to use Cucumber and Aruba to test it. My plugin is currently just adding a command to Jekyll like it specifies here: https://jekyllrb.com/docs/plugins/#commands I'm bundling this as a gem.

This is the structure of my gem folder:

├── Gemfile
├── Gemfile.lock
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
│   ├── console
│   └── setup
├── features
│   ├── hello_world.feature
│   ├── step_definitions.rb
│   └── support
│       └── env.rb
├── hello_world.gemspec
├── lib
│   ├── hello_world
│   │   └── version.rb
│   └── hello_world.rb
├── pkg
│   └── hello_world-0.1.0.gem
└── spec
    ├── hello_world_spec.rb
    └── spec_helper.rb

This is my lib/hello_world.rb file:

require "hello_world/version"
require "jekyll"

module Jekyll
  module Commands
    class Hello < Command
      class << self
        def init_with_program(prog)
          prog.command(:hello) do |c|
            c.action do |args, options|
              Jekyll.logger.info "Hello world!"
            end
          end
        end
      end
    end
  end
end

Here is my features/hello_world.feature file:

Feature: Hello world
  As a hacker who likes to blog
  I want to have a custom Jekyll command

  Scenario: Show Hello world
    When I run `jekyll hello`
    Then the output should contain "Hello world!"
    And the exit status should be 0

However this is what I get:

$ cucumber
Feature: Hello world
  As a hacker who likes to blog
  I want to have a custom Jekyll command

  Scenario: Show Hello world          # features/hello_world.feature:6
    When I run `jekyll hello`                    # aruba-0.14.2/lib/aruba/cucumber/command.rb:13
    Then the output should contain "Hello world!" # aruba-0.14.2/lib/aruba/cucumber/command.rb:159
      expected "fatal: 'jekyll hello' could not be found. You may need to install the jekyll-hello gem or a related gem to be able to use this subcommand. " to string includes: "hello world" (RSpec::Expectations::ExpectationNotMetError)
      features/hello_world.feature:8:in `Then the output should contain "Hello world!"'
    And the exit status should be 0              # aruba-0.14.2/lib/aruba/cucumber/command.rb:277

Failing Scenarios:
cucumber features/hello_world.feature:6 # Scenario: Help show a helpful message

1 scenario (1 failed)
3 steps (1 failed, 1 skipped, 1 passed)

I believe that the issue must have something to do with the way Jekyll plugins are required: https://jekyllrb.com/docs/plugins/#installing-a-plugin They are supposed to be required in the :jekyll_plugins group of the Gemfile.

In my Gemfile I have tried just referencing just the gemspec and trying to include the gemspec into the :jekyll_plugins group like this and neither option has worked:

source 'https://rubygems.org'
gemspec :group => :jekyll_plugins

I have also tried building my gem, installing it locally and then using it in a test Jekyll build (including via the :jekyll_plugins group in the Gemfile) and it works correctly.

How can I get my plugin's command to "register" correctly with Jekyll so that it is available for my Cucumber test?

1

1 Answers

0
votes

One way to achieve this would by defining a step-definition that creates a fixture site with the proper Gemfile

Feature: Hello world
  As a hacker who likes to blog
  I want to have a custom Jekyll command

  Scenario: Show Hello world
    Given I have a fixture site
    When I run `jekyll hello`
    Then the output should contain "Hello world!"
    And the exit status should be 0

In the above, executing the Given step is supposed to create a fixture site with a Gemfile that points to your plugin and a basic jekyll-config file. (Edit your step_definitions.rb file to do so)

# Gemfile

gem "jekyll", "~> 3.6"

group :jekyll_plugins do
  # point to the location of your plugin's gemspec, relative to this file
  gem "hello_world", :path => "path/to/repo root"
end