OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/spec/support/rspec_cleanup.rb

34 lines
1.0 KiB

RSpec.configure do |config|
config.before(:each) do
# Clear any mail deliveries
# This happens automatically for :mailer specs
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.deliveries.clear
RequestStore.clear!
end
config.append_after(:each) do
# Cleanup after specs changing locale explicitly or
# by calling code in the app setting changing the locale.
I18n.locale = :en unless I18n.locale == :en
# Set the class instance variable @current_user to nil
# to avoid having users from one spec present in the next
::User.instance_variable_set(:@current_user, nil)
end
# We don't want this to be reported on CI as it breaks the build
unless ENV['CI']
config.after(:suite) do
[User, Project, WorkPackage].each do |cls|
next if cls.count == 0
raise <<-EOS
Your specs left a #{cls} in the DB
Did you use before(:all) instead of before
or forget to kill the instances in a after(:all)?
EOS
end
end
end
end