Skip to content

Instantly share code, notes, and snippets.

@mudge
Created June 26, 2012 15:49
Show Gist options
  • Save mudge/2996609 to your computer and use it in GitHub Desktop.
Save mudge/2996609 to your computer and use it in GitHub Desktop.
A bare-bones spec helper for testing Active Record classes without the rest of Rails.
require "active_record"
require "database_cleaner"
require "rspec/rails/extensions"
# Note that this *will not load your Rails configuration* which means things like
# mass assignment protection by default, etc. will not be set.
RSpec.configure do |config|
config.before(:suite) do
ActiveRecord::Base.configurations =
YAML.load_file(File.expand_path("../../config/database.yml", __FILE__))
ActiveRecord::Base.establish_connection("test")
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment