Gem 功能无法正确加载实际的 Gem 代码

发布于 2024-11-18 15:59:29 字数 273 浏览 1 评论 0原文

我有一个带有 cukes 和扩展 RSpec 主题的规格的宝石。

所有规格都运行良好,但功能似乎无法正确加载当前的 gem 代码。不过似乎部分存在。

该宝石位于 https://github.com/ZenCocoon/rspec-subject-extensions

注意:对黄瓜不熟悉,我可能跳过了一些明显的东西。

I've got a gem with cukes and specs that extend RSpec subjects.

All specs runs fine but the features doesn't seem to properly load the current gem code. Seems partially there though.

The gem is at https://github.com/ZenCocoon/rspec-subject-extensions

Note: New to cucumber, I might have skipped something obvious.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2024-11-25 15:59:29

这是因为 rspec 是作为单独的进程启动的。您在 Cucumber 功能中定义的规范文件不需要这些扩展名,因此它们将不可用。它在您的 RSpec 测试中起作用的原因是您确实需要这些扩展。

要解决此问题,您可以在 Cucumber 功能的顶部添加一行以请求 rspec/subject/extensions.rb 文件:

Given a file named "example_spec.rb" with:
"""
  require 'rspec/subject/extensions'

  class Movie
    def ratings
      [9, 7, 9]
    end
  end

  describe Movie do
    each(:rating) { should be_an(Integer) }
  end
"""

这将解决该问题。

This is because rspec is being launched as a separate process. The spec file you're defining in your Cucumber feature does not require these extensions and so they won't be made available. The reason it's working in your RSpec tests is because you do require these extensions.

To fix this, you can add one line to the top of your Cucumber feature to require the rspec/subject/extensions.rb file:

Given a file named "example_spec.rb" with:
"""
  require 'rspec/subject/extensions'

  class Movie
    def ratings
      [9, 7, 9]
    end
  end

  describe Movie do
    each(:rating) { should be_an(Integer) }
  end
"""

This will fix the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文