2010-02-26 04:53:30 +01:00
|
|
|
ENV["RAILS_ENV"] = "test"
|
|
|
|
require 'pathname'
|
|
|
|
this_dir = Pathname.new File.dirname(__FILE__)
|
|
|
|
$LOAD_PATH << this_dir.join("../lib")
|
|
|
|
|
|
|
|
gem "rails", "3.0.0.beta"
|
|
|
|
require "rails"
|
|
|
|
require "rails/test_help"
|
|
|
|
require "active_record/fixtures"
|
2010-03-12 05:52:16 +01:00
|
|
|
require "active_support/test_case"
|
|
|
|
require 'active_support/core_ext/object/returning'
|
|
|
|
|
|
|
|
require "delorean"
|
2010-02-26 04:53:30 +01:00
|
|
|
|
2010-04-09 02:57:10 +02:00
|
|
|
require "active_record"
|
2010-02-26 04:53:30 +01:00
|
|
|
require "logger"
|
|
|
|
|
|
|
|
require "ruby-debug"
|
|
|
|
|
|
|
|
class ActiveSupport::TestCase
|
|
|
|
include ActiveRecord::TestFixtures
|
|
|
|
self.use_transactional_fixtures = true
|
|
|
|
|
|
|
|
class << self
|
2010-03-14 03:33:03 +01:00
|
|
|
def assertion(name, &block)
|
|
|
|
mc = class << self ; self ; end
|
|
|
|
mc.class_eval do
|
|
|
|
define_method(name) do
|
|
|
|
it(name, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-14 04:01:01 +01:00
|
|
|
|
|
|
|
def asssertion_group(name, &block)
|
|
|
|
mc = class << self ; self ; end
|
|
|
|
mc.class_eval do
|
|
|
|
define_method(name, &block)
|
|
|
|
end
|
|
|
|
end
|
2010-03-14 03:33:03 +01:00
|
|
|
|
|
|
|
def macro(name, &block)
|
|
|
|
class_eval do
|
|
|
|
define_method(name, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-26 04:53:30 +01:00
|
|
|
def describe(description, toplevel=nil, &blk)
|
|
|
|
text = toplevel ? description : "#{name} #{description}"
|
|
|
|
klass = Class.new(self)
|
2010-03-14 04:01:01 +01:00
|
|
|
|
2010-02-26 04:53:30 +01:00
|
|
|
klass.class_eval <<-RUBY_EVAL
|
|
|
|
def self.name
|
|
|
|
"#{text}"
|
|
|
|
end
|
|
|
|
RUBY_EVAL
|
2010-03-14 04:01:01 +01:00
|
|
|
|
|
|
|
# do not inherit test methods from the superclass
|
|
|
|
klass.class_eval do
|
|
|
|
instance_methods.grep(/^test.+/) do |method|
|
|
|
|
undef_method method
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-26 04:53:30 +01:00
|
|
|
klass.instance_eval &blk
|
|
|
|
end
|
|
|
|
alias_method :context, :describe
|
|
|
|
|
|
|
|
def let(name, &blk)
|
2010-03-12 05:52:16 +01:00
|
|
|
values = {}
|
|
|
|
define_method(name) do
|
|
|
|
return values[name] if values.has_key?(name)
|
|
|
|
values[name] = instance_eval(&blk)
|
|
|
|
end
|
2010-02-26 04:53:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def it(description, &blk)
|
|
|
|
define_method("test: #{name} #{description}", &blk)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def describe(description, &blk)
|
|
|
|
ActiveSupport::TestCase.describe(description, true, &blk)
|
|
|
|
end
|
|
|
|
|
2010-03-12 05:52:16 +01:00
|
|
|
# load test helpers
|
|
|
|
require "rails"
|
|
|
|
class MyApplication < Rails::Application ; end
|
2010-03-14 02:20:55 +01:00
|
|
|
adapter = ENV["ARE_DB"] || "sqlite3"
|
2010-02-26 04:53:30 +01:00
|
|
|
|
2010-04-09 02:57:10 +02:00
|
|
|
# load the library
|
|
|
|
require "ar-extensions/import/#{adapter}"
|
|
|
|
|
2010-03-12 05:52:16 +01:00
|
|
|
ActiveRecord::Base.logger = Logger.new("log/test.log")
|
2010-03-14 02:20:55 +01:00
|
|
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
2010-02-26 04:53:30 +01:00
|
|
|
ActiveRecord::Base.configurations["test"] = YAML.load(this_dir.join("database.yml").open)[adapter]
|
|
|
|
ActiveRecord::Base.establish_connection "test"
|
|
|
|
|
2010-03-14 02:20:55 +01:00
|
|
|
ActiveSupport::Notifications.subscribe(/active_record.sql/) do |event, _, _, _, hsh|
|
|
|
|
ActiveRecord::Base.logger.info hsh[:sql]
|
|
|
|
end
|
|
|
|
|
2010-03-12 05:52:16 +01:00
|
|
|
require "factory_girl"
|
|
|
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each{ |file| require file }
|
|
|
|
|
2010-02-26 04:53:30 +01:00
|
|
|
# Load base/generic schema
|
|
|
|
require this_dir.join("schema/version")
|
|
|
|
require this_dir.join("schema/generic_schema")
|
2010-03-14 02:20:55 +01:00
|
|
|
adapter_schema = this_dir.join("schema/#{adapter}_schema.rb")
|
2010-02-26 04:53:30 +01:00
|
|
|
require adapter_schema if File.exists?(adapter_schema)
|
|
|
|
|
2010-03-12 05:52:16 +01:00
|
|
|
Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }
|