All Ruby tests raising: undefined method `authenticate' for nil:NilClass
This question has been answered on Twitter by @MatthewClosson
@jeffehh You need to create a spec/support/devise.rb file as specified here https://github.com/plataformatec/devise#test-helpers to include the devise test helpers #ruby
Thanks once again.
I'm aware you're using Rspec but you can run into this same issue with Test::Unit
. You just need to add the devise test helpers to test/test_helper.rb
class ActiveSupport::TestCase include Devise::TestHelpersend
in RSpec
as Jeffrey W. mentioned, in his answer above -> to set this to all controllers:
RSpec.configure do |config| # ... config.include Devise::TestHelpers, type: :controller # ...end
however, if this is relevant to just one spec, you don't necessarily need to include devise helpers to all your controllers specs, you can just explicitly include those helpers in that one controller describe block:
require 'spec_helper'describe MyCoolController include Devise::TestHelpers it { } end