Skip to content

Instantly share code, notes, and snippets.

@shicholas
Created October 21, 2013 17:47
Show Gist options
  • Save shicholas/7087946 to your computer and use it in GitHub Desktop.
Save shicholas/7087946 to your computer and use it in GitHub Desktop.
cut up spec_helper to get the tests running even faster!
require_relative "spec_helper_model"
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require_relative "spec_helper_unit"
ENV["RAILS_ENV"] ||= "test"
# ActiveRecord
require "yaml"
require "active_record"
ActiveRecord::Base.establish_connection(
YAML.load(File.read(RAILS_ROOT + "config/database.yml"))["test"]
)
require 'factory_girl'
FactoryGirl.find_definitions
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
require "database_cleaner"
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
# Enter database configurations into ActiveRecord
ActiveRecord::Base.send(:configurations=, YAML::load(ERB.new(IO.read(RAILS_ROOT + "config/database.yml")).result))
require "pathname"
RAILS_ROOT = Pathname.new(File.expand_path("../..", __FILE__))
# ActiveSupport
require "active_support"
require "active_support/dependencies"
%w{ api helpers mailers models }.each do |dir|
ActiveSupport::Dependencies.autoload_paths <<
File.expand_path(RAILS_ROOT + "app/#{dir}", __FILE__)
end
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.order = 'random'
end
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[RAILS_ROOT + "spec/support/**/*.rb"].each {|f| require f}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment