如何使用多个 rspec_helpers

How to use multiple rspec_helpers

我们正在尝试将 rspec 的集成测试添加到我们的工作流程中,并且正在尝试以下文件夹结构:

.
├── spec #unit tests
├── spec-integration #e2e tests

当我 运行 使用 bundle exec rspec SPECS=spec-integration 进行 e2e 测试时,.rspec--require spec_helper 自动转到 spec/spec_helper。这是有道理和预期的,但我们不想使用单元测试中的 spec_helper,我们想使用另一个进行集成测试。

如何让 rspec 默认转到 spec-integration/spec_handler 而不是 spec/spec_handler

(Edit/PS:也欢迎来自文件夹架构的评论或关于更好的设计方法的建议,因为我们是 Ruby 生态系统的新手)

谢谢!

您可以通过指定 --options 命令行标志来覆盖它。 (ref)

bundle exec rspec --default-path spec-integration --options spec_handler

此外,当您使用 --default-path 时,您可以有一个 spec-integration/spec_helper.rb 并且它会使用它(因为 .rspec 中的 --require spec_helper)。

(尽管在 rspec 3.9 上这对我不起作用 - bundle exec rspec SPECS=spec-integration。)

谈到文件夹结构部分,我会在 spec 内的 sub-folder 中保留集成规范。单元和集成规范都可以有自己的帮助文件,spec/spec_helper 可以有共同的配置。