require 'coveralls' Coveralls.wear! <% unless @plugin -%> $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require '<%= @gem_name %>' <% end -%> require 'minitest/autorun' require 'minitest/reporters' <% if @plugin -%> require 'minitest/reporters/screenshot_reporter' Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new, Minitest::Reporters::JUnitReporter.new, Minitest::Reporters::ScreenshotReporter.new] <% else -%> Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new <% end -%> # Filter out Minitest backtrace while allowing backtrace from other libraries to be shown. Minitest.backtrace_filter = Minitest::BacktraceFilter.new <% if @plugin -%> require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)] <% if @mountable -%> ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) <% end -%> require "rails/test_help" # Load support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } # Load fixtures from the engine if ActiveSupport::TestCase.respond_to?(:fixture_path=) ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path ActiveSupport::TestCase.fixtures :all end # default test class for unit tests class UnitTest < ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all end # configure webtests with capybara and poltergeist (headless) require 'capybara/rails' require 'capybara_minitest_spec' require 'capybara/poltergeist' CAPYBARA_WINDOW_SIZE = [1024, 768] if ENV['HEADLESS'] == 'true' # headless driver configuration Capybara.register_driver :poltergeist do |app| poltergeist_options = { debug: false, timeout: 30, js_errors: true, window_size: CAPYBARA_WINDOW_SIZE } Capybara::Poltergeist::Driver.new(app, poltergeist_options) end Capybara.default_driver = :poltergeist else # chrome browser driver configuration Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) end Capybara.default_driver = :selenium Capybara.current_session.driver.browser.manage.window.resize_to CAPYBARA_WINDOW_SIZE[0], CAPYBARA_WINDOW_SIZE[1] end Capybara.default_max_wait_time = 5 # how long should capybara wait for elements to appear on the page (ajax) # use database_cleaner to clean the database after every test with truncation, instead of using transactional fixtures require 'database_cleaner' DatabaseCleaner.strategy = :truncation # default test class for webtests class WebTest < ActionDispatch::IntegrationTest include Capybara::DSL extend Minitest::Spec::DSL include Minitest::Reporters::Screenshot # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # disable transactional fixtures, as we use DatabaseCleaner self.use_transactional_fixtures = false # clean database after each test with database_cleaner def after_teardown super DatabaseCleaner.clean end end <% end -%>