如何在 Cucumber 步骤定义中重用 Minitest 支持代码?

How to reuse Minitest support code in Cucumber step definitions?

我有一个使用 Minitest 的测试套件。根据 Minitest 文档,当我有通用功能时,我将其提取到一个模块中,然后将该模块包含到 ActionDispatch::IntegrationTest 中,让我可以访问我的测试。在这种情况下,提取的功能会在我的集成测试中格式化请求并解析响应。

现在,我引入了 Cucumber,但是当我在我的步骤定义文件中添加 include MyHelperModule 时,它引发了 NameError: undefined constant.

如何在我的 Cucumber 步骤定义中包含此功能而不重写下面的模块 features/

该模块当前位于 test/support/my_helper_module.rb

features/support/env.rb 中,或在 features/support 中的另一个 .rb 文件中,执行

require_relative '../../test/support/my_helper_module'

MyHelperModule 将在步骤定义中可用。