Refactor rspec config and support files

#206
This commit is contained in:
Artur Beljajev 2016-10-20 18:34:52 +03:00
parent e8dac5e45d
commit ee3ec69e54
9 changed files with 404 additions and 132 deletions

View file

@ -1,29 +1,28 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'capybara/poltergeist'
require 'paper_trail/frameworks/rspec'
PaperTrail.whodunnit = 'autotest'
require "money-rails/test_helpers"
require 'money-rails/test_helpers'
if ENV['ROBOT']
require 'simplecov'
SimpleCov.start 'rails'
end
# 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`.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
require 'support/matchers/alias_attribute'
require 'support/matchers/active_job'
require 'support/capybara'
require 'support/database_cleaner'
require 'support/epp'
require 'support/epp_doc'
require 'support/feature'
require 'support/registrar_helpers'
require 'support/request'
require 'support/autodoc'
require 'support/paper_trail'
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
# create general settings
@ -49,81 +48,44 @@ def create_settings
# speedup and easier to create fabrications
@fixed_registrar =
Registrar.find_by_name('fixed registrar') ||
Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED')
Registrar.find_by_name('fixed registrar') ||
Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED')
end
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.include ActionView::TestCase::Behavior, type: :presenter
config.include ActiveSupport::Testing::TimeHelpers
# 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.
config.use_transactional_fixtures = false
config.before(:suite) do
ActiveRecord::Base.establish_connection :api_log_test
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = nil
ActiveRecord::Base.establish_connection :test
config.define_derived_metadata(file_path: %r{/spec/presenters/}) do |metadata|
metadata[:type] = :presenter
metadata[:db] = false
end
config.use_transactional_fixtures = false
config.before(:all) do
DatabaseCleaner.clean_with(:truncation)
create_settings
end
config.before(:all, epp: true) do
DatabaseCleaner.strategy = nil
create_settings
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
create_settings
end
config.before(:each, type: :request) do
DatabaseCleaner.strategy = :truncation
create_settings
end
config.before(:each, type: :model) do
create_settings
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
config.after(:each, type: :model) do
DatabaseCleaner.clean
end
Capybara.javascript_driver = :poltergeist
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
Autodoc.configuration.path = 'doc/repp'
Autodoc.configuration.suppressed_request_header = ['Host']
Autodoc.configuration.suppressed_response_header = ['ETag', 'X-Request-Id', 'X-Runtime']
Autodoc.configuration.template = File.read('spec/requests/repp_doc_template.md.erb')
end