diff --git a/lib/database_cleaner/configuration.rb b/lib/database_cleaner/configuration.rb index 1ce180b..6e1e136 100644 --- a/lib/database_cleaner/configuration.rb +++ b/lib/database_cleaner/configuration.rb @@ -23,6 +23,12 @@ module DatabaseCleaner orm_strategy(strategy).new(*strategy_args) end + def clean_with(*args) + strategy = create_strategy(*args) + strategy.clean + strategy + end + def strategy=(args) strategy, *strategy_args = args if strategy.is_a?(Symbol) diff --git a/spec/database_cleaner/configuration_spec.rb b/spec/database_cleaner/configuration_spec.rb index cfb54df..cecae80 100644 --- a/spec/database_cleaner/configuration_spec.rb +++ b/spec/database_cleaner/configuration_spec.rb @@ -22,7 +22,7 @@ describe DatabaseCleaner do end describe ".create_strategy ( DatabaseCleaner() )" do - it "should initialize and return the appropirate strategy based on the ORM adapter detected" do + it "should initialize and return the appropirate strategy" do DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash') result = DatabaseCleaner(:transaction, {'options' => 'hash'}) @@ -30,6 +30,15 @@ describe DatabaseCleaner do end end + describe ".clean_with" do + it "should initialize the appropirate strategy and clean with it" do + DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash') + @strategy.should_receive(:clean) + + DatabaseCleaner.clean_with(:transaction, 'options' => 'hash') + end + end + describe ".strategy=" do it "should initialize the appropirate strategy based on the ORM adapter detected" do DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')