Created
March 13, 2018 11:57
-
-
Save TheRealNeil/9f6973f7ea5496d916bef2a3d43bb128 to your computer and use it in GitHub Desktop.
Template Test Helper
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
ENV["RAILS_ENV"] = "test" | |
require File.expand_path("../../config/environment", __FILE__) | |
require "rails/test_help" | |
require "minitest/reporters" | |
require 'capybara/rails' | |
require 'capybara/minitest' | |
require 'selenium-webdriver' | |
require 'capybara-screenshot/minitest' | |
require "database_cleaner" | |
# Use MiniTest Reporters for integrating with RubyMine | |
Minitest::Reporters.use! | |
# Configure Capybara | |
Capybara.register_driver :selenium_chrome_headless do |app| | |
options = Selenium::WebDriver::Chrome::Options.new( | |
args: %w[headless disable-gpu no-sandbox window-size=1440,800] | |
) | |
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) | |
end | |
Capybara.default_driver = :selenium_chrome_headless | |
Capybara.javascript_driver = :selenium_chrome_headless | |
# Keep screenshots generated from the last failing test suite | |
Capybara::Screenshot.prune_strategy = :keep_last_run | |
Capybara.asset_host = 'http://public.lvh.me:3000' | |
# Configure Database Cleaner | |
DatabaseCleaner.strategy = :truncation | |
class ActiveSupport::TestCase | |
# Add more helper methods to be used by all tests here... | |
end | |
class ActionController::TestCase | |
include Devise::Test::ControllerHelpers | |
end | |
class ActionDispatch::IntegrationTest | |
# Make the Capybara DSL available in all integration tests | |
include Capybara::DSL | |
# Make `assert_*` methods behave like Minitest assertions | |
include Capybara::Minitest::Assertions | |
# include warden helpers to provide login_as | |
include Warden::Test::Helpers | |
# Capture Screenshots for failing tests | |
include Capybara::Screenshot::MiniTestPlugin | |
# Reset sessions and driver between tests | |
def teardown | |
DatabaseCleaner.clean | |
Capybara.reset_sessions! | |
Capybara.use_default_driver | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment