2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-04-08 18:28:17 +02:00
|
|
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2014-07-06 23:27:50 +02:00
|
|
|
require 'simplecov'
|
|
|
|
|
|
|
|
|
|
if ENV['TRAVIS']
|
2018-05-15 09:21:41 -07:00
|
|
|
require 'codecov'
|
|
|
|
|
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
2014-07-06 23:27:50 +02:00
|
|
|
end
|
2018-05-15 09:21:41 -07:00
|
|
|
SimpleCov.start 'rails'
|
2014-07-06 23:27:50 +02:00
|
|
|
|
2014-05-10 10:24:58 +02:00
|
|
|
ENV['RAILS_ENV'] ||= 'test'
|
|
|
|
|
require File.expand_path('../../config/environment', __FILE__)
|
2014-05-08 12:05:57 -07:00
|
|
|
|
2014-04-08 18:28:17 +02:00
|
|
|
require 'rspec/rails'
|
2015-10-11 23:10:01 -07:00
|
|
|
require 'shoulda/matchers'
|
2014-07-04 22:35:47 +02:00
|
|
|
# To avoid confusion on missed migrations - use Rails 4 checker to ensure
|
|
|
|
|
# all migrations applied
|
|
|
|
|
ActiveRecord::Migration.maintain_test_schema!
|
|
|
|
|
|
2018-11-16 11:57:51 -08:00
|
|
|
# Keep capybara and the database on the same page
|
|
|
|
|
require 'transactional_capybara/rspec'
|
|
|
|
|
|
2018-10-25 10:50:13 -07:00
|
|
|
require 'selenium/webdriver'
|
2014-04-08 18:28:17 +02:00
|
|
|
|
2016-05-24 23:54:46 +05:30
|
|
|
# Adds rspec helper provided by paper_trail
|
|
|
|
|
# makes it easier to control when PaperTrail is enabled during testing.
|
|
|
|
|
require 'paper_trail/frameworks/rspec'
|
|
|
|
|
|
2017-11-07 17:57:45 -08:00
|
|
|
# Make htmlescape() available
|
|
|
|
|
require 'erb'
|
|
|
|
|
include ERB::Util
|
|
|
|
|
|
2014-04-08 18:28:17 +02:00
|
|
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
|
|
|
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
|
|
|
|
# run as spec files by default. This means that files in spec/support that end
|
|
|
|
|
# in _spec.rb will both be required and run as specs, causing the specs to be
|
|
|
|
|
# run twice. It is recommended that you do not name files matching this glob to
|
|
|
|
|
# end with _spec.rb. You can configure this pattern with with the --pattern
|
|
|
|
|
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
2014-05-10 10:24:58 +02:00
|
|
|
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
2014-04-08 18:28:17 +02:00
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
|
# ## Mock Framework
|
|
|
|
|
#
|
|
|
|
|
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
|
|
|
#
|
|
|
|
|
# config.mock_with :mocha
|
|
|
|
|
# config.mock_with :flexmock
|
|
|
|
|
# config.mock_with :rr
|
|
|
|
|
|
|
|
|
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
|
|
|
# examples within a transaction, remove the following line or assign false
|
|
|
|
|
# instead of true.
|
2014-05-10 15:55:17 +02:00
|
|
|
config.use_transactional_fixtures = false
|
2014-04-08 18:28:17 +02:00
|
|
|
|
|
|
|
|
# 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
|
2014-05-10 10:24:58 +02:00
|
|
|
config.order = 'random'
|
2014-04-09 01:32:47 +02:00
|
|
|
|
2018-10-25 10:50:13 -07:00
|
|
|
Capybara.register_driver :firefox do |app|
|
|
|
|
|
Capybara::Selenium::Driver.new(app, browser: :firefox)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Capybara.register_driver :chrome do |app|
|
|
|
|
|
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Capybara.register_driver :firefox_headless do |app|
|
|
|
|
|
options = Selenium::WebDriver::Firefox::Options.new
|
|
|
|
|
options.args << '--headless'
|
|
|
|
|
options.args << '--window-size=1920,1080'
|
|
|
|
|
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
|
|
|
|
|
end
|
2014-05-10 17:53:31 +02:00
|
|
|
|
2018-10-25 10:50:13 -07:00
|
|
|
Capybara.register_driver :chrome_headless do |app|
|
|
|
|
|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
2018-10-25 16:16:56 -07:00
|
|
|
chromeOptions: { args: %w(headless disable-gpu window-size=1920x1080) }
|
2018-10-25 10:50:13 -07:00
|
|
|
)
|
|
|
|
|
Capybara::Selenium::Driver.new(
|
|
|
|
|
app, browser: :chrome, desired_capabilities: capabilities
|
2018-02-25 16:31:55 -08:00
|
|
|
)
|
2014-08-05 18:23:42 +02:00
|
|
|
end
|
|
|
|
|
|
2018-10-25 10:50:13 -07:00
|
|
|
Capybara.default_max_wait_time = 10 # seconds
|
|
|
|
|
|
|
|
|
|
# use a real browser for JS tests
|
|
|
|
|
Capybara.javascript_driver = (
|
|
|
|
|
ENV['OSEM_TEST_DRIVER'].try(:to_sym) || :chrome_headless
|
|
|
|
|
)
|
|
|
|
|
|
2014-07-04 22:35:47 +02:00
|
|
|
# Includes helpers and connect them to specific types of tests
|
2018-09-03 20:44:39 +02:00
|
|
|
config.include FactoryBot::Syntax::Methods
|
2014-07-04 22:35:47 +02:00
|
|
|
config.include OmniauthMacros
|
|
|
|
|
config.include Devise::TestHelpers, type: :controller
|
2014-05-10 17:54:56 +02:00
|
|
|
config.include LoginMacros, type: :feature
|
2014-05-14 13:18:19 +02:00
|
|
|
config.include Flash, type: :feature
|
2014-05-19 12:24:48 +05:30
|
|
|
config.include Sidebar, type: :view
|
2014-07-04 22:35:47 +02:00
|
|
|
config.include Devise::TestHelpers, type: :view
|
2014-05-19 12:24:48 +05:30
|
|
|
|
2014-04-09 01:32:47 +02:00
|
|
|
# As we start from scratch in April 2014, let's forbid the old :should syntax
|
|
|
|
|
config.expect_with :rspec do |c|
|
|
|
|
|
c.syntax = :expect
|
2014-05-08 12:05:57 -07:00
|
|
|
end
|
2014-07-04 22:35:47 +02:00
|
|
|
|
|
|
|
|
# Reuse rspec as mocking framework
|
|
|
|
|
config.mock_framework = :rspec
|
|
|
|
|
|
|
|
|
|
# Types of tests (controller, feature, model) will
|
|
|
|
|
# be inferred from subfolder name
|
|
|
|
|
config.infer_spec_type_from_file_location!
|
2017-10-10 20:23:54 -07:00
|
|
|
|
|
|
|
|
# Enable this if you like to see what you're debugging
|
|
|
|
|
# config.after(:example) do |example|
|
|
|
|
|
# if example.exception
|
|
|
|
|
# save_and_open_screenshot
|
|
|
|
|
# save_and_open_page
|
|
|
|
|
# end
|
|
|
|
|
# end
|
2014-04-08 18:28:17 +02:00
|
|
|
end
|
2014-06-18 16:58:30 +03:00
|
|
|
|
|
|
|
|
OmniAuth.config.test_mode = true
|