Skip to content

Instantly share code, notes, and snippets.

@carlesjove
Forked from 5minpause/rspec.rb
Created March 22, 2018 07:04
Show Gist options
  • Save carlesjove/aef6ecafbde4b660fe4708674c1b63c6 to your computer and use it in GitHub Desktop.
Save carlesjove/aef6ecafbde4b660fe4708674c1b63c6 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment