Skip to content

Instantly share code, notes, and snippets.

@woods
Created May 24, 2013 10:21
Show Gist options
  • Save woods/5642596 to your computer and use it in GitHub Desktop.
Save woods/5642596 to your computer and use it in GitHub Desktop.
Load just the models and lib of a Rails project. This can be useful for model/component/service specs that depend on ActiveRecord, but no other part of Rails. Running the tests in this fashion helps to make sure you don't introduce any other Rails dependencies into your code, and it helps those tests to load a few seconds faster since we're not …
require 'bundler/setup'
require 'active_support'
require 'active_support/dependencies'
ActiveSupport::Dependencies.autoload_paths += %w{ app/models lib }
require 'active_record'
db_config = YAML.load_file('config/database.yml')
ActiveRecord::Base.establish_connection(db_config['test'])
require 'carrierwave'
require 'carrierwave/orm/activerecord'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment