From 98c7231e5781a027f44bdfdf7523e575c922c37d Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Mon, 9 Jan 2012 08:56:24 -0800 Subject: [PATCH] rake tests:major_supported_rails now runs on a fresh gemset Before this commit, the user had to have each of the versions of rails installed before the rake task would successfully run. It was due to environment variables being set by bundler. Also, I removed the RAILS environment variable in favour of a .rails-version file --- .gitignore | 1 + Gemfile | 2 +- script/use_rails | 21 ++++++++++++++------- spec/support/detect_rails_version.rb | 13 ++++++++++--- tasks/test.rake | 28 +++++++++++++++------------- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index eee7ffa0c8a..31484896f87 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ test-rails* public .rvmrc .rspec +.rails-version diff --git a/Gemfile b/Gemfile index a1cb10037ee..a71c887fb57 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ gemspec require File.expand_path('../spec/support/detect_rails_version', __FILE__) -rails_version = ENV['RAILS'] || detect_rails_version || "3.1.0" +rails_version = detect_rails_version || "3.1.0" gem 'rails', rails_version case rails_version diff --git a/script/use_rails b/script/use_rails index 560f12c6052..0981b37591a 100755 --- a/script/use_rails +++ b/script/use_rails @@ -3,6 +3,8 @@ # Switches the development environment to use the given # version of rails. Caches the Gemfile.locks so that # switching it very fast. +# +require File.expand_path("../../spec/support/detect_rails_version", __FILE__) def cmd(command) puts command @@ -34,13 +36,18 @@ if File.exists?(gem_lock_file) && ARGV.include?('--clobber') cmd "rm #{gem_lock_file}" end -unless File.exists?(gem_lock_file) - # Generate it +write_rails_version(version) + +# Ensure that bundler installs +ENV['RUBYOPT'] = '' + +if File.exists?(gem_lock_file) + cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock") + cmd("ln -s #{gem_lock_file} Gemfile.lock") + cmd("bundle") +else cmd "rm Gemfile.lock" if file_or_symlink?("Gemfile.lock") - cmd "export RAILS=#{version} && bundle install" + cmd "bundle install" cmd "mv Gemfile.lock #{gem_lock_file}" + cmd("ln -s #{gem_lock_file} Gemfile.lock") end - -cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock") -cmd("ln -s #{gem_lock_file} Gemfile.lock") -cmd("bundle") diff --git a/spec/support/detect_rails_version.rb b/spec/support/detect_rails_version.rb index 4624d0b6e9e..89070811e8b 100644 --- a/spec/support/detect_rails_version.rb +++ b/spec/support/detect_rails_version.rb @@ -2,9 +2,16 @@ # # You can pass it in as an ENV variable or it will use # the current Gemfile.lock to find it + +unless defined?(RAILS_VERSION_FILE) + RAILS_VERSION_FILE = File.expand_path("../../../.rails-version", __FILE__) +end + def detect_rails_version - return nil unless (File.exists?("Gemfile.lock") || File.symlink?("Gemfile.lock")) + return nil unless File.exists?(RAILS_VERSION_FILE) + File.read(RAILS_VERSION_FILE).chomp +end - File.read("Gemfile.lock").match(/^\W*rails \(([a-z\d.]*)\)/) - return $1 +def write_rails_version(version) + File.open(RAILS_VERSION_FILE, "w+"){|f| f << version } end diff --git a/tasks/test.rake b/tasks/test.rake index 6b34ee82dc3..4d8965ea54f 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -11,28 +11,30 @@ task :test => ['spec:unit', 'spec:integration', 'cucumber', 'cucumber:class_relo namespace :test do - desc "Run the full suite against the important versions of rails" - task :major_supported_rails do + def run_tests_against(*versions) current_version = detect_rails_version if File.exists?("Gemfile.lock") - ["3.0.10", "3.1.0"].each do |version| + versions.each do |version| puts puts "== Using Rails #{version}" - if File.exists?("Gemfile.lock") - puts "Removing the current Gemfile.lock" - cmd "rm Gemfile.lock" - end - - cmd "export RAILS=#{version} && ./script/use_rails #{version}" - cmd "export RAILS=#{version} && bundle exec rspec spec/unit" - cmd "export RAILS=#{version} && bundle exec rspec spec/integration" - cmd "export RAILS=#{version} && bundle exec cucumber features" - cmd "export RAILS=#{version} && bundle exec cucumber -p class-reloading features" + cmd "./script/use_rails #{version}" + cmd "bundle exec rspec spec" + cmd "bundle exec cucumber features" + cmd "bundle exec cucumber -p class-reloading features" end + cmd "./script/use_rails #{current_version}" if current_version end + desc "Run the full suite against the important versions of rails" + task :major_supported_rails do + run_tests_against "3.0.10", "3.1.0" + end + + desc "Alias for major_supported_rails" + task :all => :major_supported_rails + end require 'rspec/core/rake_task'