Skip to content
Browse files

AP tests: detect missing dependencies and automatically run bundler

  • Loading branch information...
1 parent 6d214c9 commit 076d7f885ed808a061c1d161f00fc81465b3b4da @josh josh committed Sep 13, 2009
Showing with 34 additions and 4 deletions.
  1. +2 −2 actionpack/test/abstract_unit.rb
  2. +2 −2 actionpack/test/abstract_unit2.rb
  3. +30 −0 actionpack/test/bundler_helper.rb
View
4 actionpack/test/abstract_unit.rb
@@ -6,8 +6,8 @@
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
-bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment')
-require bundler if File.exist?("#{bundler}.rb")
+require 'bundler_helper'
+ensure_requirable %w( rack rack/test sqlite3 builder memcache tzinfo )
ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
View
4 actionpack/test/abstract_unit2.rb
@@ -5,8 +5,8 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__) + '/lib')
-bundler = File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'gems', 'environment')
-require bundler if File.exist?("#{bundler}.rb")
+require 'bundler_helper'
+ensure_requirable %w( rack rack/test )
require 'test/unit'
require 'active_support'
View
30 actionpack/test/bundler_helper.rb
@@ -0,0 +1,30 @@
+BUNDLER_ENV_FILE = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment')
+
+def load_bundled_gems
+ load_bundled_gems! if File.exist?("#{BUNDLER_ENV_FILE}.rb")
+end
+
+def load_bundled_gems!
+ puts "Checking if the bundled testing requirements are up to date..."
+
+ result = system "gem bundle"
+ unless result
+ puts "The gem bundler is not installed. Installing."
+ system "gem install bundler"
+ system "gem bundle"
+ end
+
+ require BUNDLER_ENV_FILE
+end
+
+def ensure_requirable(libs)
+ load_bundled_gems
+
+ begin
+ libs.each { |lib| require lib }
+ rescue LoadError => e
+ puts "Missing required libs to run test"
+ puts e.message
+ load_bundled_gems!
+ end
+end

0 comments on commit 076d7f8

Please sign in to comment.
Something went wrong with that request. Please try again.