Rspec 2 配置:类型类型

发布于 2024-11-14 07:56:09 字数 396 浏览 3 评论 0原文

在我的spec_helper.rb 中,

config.include Devise::TestHelpers, :type => :controller

我可以实际测试需要对用户进行身份验证的控制器。但是,请求中同一类的规范也需要登录,否则测试将失败。我已经尝试过

config.include Devise::TestHelpers, :type => :request

,但这也行不通。我似乎找不到可以传递到 rspec include 或extend 方法中的类型选项。我假设 :model 和 :view 会在那里,但其他的我完全不确定。我应该使用什么以便我的请求规范可以通过,并且是否有 :type 的不同类型的列表?

In my spec_helper.rb I have

config.include Devise::TestHelpers, :type => :controller

so that I can actually test my controllers that require the user to be authenticated. However, the spec for the same class in requests needs to sign in as well or the tests will fail. I've tried

config.include Devise::TestHelpers, :type => :request

but that doesn't work either. I cannot seem to find what type options I can pass into the rspec include or extend methods. I assume :model and :view would be there but the others I'm completely unsure of. What should I be using so my requests spec can pass and is there a list of the different types for :type?

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

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

发布评论

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

评论(2

暗地喜欢 2024-11-21 07:56:09

此提交应该有助于澄清 :type 选项。

https://github.com/rspec/rspec-rails/commit/fc5cdbb603f0e66f9f3d19a0a60a775e124fb218

:type => :request 是有效的,所以我不确定为什么你的测试失败。

哪个目录保存您的集成测试?通常,它们位于 spec/requests 或可能位于 spec/integration 中。

您可以使用另一个选项来指定何时包含 Devise::TestHelpers;选项是 :example_group

config.include Devise::TestHelpers, :example_group => {
  :file_path => config.escaped_path(%w[spec (requests|integration)])
}

现在,Devise::TestHelpers 将包含在文件位于指定路径内的示例组中。

确保将数组成员 (requests|integration) 替换为集成测试所在的文件夹名称。

This commit should help clarify the :type option.

https://github.com/rspec/rspec-rails/commit/fc5cdbb603f0e66f9f3d19a0a60a775e124fb218

:type => :request is valid, so I'm unsure why your tests are failing.

Which directory holds your integration tests? Typically, they're located in spec/requests or possibly spec/integration.

You can use another option to specify when to include Devise::TestHelpers; the option is :example_group:

config.include Devise::TestHelpers, :example_group => {
  :file_path => config.escaped_path(%w[spec (requests|integration)])
}

Now, Devise::TestHelpers will be included into example groups whose file is within the specified paths.

Make sure to replace the array member (requests|integration) with the folder name where your integration tests are located.

梦初启 2024-11-21 07:56:09

也许为时已晚,但对于任何需要它的人来说,将类型更改为 :feature 对我有用:

config.include Devise::TestHelpers, :type => :feature

Maybe is too late, but for anyone who needs it, changing the type to :feature worked for me:

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