View helper methods not included in Devise views in rspec integration / query tests?

When I visit my browser login page, everything works fine.

When I visit my rspec integration test login page, I get the following error:

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

The title method is used in the view and is defined in the ApplicationHelper, which appears to be found when using the browser. However, during the integration tests of rspec, the developer cannot find a helper method.

Is there anything I would need to bite? The integration tests seem to fulfill the requirements. Any other ideas?

(This question is not about how to include development assistants in integration tests). I manually fill out the sign in the forms for authentication).

+8
ruby-on-rails integration-testing rspec devise
source share
3 answers

Looks like this question . (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 unlikely to be combined, so I forked spork-rails on here with this fix. And, as you probably know, I can point my Gemfile to this repo:

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

Not optimal, but now it’s being done.

+7
source share

I had a similar problem using Cucumber when I installed the program:

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

I solved this by including the module in env.rb

 Spork.prefork do include FlashBlockHelper 

Hope this helps.

+2
source share

Inside / spec / support, create devise.rb as follows:

 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 what your specifications have:

 require 'spec_helper' 
+1
source share

All Articles