如何在RSPEC测试工作中制作自定义模块?

发布于 2025-01-23 10:42:43 字数 698 浏览 2 评论 0原文

我正在尝试将自定义模块包括在RSPEC测试中。但是,我一直遇到错误,告诉我它找不到我的模块,它说了NameRor:非专业化的常量Authhelper。

我一直在尝试遵循此 https://stackoverflow.com/a/68669816/55568244

我不知道在哪里要放置该模块,以便我创建了一个名为spec/support/的文件夹和一个名为auth_helper.rb的文件,然后放入module authhelper ...等...结束,因为

我尝试了简单地包括它在测试

规格/请求/topics_specs.rb

require 'rails_helper'
include AuthHelper

中,我希望能够自动在支持文件夹中找到该模块,但没有。应该吗? RSPEC是否在特定的地方看?

我还尝试设置rails_helper.rb文件以包含它,

RSpec.configure do |config|
  config.include(AuthHelper, :type => :request) 
end

但这仍然不起作用。

我想念什么?这个应该如何工作?

I am trying to include a custom module into an RSpec test. However, I keep getting errors telling me it can't find my module, it says NameError: uninitialized constant AuthHelper.

I have been trying to follow this https://stackoverflow.com/a/68669816/5568244

I didn't know where to put the the module so I created a folder called specs/support/ and a file called auth_helper.rb in it and put module AuthHelper ...etc... end in that

I have tried simply including it in the test

spec/requests/topics_specs.rb

require 'rails_helper'
include AuthHelper

which i expected to be able to just automatically find the module in the support folder but it didn't. Should it? Does RSpec look in specific places?

I also tried to set up the rails_helper.rb file to include it

RSpec.configure do |config|
  config.include(AuthHelper, :type => :request) 
end

This still didn't work.

What am i missing? How should this work?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文