Permalink
Browse files

Better dependency loading for specs. Try to use Rails app defaults if…

… available (already loaded), otherwise require the gem as last resort.
  • Loading branch information...
1 parent 8f142f0 commit b20210812b37afd9b1b6806ffbbeae4592c18504 @grimen grimen committed with Oct 12, 2009
Showing with 17 additions and 15 deletions.
  1. +17 −15 spec/test_helper.rb
View
32 spec/test_helper.rb
@@ -1,22 +1,24 @@
# coding: utf-8
require 'rubygems'
-# To get the specs to run on Ruby 1.9.x.
-gem 'activesupport', '>= 2.3.3'
-gem 'actionpack', '>= 2.3.3'
-gem 'rspec', '>= 1.2.6'
-gem 'rspec-rails', '>= 1.2.6'
-gem 'rspec_hpricot_matchers', '>= 1.0.0'
-gem 'hpricot', '>= 0.6.1'
+def smart_require(lib_name, gem_name, gem_version = '>= 0.0.0')
+ begin
+ require lib_name if lib_name
+ rescue LoadError
+ if gem_name
+ gem gem_name, gem_version
+ require lib_name if lib_name
+ end
+ end
+end
-require 'spec'
-require 'activesupport'
-require 'actionpack'
-require 'active_support'
-require 'action_controller'
-require 'action_view'
-require 'rexml/document'
-require 'rspec_hpricot_matchers'
+smart_require 'spec', 'spec', '>= 1.2.6'
+smart_require false, 'rspec-rails', '>= 1.2.6'
+smart_require 'hpricot', 'hpricot', '>= 0.6.1'
+smart_require 'rspec_hpricot_matchers', 'rspec_hpricot_matchers', '>= 1.0.0'
+smart_require 'active_support', 'activesupport', '>= 2.3.4'
+smart_require 'action_controller', 'actionpack', '>= 2.3.4'
+smart_require 'action_view', 'actionpack', '>= 2.3.4'
Spec::Runner.configure do |config|
config.include(RspecHpricotMatchers)

0 comments on commit b202108

Please sign in to comment.