2010-06-15 14:24:50 +00:00
#Hilarious as it seems, this is necessary so bundle exec cucumber works for mongoid cukeage (I'm assuming mongomapper is automatically present because its a git repo)
Object . send ( :remove_const , 'MongoMapper' ) if defined? ( :: MongoMapper )
2009-03-01 08:45:58 +00:00
require 'rubygems'
2010-05-31 04:37:23 +00:00
require 'bundler'
2010-06-15 14:24:50 +00:00
2010-05-04 20:07:21 +00:00
Bundler . setup
2012-07-08 10:51:27 +00:00
require 'rspec/expectations'
2010-05-04 20:07:21 +00:00
require 'ruby-debug'
2009-03-01 08:45:58 +00:00
2010-05-25 17:21:45 +00:00
DB_DIR = " #{ File . dirname ( __FILE__ ) } /../../db "
2010-05-16 21:26:56 +00:00
orm = ENV [ 'ORM' ]
another_orm = ENV [ 'ANOTHER_ORM' ]
strategy = ENV [ 'STRATEGY' ]
2010-05-26 07:20:29 +00:00
multiple_db = ENV [ 'MULTIPLE_DBS' ]
2009-03-01 08:45:58 +00:00
2010-05-30 18:29:42 +00:00
2009-05-07 15:36:02 +00:00
if orm && strategy
2010-05-25 17:21:45 +00:00
$: . unshift ( File . dirname ( __FILE__ ) + '/../../../lib' )
require 'database_cleaner'
require 'database_cleaner/cucumber'
2010-05-31 03:12:58 +00:00
begin
require " #{ File . dirname ( __FILE__ ) } /../../lib/ #{ orm . downcase } _models "
rescue LoadError = > e
2009-05-07 15:36:02 +00:00
raise " You don't have the #{ orm } ORM installed "
end
2010-05-31 03:12:58 +00:00
2010-05-16 21:26:56 +00:00
if another_orm
2010-05-31 03:12:58 +00:00
begin
require " #{ File . dirname ( __FILE__ ) } /../../lib/ #{ another_orm . downcase } _models "
rescue LoadError = > e
2010-05-16 21:26:56 +00:00
raise " You don't have the #{ another_orm } ORM installed "
end
end
2009-03-01 08:45:58 +00:00
2010-05-31 03:12:58 +00:00
2010-08-23 20:50:32 +00:00
if multiple_db
2010-05-30 22:08:22 +00:00
DatabaseCleaner . app_root = " #{ File . dirname ( __FILE__ ) } /../.. "
orm_sym = orm . gsub ( / (.)([A-Z]+) / , '\1_\2' ) . downcase . to_sym
2010-05-31 03:12:58 +00:00
2010-05-30 22:08:22 +00:00
if orm_sym == :mongo_mapper
DatabaseCleaner [ orm_sym , { :connection = > 'database_cleaner_test_one' } ] . strategy = strategy . to_sym
DatabaseCleaner [ orm_sym , { :connection = > 'database_cleaner_test_two' } ] . strategy = strategy . to_sym
else
DatabaseCleaner [ orm_sym , { :connection = > :one } ] . strategy = strategy . to_sym
DatabaseCleaner [ orm_sym , { :connection = > :two } ] . strategy = strategy . to_sym
end
2010-05-31 03:12:58 +00:00
2010-05-26 07:20:29 +00:00
elsif another_orm
2010-05-25 17:21:45 +00:00
DatabaseCleaner [ orm . gsub ( / (.)([A-Z]+) / , '\1_\2' ) . downcase . to_sym ] . strategy = strategy . to_sym
DatabaseCleaner [ another_orm . gsub ( / (.)([A-Z]+) / , '\1_\2' ) . downcase . to_sym ] . strategy = strategy . to_sym
2010-05-26 07:20:29 +00:00
else
2011-01-16 16:34:45 +00:00
DatabaseCleaner . strategy = strategy . to_sym unless strategy == " default "
2010-05-25 17:21:45 +00:00
end
2010-05-31 03:12:58 +00:00
2009-05-07 15:36:02 +00:00
else
2011-01-16 16:34:45 +00:00
raise " Run 'ORM=ActiveRecord|DataMapper|MongoMapper|CouchPotato [ANOTHER_ORM=...] [MULTIPLE_DBS=true] STRATEGY=transaction|truncation|default cucumber examples/features' "
2009-05-07 15:36:02 +00:00
end