Rspec test case for protected controller with devise “before_filter :authenticate_user!”


In rspec_helper.rb we need to add

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

and in spec_controller.rb file

before (:each) do
@user = FactoryGirl.create(:user)
sign_in @user
end

if using FactroyGirl.

OR

we can also add

include Devise::TestHelpers

in each and every controller where controller is protected. followed by sign_in @user

I hope it help.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s