Permalink
Browse files

Cleanup the spec helper and spec rake task a bit

  • Loading branch information...
1 parent 195cc14 commit 09765829d38e78c0d260aac805c9f405a1523d56 Carl Lerche committed Mar 23, 2010
View
@@ -27,18 +27,21 @@ else
end
namespace :spec do
- for adapter in %w[mysql sqlite3 postgresql oracle]
- desc "Run specs with the #{adapter} database adapter"
+ %w[mysql sqlite3 postgresql oracle].each do |adapter|
+ task "set_env_for_#{adapter}" do
+ ENV['ADAPTER'] = adapter
+ end
+
Spec::Rake::SpecTask.new(adapter) do |t|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.libs << "#{File.dirname(__FILE__)}/vendor/rails/activerecord/lib"
t.libs << "#{File.dirname(__FILE__)}/spec"
# t.warning = true
- t.spec_files =
- ["spec/support/connections/#{adapter}_connection.rb"] +
- ["spec/support/schemas/#{adapter}_schema.rb"] +
- FileList['spec/**/*_spec.rb']
+ t.spec_files = FileList['spec/**/*_spec.rb']
end
+
+ desc "Run specs with the #{adapter} database adapter"
+ task adapter => "set_env_for_#{adapter}"
end
end
View
@@ -1,3 +1,3 @@
module Arel
- VERSION = "0.3.1"
+ VERSION = "0.3.1" unless defined?(Arel::VERSION)
end
View
@@ -7,6 +7,10 @@
require 'fileutils'
require 'arel'
+if adapter = ENV['ADAPTER']
+ require "support/connections/#{adapter}_connection.rb"
+end
+
Dir["#{dir}/{support,shared}/*.rb"].each do |file|
require file
end
@@ -16,13 +20,17 @@
config.include AdapterGuards
config.include Check
- config.before do
- Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base) if defined?(ActiveRecord::Base)
- end
-end
+ if defined?(ActiveRecord::Base)
+ tmp = File.expand_path('../../tmp', __FILE__)
-# load corresponding adapter using ADAPTER environment variable when running single *_spec.rb file
-if adapter = ENV['ADAPTER']
- require "#{dir}/support/connections/#{adapter}_connection.rb"
- require "#{dir}/support/schemas/#{adapter}_schema.rb"
+ FileUtils.mkdir_p(tmp)
+ ActiveRecord::Base.logger = Logger.new("#{tmp}/debug.log")
+ ActiveRecord::Base.establish_connection("unit")
+
+ require "support/schemas/#{ENV['ADAPTER']}_schema.rb"
+
+ config.before do
+ Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)
+ end
+ end
end
@@ -2,7 +2,7 @@
require "active_record"
require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
+ENV['ADAPTER'] = 'mysql'
ActiveRecord::Base.configurations = {
'unit' => {
@@ -11,6 +11,4 @@
:encoding => 'utf8',
:database => 'arel_unit',
}
-}
-
-ActiveRecord::Base.establish_connection 'unit'
+}
@@ -2,18 +2,16 @@
require "active_record"
require 'logger'
+ENV['ADAPTER'] = 'oracle'
+
# Prepend oracle_enhanced local development directory in front of load path
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../oracle-enhanced/lib"
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
ActiveRecord::Base.configurations = {
'unit' => {
:adapter => 'oracle_enhanced',
:username => 'arel_unit',
:password => 'arel_unit',
:database => 'orcl',
}
-}
-
-ActiveRecord::Base.establish_connection 'unit'
+}
@@ -2,14 +2,12 @@
require "active_record"
require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
+ENV['ADAPTER'] = 'postgresql'
ActiveRecord::Base.configurations = {
'unit' => {
:adapter => 'postgresql',
:encoding => 'utf8',
:database => 'arel_unit',
}
-}
-
-ActiveRecord::Base.establish_connection 'unit'
+}
@@ -2,7 +2,7 @@
require "active_record"
require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
+ENV['ADAPTER'] = 'sqlite3'
db_file = "spec/support/fixtures/fixture_database.sqlite3"
@@ -22,5 +22,3 @@
puts "Executing '#{sqlite_command}'"
raise "Seems that there is no sqlite3 executable available" unless system(sqlite_command)
end
-
-ActiveRecord::Base.establish_connection("unit")

0 comments on commit 0976582

Please sign in to comment.