Skip to content

Instantly share code, notes, and snippets.

@budu
Created June 1, 2012 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save budu/2855631 to your computer and use it in GitHub Desktop.
Save budu/2855631 to your computer and use it in GitHub Desktop.
require 'spork'
require 'database_cleaner'
ENV["RAILS_ENV"] ||= 'test'
def configure_rspec
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.before(:suite) do
# WARNING: If you modify these table during tests, you'll have to
# clean them up yourself!
protected_tables = %w()
DatabaseCleaner.clean_with :truncation, except: protected_tables
end
config.before(:each) do
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after(:each) { DatabaseCleaner.clean }
config.with_options(type: :controller) do |config|
config.include Devise::TestHelpers
config.extend AuthenticationMacrosForController
end
config.extend AcceptanceMacros, type: :acceptance
config.include FactoryGirl::Syntax::Methods
config.include AuthenticationMacrosForRequest
config.include MailerMacros
config.include Warden::Test::Helpers
config.before(:each) { reset_email }
FactoryGirl.reload
end
end
Spork.prefork do
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# TODO: refactor, put somewhere else!
Dir[Rails.root.join("spec/example_groups/**/*.rb")].each do |f|
require f
full_name = f.to_s
.sub("#{Rails.root}/spec/example_groups", '')
.sub(/\.rb$/, '')
group = full_name
.camelize
.constantize
name = full_name.sub('_example_group', '')
RSpec.configure do |config|
config.include group, example_group: { file_path: %r(spec#{name}) }
end
end
module Matchers
Dir[Rails.root.join("spec/matchers/**/*.rb")].each do |f|
require f
matcher = f.to_s
.sub("#{Rails.root}/spec/", '')
.sub(/\.rb$/, '')
.camelize
.constantize
RSpec::Matchers.send(:include, matcher)
end
end
require 'capybara/rspec'
Capybara.javascript_driver = :webkit
end
Spork.each_run do
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
require 'factory_girl_rails'
configure_rspec
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment