Permalink
Browse files

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
  • Loading branch information...
1 parent da8d0d3 commit 98c7231e5781a027f44bdfdf7523e575c922c37d @gregbell gregbell committed Jan 9, 2012
Showing with 41 additions and 24 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 Gemfile
  3. +14 −7 script/use_rails
  4. +10 −3 spec/support/detect_rails_version.rb
  5. +15 −13 tasks/test.rake
View
@@ -33,3 +33,4 @@ test-rails*
public
.rvmrc
.rspec
+.rails-version
View
@@ -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
View
@@ -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")
@@ -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
View
@@ -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'

0 comments on commit 98c7231

Please sign in to comment.