Skip to content

Instantly share code, notes, and snippets.

@rob-b
Forked from mattsnyder/authentication_helpers.rb
Created November 10, 2012 17:53
Show Gist options
  • Save rob-b/4051899 to your computer and use it in GitHub Desktop.
Save rob-b/4051899 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