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

时间:2011-08-04 22:29:21

标签: ruby-on-rails rspec devise integration-testing

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

当我在rspec集成/请求测试中访问我的登录页面时,出现以下错误:

ActionView::Template::Error:
   undefined method `title' for #<#<Class:0x00000007af9180>:0x00000007af32a8>

标题方法由视图使用,并在ApplicationHelper中定义,设计似乎在使用浏览器时找到。但是,在rspec集成测试期间,设计无法找到辅助方法。

我有什么东西要瞎扯吗?在集成测试中进行存根似乎是错误的。还有其他想法吗?

(这个问题不是关于如何在集成测试中包含设计助手。我手动填写登录表单进行身份验证)。

3 个答案:

答案 0 :(得分:7)

看起来像this issue。 (在某些情况下与ActiveAdmin https://github.com/gregbell/active_admin/wiki/Use-spork相关)

Here我找到了适用于我的黑客(REE 1.8.7,Rails 3.1,Capybara,Devise,active_admin)。

但是,这不太可能合并,所以我将spork-rails分叉到here并应用了该补丁。而你可能知道我可以将我的Gemfile指向该回购:

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

不是最佳,但它现在完成了工作。

答案 1 :(得分:2)

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

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

我通过将模块包含在env.rb

中解决了这个问题
Spork.prefork do
  include FlashBlockHelper

我希望这会有所帮助。

答案 2 :(得分:1)

Inside / 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'