Fetching contributors…
Cannot retrieve contributors at this time
55 lines (47 sloc) 2.89 KB
desc "Set up a rails app for testing in the spec dir"
task :default => [:"testbed:generate", :"testbed:setup", :"testbed:migrate"]
namespace "testbed" do
# "testbed" is also hardcoded in the spec/spec_helper.rb features/support/env.rb and gitignore file. Change it there too...
"Generate rails, rspec, cucumber"
task :generate do
chdir("testbed") do
sh "bundle install"
sh "bundle exec rails ."
sh "bundle exec script/generate rspec"
sh "bundle exec script/generate cucumber --webrat"
sh "rm -rf spec features"
desc "Setup bundler, rspec, cucumber"
task :setup do
chdir("testbed") do
# Bundler
preinitializer_rb = "begin\n require \"rubygems\"\n require \"bundler\"\nrescue LoadError\n raise \"Could not load the bundler gem. Install it with `gem install bundler`.\"\nend\n\nif <=\"0.9.24\")\n raise RuntimeError, \"Your bundler version is too old for Rails 2.3.\" +\n \"Run `gem install bundler` to upgrade.\"\nend\n\nbegin\n # Set up load paths for all bundled gems\n ENV[\"BUNDLE_GEMFILE\"] = File.expand_path(\"../../Gemfile\", __FILE__)\n Bundler.setup\nrescue Bundler::GemNotFound\n raise RuntimeError, \"Bundler couldn't find some gems.\" +\n \"Did you run `bundle install`?\"\nend\n"'config/preinitializer.rb', 'w'){|f| f.write preinitializer_rb}
boot_rb ='config/boot.rb').sub("# All that for this:", "class Rails::Boot\n def run\n load_initializer\n\n Rails::Initializer.class_eval do\n def load_gems\n @bundler_loaded ||= Bundler.require :default, Rails.env\n end\n end\n\n\n end\nend\n\n# All that for this:")'config/boot.rb', 'w'){|f| f.write boot_rb}
puts "NOTE: These files were created/modified as described here:"
# Rspec
rspec_rake ='lib/tasks/rspec.rake').gsub('#{RAILS_ROOT}/spec/', '#{RAILS_ROOT}/../spec/').gsub("FileList['spec/", "FileList['../spec/").gsub("File.exist?('spec/","File.exist?('../spec/")'lib/tasks/rspec.rake', 'w'){|f| f.write rspec_rake}
# Cucumber
cucumber_rake ='lib/tasks/cucumber.rake').sub("begin", "ENV['FEATURE'] ||= '../features'\n\nbegin")'lib/tasks/cucumber.rake', 'w'){|f| f.write cucumber_rake}
desc "Generate, migrate testbed"
task :migrate do
sh "cp -R generators testbed/lib"
chdir("testbed") do
sh "bundle exec script/generate surveyor"
sh "bundle exec rake db:migrate db:test:prepare"
desc "Remove testbed app"
task :remove do
puts "Removing the test_app in the spec folder"
chdir("testbed") do
sh 'rm -rf Gemfile.lock README Rakefile app config db doc features lib log public script spec surveys test tmp vendor'