From ed0e38f441d36a72f5281faa1db1b0152dc184fd Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 23 May 2018 01:29:19 -0700 Subject: [PATCH] extract method. --- lib/database_cleaner/base.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/database_cleaner/base.rb b/lib/database_cleaner/base.rb index 9691cf6..17b05a4 100644 --- a/lib/database_cleaner/base.rb +++ b/lib/database_cleaner/base.rb @@ -163,16 +163,18 @@ module DatabaseCleaner rescue NameError $stderr.puts <<-TEXT Requiring the `database_cleaner` gem directly is deprecated, and will raise an error in database_cleaner 2.0. Instead, please require the specific gem (or gems) for your ORM. - For example, replace `gem "database_cleaner"` with `gem "database_cleaner-active_record"` in your Gemfile. See ### for more information. + For example, replace `gem "database_cleaner"` with `gem "database_cleaner-#{orm}"` in your Gemfile. TEXT - begin - require "database_cleaner/#{orm.to_s}/#{strategy.to_s}" - rescue LoadError - raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}" - end + require_orm_strategy(orm, strategy) retry end + def require_orm_strategy(orm, strategy) + require "database_cleaner/#{orm.to_s}/#{strategy.to_s}" + rescue LoadError + raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}" + end + def autodetect @autodetected = true