]> git.wincent.com - wikitext.git/commitdiff
Bundlerize test Rails apps
authorWincent Colaiuta <win@wincent.com>
Sun, 15 May 2011 09:41:05 +0000 (02:41 -0700)
committerWincent Colaiuta <win@wincent.com>
Sun, 15 May 2011 09:41:05 +0000 (02:41 -0700)
This gets all versions 3.0.1 through 3.0.7 passing, although we still have
problems with "Edge" Rails.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
spec/rails_spec.rb

index a987039ab043876b518a7eec30feb7d1fbac48e1..edeee3dbec5f0c8a9895f6b8d3f5f345216d49f5 100644 (file)
@@ -78,6 +78,7 @@ module RailsSpecs
     end
     run 'ruby', RAILS_BIN_PATH, 'new', app, '--skip-activerecord', '--dev'
     create_gemfile app
+    bundlerize app
   end
 
   def insert text, after, infile
@@ -107,12 +108,24 @@ module RailsSpecs
   def create_gemfile app
     File.open(app + 'Gemfile', 'w') do |f|
       f.write <<-GEMFILE
+        source :rubygems
+        gem 'rake'
         gem 'rails', :path => "#{CLONE_PATH.realpath}"
+        gem 'sqlite3'
         gem 'wikitext', :path => "#{WIKITEXT_GEM_PATH.realpath}"
       GEMFILE
     end
   end
 
+  def bundlerize app
+    clean_bundler_environment
+    Dir.chdir app do
+      run 'bundle', 'install', '--path', '../bundle', '--binstubs'
+    end
+  ensure
+    restore_bundler_environment
+  end
+
   def create_controller app
     File.open(app + 'app' + 'controllers' + 'wiki_controller.rb', 'w') do |f|
       f.write 'class WikiController < ApplicationController; end'
@@ -161,10 +174,25 @@ TEST
     create_test path
   end
 
+  def clean_bundler_environment
+    @bundler_env = {}
+    ENV.each do |k, v|
+      @bundler_env[k] = v
+      ENV.delete(k)
+    end
+  end
+
+  def restore_bundler_environment
+    @bundler_env.each { |k, v| ENV[k] = v }
+  end
+
   def run_integration_test app
+    clean_bundler_environment
     FileUtils.cd app do
-      return run('rake', 'test:integration').stdout
+      return run('bin/rake', 'test:integration').stdout
     end
+  ensure
+    restore_bundler_environment
   end
 end # module RailsSpecs