spec/spec_helper.rb in rom-sql-0.7.0 vs spec/spec_helper.rb in rom-sql-0.8.0
- old
+ new
@@ -1,47 +1,100 @@
# encoding: utf-8
require 'bundler'
Bundler.setup
-if RUBY_ENGINE == 'rbx'
+if RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.3.1'
require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start
end
require 'rom-sql'
require 'rom/sql/rake_task'
-# FIXME: why do we need to require it manually??
-require 'sequel/adapters/postgres'
-require 'active_support/inflector'
-
require 'logger'
+require 'tempfile'
+
begin
require 'byebug'
rescue LoadError # rubocop:disable Lint/HandleExceptions
end
LOGGER = Logger.new(File.open('./log/test.log', 'a'))
-DB_URI = 'postgres://localhost/rom_sql'
-root = Pathname(__FILE__).dirname
+if defined? JRUBY_VERSION
+ SQLITE_DB_URI = 'jdbc:sqlite:::memory'
+ POSTGRES_DB_URI = 'jdbc:postgresql://localhost/rom_sql'
+ MYSQL_DB_URI = 'jdbc:mysql://localhost/rom_sql?user=root'
+else
+ SQLITE_DB_URI = 'sqlite::memory'
+ POSTGRES_DB_URI = 'postgres://localhost/rom_sql'
+ MYSQL_DB_URI = 'mysql2://root@localhost/rom_sql'
+end
+
+URIS = { postgres: POSTGRES_DB_URI, sqlite: SQLITE_DB_URI, mysql: MYSQL_DB_URI }
+ADAPTERS = URIS.keys
+PG_LTE_95 = ENV.fetch('PG_LTE_95', 'true') == 'true'
+
+SPEC_ROOT = root = Pathname(__FILE__).dirname
TMP_PATH = root.join('../tmp')
-Dir[root.join('shared/*.rb').to_s].each { |f| require f }
+Dir[root.join('shared/**/*')].each { |f| require f }
+Dir[root.join('support/**/*')].each { |f| require f }
+require 'rom/support/deprecations'
+ROM::Deprecations.set_logger!(root.join('../log/deprecations.log'))
+
+def db?(type, example = nil)
+ if example
+ example.metadata[:adapter] == type
+ else
+ defined?(DB_URI) && DB_URI.include?(type.to_s)
+ end
+end
+
+def postgres?(example = nil)
+ db?(:postgres, example)
+end
+
+def mysql?(example = nil)
+ db?(:mysql, example)
+end
+
+def with_adapter(adapter, &block)
+ Object.const_set(:DB_URI, URIS[:mysql])
+ block.call
+ Object.send(:remove_const, :DB_URI)
+end
+
+def with_adapters(*args, &block)
+ adapters = args.empty? || args[0] == :all ? ADAPTERS : args
+
+ adapters.each do |adapter|
+ context("with #{adapter}", adapter: adapter, &block)
+ end
+end
+
RSpec.configure do |config|
+ config.disable_monkey_patching
+
config.before(:suite) do
tmp_test_dir = TMP_PATH.join('test')
FileUtils.rm_r(tmp_test_dir) if File.exist?(tmp_test_dir)
FileUtils.mkdir_p(tmp_test_dir)
end
+ config.around(adapter: :mysql) do |example|
+ with_adapter(:mysql) { example.run }
+ end
+
config.before do
- @constants = Object.constants
+ module Test
+ end
end
config.after do
- added_constants = Object.constants - @constants
- added_constants.each { |name| Object.send(:remove_const, name) }
+ Object.send(:remove_const, :Test)
end
+
+ config.include(Helpers, helpers: true)
end