Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created April 3, 2018 16:28
ENV['RAILS_ENV'] ||= 'test'
Minitest::Reporters.use!
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
require "database_cleaner"
require 'capybara/rails'
require 'capybara/minitest'
class ActiveSupport::TestCase
include FactoryBot::Syntax::Methods
end
# Capybara setup
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
Capybara.server = :puma # Until your setup is working
Capybara.javascript_driver = :webkit
# Reset sessions and driver between tests
# Use super wherever this method is redefined in your individual test classes
def teardown
Capybara.reset_sessions!
end
end
Capybara::Webkit.configure do |config|
config.block_unknown_urls
end
# Database cleaner setup
DatabaseCleaner.strategy = :transaction
module AroundEachTest
def before_setup
super
DatabaseCleaner.start
end
def after_teardown
super
DatabaseCleaner.clean
end
end
class Minitest::Test
include AroundEachTest
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment