Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Last active October 6, 2015 16:34
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 tncbbthositg/433442e05f9a6686edd5 to your computer and use it in GitHub Desktop.
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
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