Skip to content

Commit

Permalink
rake tests:major_supported_rails now runs on a fresh gemset
Browse files Browse the repository at this point in the history
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
gregbell committed Jan 9, 2012
1 parent da8d0d3 commit 98c7231
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ test-rails*
public
.rvmrc
.rspec
.rails-version
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions script/use_rails
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
13 changes: 10 additions & 3 deletions spec/support/detect_rails_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 15 additions & 13 deletions tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 98c7231

Please sign in to comment.