Last active
October 6, 2015 16:34
-
-
Save tncbbthositg/433442e05f9a6686edd5 to your computer and use it in GitHub Desktop.
Rspec helper module that logs in a user and avails that user to scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LoginHelper | |
def sign_in(user) | |
@signed_in_user = user | |
visit root_path | |
fill_in "Username", with: user.username | |
fill_in "Password", with: user.password | |
click_on "Log in" | |
end | |
def signed_in_user | |
@signed_in_user | |
end | |
RSpec.configure do |config| | |
config.before(:each) do |example| | |
user_type = example.metadata[:sign_in] | |
next unless user_type | |
user = FactoryGirl.create(:user, user_type) | |
sign_in(user) | |
end | |
end | |
end | |
# usage | |
# feature "Logs in user", sign_in: :admin do | |
# scenario "the user is signed in" do | |
# expect(signed_in_user).to be_admin | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment