Created
November 4, 2011 19:10
-
-
Save daveworth/1340206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spork' | |
Spork.prefork do | |
# Loading more in this block will cause your tests to run faster. However, | |
# if you change any configuration or code from libraries loaded here, you'll | |
# need to restart spork for it take effect. | |
# This file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV["RAILS_ENV"] ||= 'test' | |
# Dont have devise load the User model when loading routes | |
require 'rails/application' | |
Spork.trap_method(Rails::Application, :reload_routes!) | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
`rake fuzzymatch:load_functions RAILS_ENV=test` | |
# Requires supporting ruby files with custom matchers and macros, etc, | |
# in spec/support/ and its subdirectories. | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
$original_sunspot_session = Sunspot.session | |
Sunspot::Rails::Tester.start_original_sunspot_session | |
if Spork.using_spork? | |
# reload classes for spork | |
ActiveSupport::Dependencies.clear | |
# re-instantiate observers | |
ActiveRecord::Base.instantiate_observers | |
end | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
config.fixture_path = "#{::Rails.root}/spec/fixtures" | |
config.use_transactional_fixtures = false | |
config.include Devise::TestHelpers, :type => :controller | |
config.extend ControllerMacros, :type => :controller | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :truncation #:transaction | |
DatabaseCleaner.clean_with(:truncation) | |
Sunspot.session = Sunspot::Rails::StubSessionProxy.new( $original_sunspot_session ) | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
config.before(:each, :solr => true) do | |
Sunspot.session = $original_sunspot_session | |
Sunspot.remove_all! | |
end | |
end | |
end | |
Spork.each_run do | |
# This code will be run each time you run your specs. | |
# reload classes for spork | |
ActiveSupport::Dependencies.clear | |
# re-instantiate observers | |
ActiveRecord::Base.instantiate_observers | |
# Reload FactoryGirl factories on each run | |
Factory.factories.clear | |
Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| load f } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment