# This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # Require this file using `require "spec_helper"` to ensure that it is only # loaded once. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration $LOAD_PATH.unshift(File.dirname(__FILE__)) ENV['RAILS_ENV'] ||= 'test' require File.expand_path("../dummy/config/environment.rb", __FILE__) require 'rspec/rails' require 'shoulda-matchers' require 'capybara/rails' require 'capybara/rspec' require 'selenium-webdriver' require 'webdrivers' require 'database_cleaner' require 'factory_bot' Capybara.register_driver :chrome do |app| Capybara::Selenium::Driver.new(app, browser: :chrome) end Capybara.register_driver :headless_chrome do |app| caps = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: { browser: 'ALL' }) opts = Selenium::WebDriver::Chrome::Options.new chrome_args = %w[--headless --window-size=1920,1080 --no-sandbox --disable-dev-shm-usage --enable-features=NetworkService,NetworkServiceInProcess] chrome_args.each { |arg| opts.add_argument(arg) } Capybara::Selenium::Driver.new(app, browser: :chrome, options: opts, desired_capabilities: caps) end Capybara.configure do |config| # change this to :chrome to observe tests in a real browser config.default_selector = :css config.javascript_driver = :headless_chrome end Rails.backtrace_cleaner.remove_silencers! # Load support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } DatabaseCleaner.strategy = :truncation RSpec.configure do |config| config.run_all_when_everything_filtered = true config.mock_with :rspec config.infer_base_class_for_anonymous_controllers = false # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = 'random' config.include Warden::Test::Helpers, type: :feature config.include FactoryBot::Syntax::Methods # Defines #create as FactoryBot.create config.before :all do FactoryBot.reload end config.before :each do DatabaseCleaner.clean_with :truncation end config.after(:each, :type => :feature) do DatabaseCleaner.clean # Truncate the database Capybara.reset_sessions! # Forget the (simulated) browser state Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver end end