spec/bitcoin/spec_helper.rb in bitcoin-ruby-0.0.3 vs spec/bitcoin/spec_helper.rb in bitcoin-ruby-0.0.4
- old
+ new
@@ -100,5 +100,26 @@
puts "Note: to run all the tests, you will also need: ffi, sequel, sqlite3"
exit 1
end
Bacon.summary_on_exit
require 'minitest/mock'
+
+require 'sequel'
+def setup_db backend, db = nil, conf = {}
+ uri = case db
+ when :sqlite
+ "sqlite:/"
+ when :postgres
+ ENV["TEST_DB_POSTGRES"].dup rescue nil
+ when :mysql
+ ENV["TEST_DB_MYSQL"].dup rescue nil
+ end
+ if [:postgres, :mysql].include?(db)
+ unless uri
+ puts "Skipping #{db} tests"
+ return nil
+ end
+ db = Sequel.connect(uri)
+ db.drop_table(*db.tables, cascade: true)
+ end
+ Bitcoin::Storage.send(backend, conf.merge(db: uri, log_level: :warn))
+end