public
Created

  • Download Gist
spec_helper.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.