Last active
July 6, 2023 19:51
-
-
Save dyanagi/eec2928c948bf6f6734d317627e63ea4 to your computer and use it in GitHub Desktop.
Ruby on Rails Capybara setting example
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
# /spec/support/capybara.rb | |
# Add the following line in rails_helper.rb to load this configuration. | |
# | |
# require_relative 'support/capybara' | |
# | |
require 'capybara/rspec' | |
require 'capybara-screenshot/rspec' | |
RSpec.configure do |config| | |
# Test Drivers - https://everydayrails.com/2018/01/08/rspec-3.7-system-tests.html | |
config.before(:each, type: :system) do | |
# Whether :js is true or not, this block will run when "type: :system" | |
driven_by :rack_test # Use :rack_test for faster execution, but it won't save pictures | |
# driven_by :selenium_chrome # Use :selenium_chrome to see the browser | |
# driven_by :selenium_chrome_headless # Use :rack_test for faster execution, but :selenium can save pictures | |
end | |
config.before(:each, type: :system, js: true) do | |
# When 'js: true' is added, this will "also" run and override the driver choice | |
driven_by :selenium_chrome_headless | |
end | |
Capybara.asset_host = 'http://localhost:3000' # For better looking HTML screenshots | |
# To use subdomain in the local environment, lvh.me is helpful to refer localhost easily | |
# Example: | |
# Capybara.app_host = 'http://lvh.me' | |
Capybara::Screenshot.prune_strategy = :keep_last_run # Remove old files | |
# Devise | |
# For Devise Log-in - https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara | |
config.include Warden::Test::Helpers | |
# To make sure Devise log-in works correctly, reset warden after each test | |
config.after(:each, type: :system) do | |
Warden.test_reset! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment