diff options
author | Jamie Winsor <jamie@enmasse.com> | 2011-10-10 19:39:51 -0700 |
---|---|---|
committer | Jamie Winsor <jamie@enmasse.com> | 2011-10-10 19:39:51 -0700 |
commit | 754cddb141715eb152049451fff3e1dff1ac146a (patch) | |
tree | cc05bb775e3c926545872b9c8a2da85f7f2b0ded | |
parent | 85419ce88e56b9971ffe8dd6aa98c146a787f513 (diff) | |
download | refinerycms-blog-754cddb141715eb152049451fff3e1dff1ac146a.tar.gz refinerycms-blog-754cddb141715eb152049451fff3e1dff1ac146a.tar.bz2 refinerycms-blog-754cddb141715eb152049451fff3e1dff1ac146a.zip |
Load refinerycms factories properly
Expose blog factories to other gems
-rw-r--r-- | lib/refinerycms-blog.rb | 4 | ||||
-rw-r--r-- | spec/spec_helper.rb | 36 | ||||
-rw-r--r-- | 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 |