Skip to content

Instantly share code, notes, and snippets.

@5minpause
Created March 7, 2018 12:19
Show Gist options
  • Save 5minpause/91ce01a51ee5cc6e5059321f0bdbca08 to your computer and use it in GitHub Desktop.
Save 5minpause/91ce01a51ee5cc6e5059321f0bdbca08 to your computer and use it in GitHub Desktop.
how to use sessions with capybara
# support/setup.rb
def in_browser(name)
old_session = Capybara.session_name
Capybara.session_name = name
yield
ensure
Capybara.session_name = old_session
end
# in a spec file
in_browser(:guest) do
sign_in(guest)
# do what you want
end
in_browser(:admin) do
sign_in(admin)
# do something else
end
# etc.
@5minpause
Copy link
Author

inspired by @niklas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment