From de3b1609f26d5becb0072d5a209a676d62e1a725 Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Mon, 23 May 2016 13:10:37 +1000 Subject: [PATCH 1/3] Make the NullStrategy API-complete --- lib/database_cleaner/null_strategy.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/database_cleaner/null_strategy.rb b/lib/database_cleaner/null_strategy.rb index eb67c97c..151484f5 100644 --- a/lib/database_cleaner/null_strategy.rb +++ b/lib/database_cleaner/null_strategy.rb @@ -11,5 +11,10 @@ def self.db=(connection) def self.clean # no-op end + + def self.cleaning + # no-op + yield + end end end From ea925ec33be78eba21d62896e7521a818433a350 Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Mon, 23 May 2016 14:07:23 +1000 Subject: [PATCH 2/3] specs for NullStrategy --- lib/database_cleaner/null_strategy.rb | 2 +- spec/database_cleaner/null_strategy_spec.rb | 28 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/database_cleaner/null_strategy_spec.rb diff --git a/lib/database_cleaner/null_strategy.rb b/lib/database_cleaner/null_strategy.rb index 151484f5..c232138d 100644 --- a/lib/database_cleaner/null_strategy.rb +++ b/lib/database_cleaner/null_strategy.rb @@ -14,7 +14,7 @@ def self.clean def self.cleaning # no-op - yield + yield if block_given? end end end diff --git a/spec/database_cleaner/null_strategy_spec.rb b/spec/database_cleaner/null_strategy_spec.rb new file mode 100644 index 00000000..80a3a7e5 --- /dev/null +++ b/spec/database_cleaner/null_strategy_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +module DatabaseCleaner + describe NullStrategy do + it 'responds to .start' do + expect { NullStrategy.start }.not_to raise_error(NoMethodError) + end + + it 'responds to .clean' do + expect { NullStrategy.clean }.not_to raise_error(NoMethodError) + end + + describe '.cleaning' do + it 'no-ops without a block' do + expect { NullStrategy.cleaning }.not_to raise_error(LocalJumpError) + end + + it 'no-ops with a block' do + effect = double + expect(effect).to receive(:occur).once + + NullStrategy.cleaning do + effect.occur + end + end + end + end +end From 73dcfef9e5ff116449961bb20c0dffe08dff036d Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Mon, 23 May 2016 14:10:22 +1000 Subject: [PATCH 3/3] NullStrategy.cleaning should LocalJumpError without a block, like the other strategies --- lib/database_cleaner/null_strategy.rb | 4 ++-- spec/database_cleaner/null_strategy_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/database_cleaner/null_strategy.rb b/lib/database_cleaner/null_strategy.rb index c232138d..f654572a 100644 --- a/lib/database_cleaner/null_strategy.rb +++ b/lib/database_cleaner/null_strategy.rb @@ -12,9 +12,9 @@ def self.clean # no-op end - def self.cleaning + def self.cleaning(&block) # no-op - yield if block_given? + yield end end end diff --git a/spec/database_cleaner/null_strategy_spec.rb b/spec/database_cleaner/null_strategy_spec.rb index 80a3a7e5..3fb1d149 100644 --- a/spec/database_cleaner/null_strategy_spec.rb +++ b/spec/database_cleaner/null_strategy_spec.rb @@ -11,8 +11,8 @@ module DatabaseCleaner end describe '.cleaning' do - it 'no-ops without a block' do - expect { NullStrategy.cleaning }.not_to raise_error(LocalJumpError) + it 'fails without a block' do + expect { NullStrategy.cleaning }.to raise_error(LocalJumpError) end it 'no-ops with a block' do