gpt4 book ai didi

ruby - 使用 Cucumber 测试 Jekyll 插件

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:51 25 4
gpt4 key购买 nike

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

这是我的 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它们应该在 Gemfile:jekyll_plugins 组中是必需的。

在我的 Gemfile 中,我尝试只引用 gemspec 并尝试将 gemspec 包含到 :jekyll_plugins 像这样分组,但两个选项都不起作用:

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

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

如何让我的插件命令正确地“注册”Jekyll,以便它可用于我的 Cucumber 测试?

最佳答案

实现此目的的一种方法是定义一个 step-definition,它使用适当的 Gemfile

创建一个 fixture 站点
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 的 fixture 站点和一个基本的 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

关于ruby - 使用 Cucumber 测试 Jekyll 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46959120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com