Refactoring: Move all RSpec configurations to dedicated support files.
This commit is contained in:
parent
9c7ddb7a9d
commit
dc18e883ce
7 changed files with 45 additions and 56 deletions
|
@ -6,8 +6,10 @@ require File.expand_path('../config/environment', __dir__)
|
|||
|
||||
# Prevent database truncation if the environment is production
|
||||
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
||||
|
||||
require 'spec_helper'
|
||||
require 'rspec/rails'
|
||||
|
||||
# Add additional requires below this line. Rails is not loaded until this point!
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||
|
@ -24,58 +26,3 @@ require 'rspec/rails'
|
|||
# require only the support files necessary.
|
||||
#
|
||||
Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f }
|
||||
|
||||
# Reset database to be ready for tests
|
||||
Rake::Task['zammad:db:reset'].execute
|
||||
|
||||
# make sure that all migrations of linked packages are executed
|
||||
Package::Migration.linked
|
||||
|
||||
RSpec.configure do |config|
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
# make usage of time travel helpers possible
|
||||
config.include ActiveSupport::Testing::TimeHelpers
|
||||
config.after do
|
||||
travel_back
|
||||
end
|
||||
|
||||
# Zammad specific helpers
|
||||
config.include ZammadHelper
|
||||
|
||||
# skip Zammad helper functions in the stacktrace to lower noise
|
||||
config.backtrace_exclusion_patterns << %r{/spec/spec_helper/}
|
||||
|
||||
# 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 = true
|
||||
|
||||
# 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!
|
||||
|
||||
# Filter lines from Rails gems in backtraces.
|
||||
config.filter_rails_from_backtrace!
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
end
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
config.integrate do |with|
|
||||
with.test_framework :rspec
|
||||
with.library :rails
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
require_relative './rake'
|
||||
|
||||
# Reset database to be ready for tests
|
||||
Rake::Task['zammad:db:reset'].execute
|
||||
|
||||
# make sure that all migrations of linked packages are executed
|
||||
Package::Migration.linked
|
8
spec/support/db_transactional_fixtures.rb
Normal file
8
spec/support/db_transactional_fixtures.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
RSpec.configure do |config|
|
||||
# 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 = true
|
||||
end
|
5
spec/support/fixtures.rb
Normal file
5
spec/support/fixtures.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
end
|
|
@ -1,7 +1,15 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module ZammadHelper
|
||||
module OtrsImportJsonFixtureHelper
|
||||
def json_fixture(file)
|
||||
JSON.parse(File.read("spec/fixtures/#{file}.json"))
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
# Zammad specific helpers
|
||||
config.include OtrsImportJsonFixtureHelper
|
||||
|
||||
# skip OtrsImportJsonFixtureHelper functions in the backtraces to lower noise
|
||||
config.backtrace_exclusion_patterns << %r{/spec/spec_helper/}
|
||||
end
|
||||
|
|
8
spec/support/rails_backtrace_filter.rb
Normal file
8
spec/support/rails_backtrace_filter.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
RSpec.configure do |config| # rubocop:disable Style/SymbolProc
|
||||
# Filter lines from Rails gems in backtraces.
|
||||
config.filter_rails_from_backtrace!
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
end
|
8
spec/support/shoulda_matchers.rb
Normal file
8
spec/support/shoulda_matchers.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
config.integrate do |with|
|
||||
with.test_framework :rspec
|
||||
with.library :rails
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue