$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'active_record' # database ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}} ActiveRecord::Base.establish_connection('test') # models class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post end #migrations class CreateAllTables < ActiveRecord::Migration def self.up create_table(:posts) {|t| t.string :title} create_table(:comments) {|t| t.text :body; t.references :post} end end RSpec.configure do |config| config.before :all do CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'posts' end end