Skip to content

Instantly share code, notes, and snippets.

@jimmylorunning
Created January 5, 2015 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmylorunning/26cfa271d9c6fa4831d1 to your computer and use it in GitHub Desktop.
Save jimmylorunning/26cfa271d9c6fa4831d1 to your computer and use it in GitHub Desktop.
stubbing devise authentication
module ControllerHelpers
def sign_in(user = double('user'))
if user.nil?
allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user})
allow(controller).to receive(:current_user).and_return(nil)
else
allow(request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end
end
end
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.include ControllerHelpers, :type => :controller
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment