使用Cucumber测试Jekyll插件

时间:2017-10-26 16:14:18

标签: ruby cucumber jekyll jekyll-extensions

我正在为Jekyll开发一个插件,并希望使用Cucumber和Aruba来测试它。我的插件目前只是向Jekyll添加一个命令,就像它在这里指定的那样:https://jekyllrb.com/docs/plugins/#commands我将它捆绑为一个宝石。

这是我的gem文件夹的结构:

├── 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

这是我的lib/hello_world.rb文件:

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

这是我的features/hello_world.feature文件:

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

然而,这就是我得到的:

$ 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)

我认为该问题必须与Jekyll插件的使用方式有关:https://jekyllrb.com/docs/plugins/#installing-a-plugin :jekyll_plugins Gemfile组中应该需要它们。

在我的Gemfile中,我尝试仅引用gemspec并试图将gemspec包含在此:jekyll_plugins组中,这两种方法都没有效果:

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

我还尝试构建我的gem,在本地安装它,然后在测试Jekyll构建中使用它(包括通过:jekyll_plugins中的Gemfile组)并且它可以正常工作。

如何将我的插件命令发送到&#34;注册&#34;正确地使用Jekyll以便它可用于我的Cucumber测试吗?

1 个答案:

答案 0 :(得分:0)

实现这一目标的一种方法是定义一个step-definition,用适当的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

在上面,执行Given步骤应该创建一个夹具网站,其中Gemfile指向您的插件和一个基本的jekyll-config文件。 (编辑step_definitions.rb文件以执行此操作)

# 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
相关问题