aboutsummaryrefslogtreecommitdiffstats
path: root/spec/spec_helper.rb
blob: 9d4bffec55289f0b632cd74ada67d04ad1893695 (plain) (blame)
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
require 'rubygems'

def load_all(*patterns)
  patterns.each { |pattern| Dir[pattern].sort.each { |path| load File.expand_path(path) } }
end

def setup_environment  
  # Configure Rails Environment
  ENV["RAILS_ENV"] = 'test'
  require File.expand_path("../dummy/config/environment.rb",  __FILE__)
    
  require 'rspec/rails'
  require 'capybara/rspec'
  require 'factory_girl_rails'
  
  Rails.backtrace_cleaner.remove_silencers!

  RSpec.configure do |config|
    config.mock_with :rspec
  end
end

def each_run  
  FactoryGirl.reload
  ActiveSupport::Dependencies.clear

  load_all 'spec/support/**/*.rb'
  load_all 'spec/factories/**/*.rb' if FactoryGirl.factories.none?
end

# If spork is available in the Gemfile it'll be used but we don't force it.
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
  Spork.prefork { setup_environment }
  Spork.each_run { each_run }
else
  setup_environment
  each_run
end