From 754cddb141715eb152049451fff3e1dff1ac146a Mon Sep 17 00:00:00 2001 From: Jamie Winsor Date: Mon, 10 Oct 2011 19:39:51 -0700 Subject: Load refinerycms factories properly Expose blog factories to other gems --- lib/refinerycms-blog.rb | 4 ++++ spec/spec_helper.rb | 36 ++++++++++++------------------------ spec/support/refinery.rb | 2 ++ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/refinerycms-blog.rb b/lib/refinerycms-blog.rb index fafedf5..135b3e1 100644 --- a/lib/refinerycms-blog.rb +++ b/lib/refinerycms-blog.rb @@ -19,6 +19,10 @@ module Refinery def version ::Refinery::Blog::Version.to_s end + + def factory_paths + @factory_paths ||= [ File.expand_path("../../spec/factories", __FILE__) ] + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b8df592..ea550e2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +1,17 @@ require 'rubygems' -def setup_environment - # 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. - +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! @@ -20,30 +21,17 @@ def setup_environment end def each_run - require 'factory_girl_rails' - require 'refinerycms-testing' + FactoryGirl.reload + ActiveSupport::Dependencies.clear - Dir[File.expand_path("../../app/models/**/*.rb", __FILE__)].each do |model| - load model - end - - Dir[ - File.expand_path("../support/**/*.rb", __FILE__), - File.expand_path("../factories/**/*.rb", __FILE__) - ].each {|f| require f} + load_all 'spec/support/**/*.rb' + load_all 'spec/factories/**/*.rb' 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 do - setup_environment - - ActiveSupport::Dependencies.clear - end - - Spork.each_run do - each_run - end + Spork.prefork { setup_environment } + Spork.each_run { each_run } else setup_environment each_run diff --git a/spec/support/refinery.rb b/spec/support/refinery.rb index d761787..575ac2b 100644 --- a/spec/support/refinery.rb +++ b/spec/support/refinery.rb @@ -1,5 +1,7 @@ require 'refinerycms-testing' +Refinery::Testing.load_factories + RSpec.configure do |config| config.extend Refinery::Testing::ControllerMacros::Authentication, :type => :controller config.extend Refinery::Testing::RequestMacros::Authentication, :type => :request -- cgit v1.2.3