Permalink
Browse files

Better handling of gemfile scenarios

  • Loading branch information...
dchelimsky committed Apr 17, 2011
1 parent 3c53e96 commit 08f5d4e0971a0d499f61a785ab781d005d7800dc
Showing with 78 additions and 9 deletions.
  1. +1 −0 .gitignore
  2. +43 −0 README_DEV.md
  3. +31 −7 Rakefile
  4. +1 −0 Thorfile
  5. +2 −2 templates/run_specs.rb
View
@@ -11,3 +11,4 @@ gemfiles/bin/*
bin
.rvmrc
*.rbc
+.gemfile
View
@@ -0,0 +1,43 @@
+# Information for rspec-rails developers
+
+rspec-rails lives in a complicated ecosystem. We need to run it against
+multiple versions of rails and multiple versions of Ruby as well. There are
+several tools already available to manage running against multiple versions of
+Ruby (e.g. rvm), and there are even some multi-rails tools (e.g. multi-rails)
+but we haven't found one that does exactly what we need here, so we've rolled
+our own.
+
+## The short version
+
+thor rails:use 3.0.6
+rake
+
+## The long version
+
+### thor rails:use
+
+The `thor rails:use` task accepts any released version of rails, or either the
+3-0-stable or master branches.
+
+ thor rails:use master
+ thor rails:use 3-0-stable
+ thor rails:use 3.0.6
+ thor rails:use 3.0.5
+ thor rails:use 3.0.4
+ thor rails:use 3.0.3
+ thor rails:use 3.0.2
+ thor rails:use 3.0.1
+ thor rails:use 3.0.0
+
+It then does several things:
+
+* generates a .gemfile file with the version listed. This is used internally by
+ assorted rake tasks.
+* installs the bundle using the appropriate file in the gemfiles directory
+** this includes binstubs, which are stored in ./gemfiles/bin
+* symlinks the gemfiles/bin directory to ./bin (in the project root) to support
+ running bin/rspec from the project root
+
+At any time, if you want to change rails versions, run `thor rails:use` with a
+new version number. To play it safe, you probably want to also run `rake
+clobber` to delete all the code generated by the previous rails version.
View
@@ -1,14 +1,34 @@
-unless ENV["BUNDLE_GEMFILE"]
+unless File.exist?("./.gemfile")
warn <<-MESSAGE
-You must set the BUNDLE_GEMFILE environment variable to point to any of the
-files in the gemfiles directory (other than base) using the absolute path to
-the file e.g. (in bash):
+=============================================================================
+You must set the version of rails you want to run against. The simplest way
+to accomplish this is to install thor (if you don't already have it) and run:
+
+ thor rails:use 3.0.6
+
+You can use any of the following versions/branches:
+
+ 3.0.0 .. 3.0.6
+ master
+ 3-0-stable
+
+See the README_DEV.md file for more information.
+=============================================================================
- export BUNDLE_GEMFILE=#{File.expand_path("../gemfiles/rails-3.0.6", __FILE__)}
- bundle install
MESSAGE
exit 1
end
+
+require 'pathname'
+ENV["BUNDLE_GEMFILE"] ||= begin
+ version = if File.exist?("./.gemfile")
+ File.read("./.gemfile").chomp
+ else
+ "rails-3.0.6"
+ end
+ File.expand_path("../gemfiles/#{version}", __FILE__)
+ end
+puts "Using gemfile: #{ENV["BUNDLE_GEMFILE"].gsub(Pathname.new(__FILE__).dirname.to_s,'').sub(/^\//,'')}"
require "bundler"
Bundler.setup
Bundler::GemHelper.install_tasks
@@ -55,7 +75,11 @@ namespace :generate do
desc "generate a fresh app with rspec installed"
task :app do |t|
unless File.directory?('./tmp/example_app')
- sh "bundle exec rails new ./tmp/example_app"
+ sh "bin/rails new ./tmp/example_app"
+ bindir = File.expand_path("gemfiles/bin")
+ Dir.chdir("./tmp/example_app") do
+ sh "ln -s #{bindir}"
+ end
end
end
View
@@ -5,5 +5,6 @@ class Rails < Thor
say `bundle install #{gemfile} --binstubs`
say `bundle #{gemfile} update rails` unless version =~ /^\d\.\d\.\d$/
say `ln -s gemfiles/bin` unless File.exist?('bin')
+ `echo rails-#{version} > ./.gemfile`
end
end
View
@@ -1,9 +1,9 @@
-run('bundle exec rspec spec -cfdoc')
+run('rspec spec -cfdoc')
run('rake spec')
run('rake spec:requests')
run('rake spec:models')
run('rake spec:views')
run('rake spec:controllers')
run('rake spec:helpers')
run('rake spec:mailers')
-run('rake stats')
+run("rake stats")

0 comments on commit 08f5d4e

Please sign in to comment.