查看 rspec 集成/请求测试中的 Devise 视图未包含的辅助方法?
当我在浏览器中访问登录页面时,一切正常。
当我在 rspec 集成/请求测试中访问我的登录页面时,出现以下错误:
ActionView::Template::Error:
undefined method `title' for #<#<Class:0x00000007af9180>:0x00000007af32a8>
标题方法由视图使用并在 ApplicationHelper 中定义,该方法似乎在使用浏览器时找到。但是,在 rspec 集成测试期间,devise 无法找到辅助方法。
有什么我应该存根的吗?在集成测试中进行存根似乎是错误的。还有其他想法吗?
(这个问题不是关于如何在集成测试中包含设计助手。我手动填写登录表单以进行身份验证)。
When I visit my sign in page in a browser everything works fine.
When I visit my sign in page in an rspec integration/request test, I get the following error:
ActionView::Template::Error:
undefined method `title' for #<#<Class:0x00000007af9180>:0x00000007af32a8>
The title method is used by the view and defined in ApplicationHelper which devise seems to find when using the browser. However, during rspec integration tests, devise is unable to find the helper method.
Is there anything I should be stubbing? It seems wrong to be stubbing in integration tests. Any other ideas?
(This question is not about how to include devise helpers in integration tests. I'm manually filling in the sign in forms to authenticate).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来像此问题。 (在某些情况下与 ActiveAdmin https://github.com/gregbell/active_admin/wiki/ Use-spork)
在这里我找到了一个适合我的黑客(REE 1.8.7、Rails 3.1、水豚、Devise、active_admin)。
然而,这不太可能被合并,所以我用该补丁将 spork-rails 分叉到 此处应用。正如您可能知道的那样,我可以将我的 Gemfile 指向该存储库:
不是最佳的,但它现在可以完成工作。
Looks like this issue. (in some cases related to ActiveAdmin https://github.com/gregbell/active_admin/wiki/Use-spork)
Here I found a hack that works for me (REE 1.8.7, Rails 3.1, Capybara, Devise, active_admin).
However, this is not likely to be merged, so I forked spork-rails to here with that patch applied. And as you probably know I can point my Gemfile to that repo:
Not optimal but it gets the job done for now.
当我安装 devise 时,我使用 Cucumber 遇到了类似的问题:
我通过在
env.rb
中包含该模块来解决它,我希望这会有所帮助。
I had a similar problem using Cucumber when I installed devise:
I solved it by including the module in
env.rb
I hope this helps.
在 /spec/support 内创建 devise.rb ,内容如下:
确保您的 spec_helper.rb 包含:
并且您的规格具有:
Inside /spec/support create devise.rb with this:
Make sure your spec_helper.rb includes:
and that your specs have: