Skip to content

Commit 98c7231

Browse files
committed
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
1 parent da8d0d3 commit 98c7231

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ test-rails*
3333
public
3434
.rvmrc
3535
.rspec
36+
.rails-version

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gemspec
44

55
require File.expand_path('../spec/support/detect_rails_version', __FILE__)
66

7-
rails_version = ENV['RAILS'] || detect_rails_version || "3.1.0"
7+
rails_version = detect_rails_version || "3.1.0"
88
gem 'rails', rails_version
99

1010
case rails_version

script/use_rails

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Switches the development environment to use the given
44
# version of rails. Caches the Gemfile.locks so that
55
# switching it very fast.
6+
#
7+
require File.expand_path("../../spec/support/detect_rails_version", __FILE__)
68

79
def cmd(command)
810
puts command
@@ -34,13 +36,18 @@ if File.exists?(gem_lock_file) && ARGV.include?('--clobber')
3436
cmd "rm #{gem_lock_file}"
3537
end
3638

37-
unless File.exists?(gem_lock_file)
38-
# Generate it
39+
write_rails_version(version)
40+
41+
# Ensure that bundler installs
42+
ENV['RUBYOPT'] = ''
43+
44+
if File.exists?(gem_lock_file)
45+
cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock")
46+
cmd("ln -s #{gem_lock_file} Gemfile.lock")
47+
cmd("bundle")
48+
else
3949
cmd "rm Gemfile.lock" if file_or_symlink?("Gemfile.lock")
40-
cmd "export RAILS=#{version} && bundle install"
50+
cmd "bundle install"
4151
cmd "mv Gemfile.lock #{gem_lock_file}"
52+
cmd("ln -s #{gem_lock_file} Gemfile.lock")
4253
end
43-
44-
cmd("rm Gemfile.lock") if file_or_symlink?("Gemfile.lock")
45-
cmd("ln -s #{gem_lock_file} Gemfile.lock")
46-
cmd("bundle")

spec/support/detect_rails_version.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
#
33
# You can pass it in as an ENV variable or it will use
44
# the current Gemfile.lock to find it
5+
6+
unless defined?(RAILS_VERSION_FILE)
7+
RAILS_VERSION_FILE = File.expand_path("../../../.rails-version", __FILE__)
8+
end
9+
510
def detect_rails_version
6-
return nil unless (File.exists?("Gemfile.lock") || File.symlink?("Gemfile.lock"))
11+
return nil unless File.exists?(RAILS_VERSION_FILE)
12+
File.read(RAILS_VERSION_FILE).chomp
13+
end
714

8-
File.read("Gemfile.lock").match(/^\W*rails \(([a-z\d.]*)\)/)
9-
return $1
15+
def write_rails_version(version)
16+
File.open(RAILS_VERSION_FILE, "w+"){|f| f << version }
1017
end

tasks/test.rake

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@ task :test => ['spec:unit', 'spec:integration', 'cucumber', 'cucumber:class_relo
1111

1212
namespace :test do
1313

14-
desc "Run the full suite against the important versions of rails"
15-
task :major_supported_rails do
14+
def run_tests_against(*versions)
1615
current_version = detect_rails_version if File.exists?("Gemfile.lock")
1716

18-
["3.0.10", "3.1.0"].each do |version|
17+
versions.each do |version|
1918
puts
2019
puts "== Using Rails #{version}"
2120

22-
if File.exists?("Gemfile.lock")
23-
puts "Removing the current Gemfile.lock"
24-
cmd "rm Gemfile.lock"
25-
end
26-
27-
cmd "export RAILS=#{version} && ./script/use_rails #{version}"
28-
cmd "export RAILS=#{version} && bundle exec rspec spec/unit"
29-
cmd "export RAILS=#{version} && bundle exec rspec spec/integration"
30-
cmd "export RAILS=#{version} && bundle exec cucumber features"
31-
cmd "export RAILS=#{version} && bundle exec cucumber -p class-reloading features"
21+
cmd "./script/use_rails #{version}"
22+
cmd "bundle exec rspec spec"
23+
cmd "bundle exec cucumber features"
24+
cmd "bundle exec cucumber -p class-reloading features"
3225
end
26+
3327
cmd "./script/use_rails #{current_version}" if current_version
3428
end
3529

30+
desc "Run the full suite against the important versions of rails"
31+
task :major_supported_rails do
32+
run_tests_against "3.0.10", "3.1.0"
33+
end
34+
35+
desc "Alias for major_supported_rails"
36+
task :all => :major_supported_rails
37+
3638
end
3739

3840
require 'rspec/core/rake_task'

0 commit comments

Comments
 (0)