Skip to content

Instantly share code, notes, and snippets.

@krasio
Created November 18, 2011 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krasio/1375915 to your computer and use it in GitHub Desktop.
Save krasio/1375915 to your computer and use it in GitHub Desktop.
Rails controller specs with Devise
# spec/support/macros/authentication_macros.rb
module AuthenticationMacros
def sign_in_user
let(:current_user) { Factory.stub(:user) }
before do
sign_in current_user
warden.stub(:authenticate => current_user)
warden.stub(:authenticate! => current_user)
end
end
end
# spec/support/configuration.rb
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.extend AuthenticationMacros, :type => :controller
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment