2011-08-14 19:16:59 +00:00
|
|
|
# Note: if segmentation fault with spork / imagemagick on mac os x, take a look at:
|
|
|
|
# http://stackoverflow.com/questions/2838307/why-is-this-rmagick-call-generating-a-segmentation-fault
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'spork'
|
|
|
|
|
2011-08-13 23:24:02 +00:00
|
|
|
# figure out where we are being loaded from
|
|
|
|
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
|
|
|
|
begin
|
|
|
|
raise "foo"
|
|
|
|
rescue => e
|
|
|
|
puts <<-MSG
|
|
|
|
===================================================
|
|
|
|
It looks like spec_helper.rb has been loaded
|
|
|
|
multiple times. Normalize the require to:
|
|
|
|
|
|
|
|
require "spec/spec_helper"
|
|
|
|
|
|
|
|
Things like File.join and File.expand_path will
|
|
|
|
cause it to be loaded multiple times.
|
|
|
|
|
|
|
|
Loaded this time from:
|
|
|
|
|
|
|
|
#{e.backtrace.join("\n ")}
|
|
|
|
===================================================
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-28 13:38:13 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
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.
|
2011-07-26 00:00:35 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
|
|
ENV["RAILS_ENV"] ||= 'test'
|
2011-08-16 18:58:23 +00:00
|
|
|
|
|
|
|
# Avoid preloading models
|
|
|
|
require 'rails/mongoid'
|
|
|
|
Spork.trap_class_method(Rails::Mongoid, :load_models)
|
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
require File.expand_path('../../config/environment', __FILE__)
|
2010-04-09 09:23:41 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
require 'rspec/rails'
|
2010-04-09 09:23:41 +00:00
|
|
|
|
2011-08-16 18:58:23 +00:00
|
|
|
require 'factory_girl'
|
|
|
|
Spork.trap_class_method(FactoryGirl, :find_definitions)
|
2011-04-03 23:59:41 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
# 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 }
|
2011-04-28 21:47:01 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
Locomotive.configure_for_test
|
2011-04-28 21:47:01 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
RSpec.configure do |config|
|
2010-12-19 20:27:32 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
config.include(Locomotive::RSpec::Matchers)
|
2010-12-19 20:27:32 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
config.mock_with :mocha
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
config.before(:each) do
|
|
|
|
Locomotive.config.heroku = false
|
|
|
|
end
|
2010-07-30 21:04:18 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
require 'database_cleaner'
|
|
|
|
config.before(:suite) do
|
|
|
|
DatabaseCleaner.strategy = :truncation
|
|
|
|
DatabaseCleaner.orm = 'mongoid'
|
|
|
|
end
|
2010-12-14 17:00:12 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
config.before(:each) do
|
|
|
|
if self.described_class != Locomotive::Import::Job
|
|
|
|
DatabaseCleaner.clean
|
|
|
|
end
|
2010-10-28 23:36:45 +00:00
|
|
|
end
|
2011-08-13 23:24:02 +00:00
|
|
|
|
2011-08-14 19:16:59 +00:00
|
|
|
config.before(:all) do
|
|
|
|
if self.described_class == Locomotive::Import::Job
|
|
|
|
DatabaseCleaner.clean
|
|
|
|
end
|
2011-08-13 23:24:02 +00:00
|
|
|
end
|
|
|
|
end
|
2011-08-14 19:16:59 +00:00
|
|
|
|
2010-04-09 09:23:41 +00:00
|
|
|
end
|
2011-08-14 19:16:59 +00:00
|
|
|
|
|
|
|
Spork.each_run do
|
|
|
|
# This code will be run each time you run your specs.
|
|
|
|
Locomotive.configure_for_test(true)
|
|
|
|
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
|
|
|
|
|
|
|
# loading ruby file directly breaks the tests
|
|
|
|
# Dir[Rails.root.join('app/models/*.rb')].each { |f| load f }
|
|
|
|
end
|