From 579c7b4d5dd221949639c515df7c6dffed6996d3 Mon Sep 17 00:00:00 2001 From: Darcy Laycock Date: Sun, 10 Jun 2012 11:15:19 +0800 Subject: [PATCH] Add Rspec2 macros --- lib/reversible_data.rb | 1 + lib/reversible_data/rspec2_macros.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 lib/reversible_data/rspec2_macros.rb diff --git a/lib/reversible_data.rb b/lib/reversible_data.rb index b19328d..a82616f 100644 --- a/lib/reversible_data.rb +++ b/lib/reversible_data.rb @@ -8,6 +8,7 @@ module ReversibleData autoload :Table, 'reversible_data/table' autoload :TableManager, 'reversible_data/table_manager' autoload :ShouldaMacros, 'reversible_data/shoulda_macros' + autoload :RSpec2Macros, 'reversible_data/rspec2_macros' def self.add(name, opts = {}, &blk) Table.new(name, opts, &blk) diff --git a/lib/reversible_data/rspec2_macros.rb b/lib/reversible_data/rspec2_macros.rb new file mode 100644 index 0000000..fbc75db --- /dev/null +++ b/lib/reversible_data/rspec2_macros.rb @@ -0,0 +1,13 @@ +module ReversibleData + module RSpec2Macros + + def use_reversible_tables(*tables) + options = tables.extract_options! + scope = options.fetch(:scope, :each) + table_manager = ReversibleData.manager_for(*tables) + before(scope) { table_manager.up! } + after(scope) { table_manager.down! } + end + + end +end \ No newline at end of file