diff --git a/lib/database_cleaner/base.rb b/lib/database_cleaner/base.rb index f2aba04..6ccfeca 100644 --- a/lib/database_cleaner/base.rb +++ b/lib/database_cleaner/base.rb @@ -11,8 +11,8 @@ module DatabaseCleaner [orm, db] <=> [other.orm, other.db] end - def initialize(desired_orm = nil, opts = {}) - self.orm = desired_orm + def initialize(orm = :null, opts = {}) + self.orm = orm self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model) Safeguard.new.run end @@ -44,8 +44,9 @@ module DatabaseCleaner attr_reader :orm - def orm=(desired_orm) - @orm = desired_orm && desired_orm.to_sym + def orm= orm + raise ArgumentError if orm.nil? + @orm = orm.to_sym end extend Forwardable diff --git a/lib/database_cleaner/configuration.rb b/lib/database_cleaner/configuration.rb index bb32294..d690ff4 100644 --- a/lib/database_cleaner/configuration.rb +++ b/lib/database_cleaner/configuration.rb @@ -4,13 +4,12 @@ require 'forwardable' module DatabaseCleaner - class NoORMDetected < StandardError; end class UnknownStrategySpecified < ArgumentError; end class Cleaners < Hash # FIXME this method conflates creation with lookup... both a command and a query. yuck. def [](orm, opts = {}) - raise NoORMDetected unless orm + raise ArgumentError if orm.nil? fetch([orm, opts]) { add_cleaner(orm, opts) } end diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 4f29225..7967139 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -46,15 +46,14 @@ module DatabaseCleaner expect(cleaner.orm).to eq :mongoid end - it "should default to nil" do + it "should default to :null" do cleaner = Base.new - expect(cleaner.orm).to be_nil + expect(cleaner.orm).to eq :null end - it "can handle being set to nil" do + it "raises ArgumentError when explicitly set to nil" do cleaner = Base.new - cleaner.orm = nil - expect(cleaner.orm).to be_nil + expect { cleaner.orm = nil }.to raise_error(ArgumentError) end end end diff --git a/spec/database_cleaner/configuration_spec.rb b/spec/database_cleaner/configuration_spec.rb index dfe0609..21a13d5 100644 --- a/spec/database_cleaner/configuration_spec.rb +++ b/spec/database_cleaner/configuration_spec.rb @@ -12,8 +12,8 @@ RSpec.describe DatabaseCleaner::Configuration do subject(:config) { described_class.new } context "orm specification" do - it "should not accept unrecognised orms" do - expect { config[nil] }.to raise_error(DatabaseCleaner::NoORMDetected) + it "should not accept nil orms" do + expect { config[nil] }.to raise_error(ArgumentError) end it "should accept :active_record" do