查看 rspec 集成/请求测试中的 Devise 视图未包含的辅助方法?

发布于 2024-11-28 03:40:51 字数 407 浏览 0 评论 0原文

当我在浏览器中访问登录页面时,一切正常。

当我在 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 技术交流群。

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

发布评论

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

评论(3

萌︼了一个春 2024-12-05 03:40:51

看起来像此问题。 (在某些情况下与 ActiveAdmin https://github.com/gregbell/active_admin/wiki/ Use-spork

在这里我找到了一个适合我的黑客(REE 1.8.7、Rails 3.1、水豚、Devise、active_admin)。

然而,这不太可能被合并,所以我用该补丁将 spork-rails 分叉到 此处应用。正如您可能知道的那样,我可以将我的 Gemfile 指向该存储库:

gem 'spork-rails', :git => "git://github.com/chopmo/spork-rails.git"

不是最佳的,但它现在可以完成工作。

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:

gem 'spork-rails', :git => "git://github.com/chopmo/spork-rails.git"

Not optimal but it gets the job done for now.

垂暮老矣 2024-12-05 03:40:51

当我安装 devise 时,我使用 Cucumber 遇到了类似的问题:

undefined local variable or method `flash_block' for #<#<Class:0x007ffd0a28dae8>:0x007ffd0b2f6d58> (ActionView::Template::Error)

我通过在 env.rb 中包含该模块来解决它,

Spork.prefork do
  include FlashBlockHelper

我希望这会有所帮助。

I had a similar problem using Cucumber when I installed devise:

undefined local variable or method `flash_block' for #<#<Class:0x007ffd0a28dae8>:0x007ffd0b2f6d58> (ActionView::Template::Error)

I solved it by including the module in env.rb

Spork.prefork do
  include FlashBlockHelper

I hope this helps.

甜中书 2024-12-05 03:40:51

在 /spec/support 内创建 devise.rb ,内容如下:

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

确保您的 spec_helper.rb 包含:

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

并且您的规格具有:

require 'spec_helper'

Inside /spec/support create devise.rb with this:

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

Make sure your spec_helper.rb includes:

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

and that your specs have:

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