Rspec 2 配置:类型类型
在我的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此提交应该有助于澄清
:type
选项。https://github.com/rspec/rspec-rails/commit/fc5cdbb603f0e66f9f3d19a0a60a775e124fb218
:type => :request
是有效的,所以我不确定为什么你的测试失败。哪个目录保存您的集成测试?通常,它们位于
spec/requests
或可能位于spec/integration
中。您可以使用另一个选项来指定何时包含 Devise::TestHelpers;选项是
:example_group
:现在,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 possiblyspec/integration
.You can use another option to specify when to include Devise::TestHelpers; the option is
:example_group
: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.也许为时已晚,但对于任何需要它的人来说,将类型更改为
:feature
对我有用:Maybe is too late, but for anyone who needs it, changing the type to
:feature
worked for me: