8
votes

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).

3
Did you ever get anywhere with this, Nathan? I'm having the same issue when using capybara and rspec request specs; if a view involved in the test calls any helper methods, I'll get an exception. In my case, this only happens if I've got guard running; running rspec by hand works. Thankswkhatch
No. I didn't. However, I found that in some cases, spork was causing problems for me (some tests worked when run outside spork).Nathan Hurst
Thanks. I did some more testing and found that spork is the culprit. Haven't determined exactly what the issue is, but without spork, it's fine.wkhatch

3 Answers

7
votes

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.

2
votes

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.

1
votes

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'