Skip to content

Instantly share code, notes, and snippets.

@mattsnyder
Created June 17, 2011 14:07
Show Gist options
  • Save mattsnyder/1031474 to your computer and use it in GitHub Desktop.
Save mattsnyder/1031474 to your computer and use it in GitHub Desktop.
Easy faking of user authentication in RSpec when using Devise
module AuthenticationHelpers
# Example usage: login mock_user(Editor)
def login(user)
request.env['warden'] = mock(Warden,
:authenticate => user,
:authenticate! => user)
end
def mock_user(type, stubs={})
mock_model(type, stubs).as_null_object
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment