0
+ # Yields a block with STDOUT and STDERR silenced. If you *really* want
0
+ # to output something, the block is yielded with the original output
0
+ # puts 'hello!' # no output produced
0
+ # o.puts 'hello!' # output on STDOUT
0
+ # (based on silence_stream in ActiveSupport.)
0
+ yield(STDOUT, STDERR) if ENV['VERBOSE']
0
+ streams = [STDOUT, STDERR]
0
+ actual_stdout = STDOUT.dup
0
+ actual_stderr = STDERR.dup
0
+ s.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
0
+ yield actual_stdout, actual_stderr
0
+ STDOUT.reopen(actual_stdout)
0
+ STDERR.reopen(actual_stderr)
0
File.join(File.dirname(__FILE__), 'test_app')
0
+ system(cmd) || raise("failed running '#{cmd}'")
0
+ desc 'Remove the test application'
0
FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
0
+ desc 'Build the test rails application (use RAILS=[edge,<directory>] to test against specific version)'
0
- # vendor_dir = File.join(test_app_dir, 'vendor')
0
- # FileUtils.mkdir_p vendor_dir
0
- # system "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
0
- # system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
- # system "rails #{test_app_dir}"
0
- # offline fix for getting rails
0
- vendor_dir = File.join(test_app_dir, 'vendor')
0
- FileUtils.mkdir_p vendor_dir
0
- system "cd #{vendor_dir} && ln -s /Users/james/Code/rails/git/rails rails"
0
- system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
- # get the database config and schema in place
0
- File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
- "development" => {"adapter" => "sqlite3", "database" => "engines_development.sqlite3"},
0
- "test" => {"adapter" => "sqlite3", "database" => "engines_test.sqlite3"}
0
+ out.puts "> Creating test application at #{test_app_dir}"
0
+ vendor_dir = File.join(test_app_dir, 'vendor')
0
+ FileUtils.mkdir_p vendor_dir
0
+ if ENV['RAILS'] == 'edge'
0
+ out.puts ">>> Cloning rails from GitHub"
0
+ run "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
0
+ elsif File.exist?(ENV['RAILS'])
0
+ out.puts ">>> Linking rails from #{ENV['RAILS']}"
0
+ run "cd #{vendor_dir} && ln -s #{ENV['RAILS']} rails"
0
+ raise "Couldn't build test application from '#{ENV['RAILS']}'"
0
+ out.puts ">>> generating rails default directory structure"
0
+ run "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+ version = `rails --version`.chomp.split.last
0
+ out.puts ">>> building rails using the 'rails' command (rails version: #{version})"
0
+ run "rails #{test_app_dir}"
0
+ # get the database config and schema in place
0
+ out.puts ">>> writing database.yml"
0
+ File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
+ "development" => {"adapter" => "sqlite3", "database" => "engines_development.sqlite3"},
0
+ "test" => {"adapter" => "sqlite3", "database" => "engines_test.sqlite3"}
0
+ out.puts ">>> copying schema.rb"
0
+ FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
+ File.join(test_app_dir, 'db'))
0
- FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
- File.join(test_app_dir, 'db'))
0
# We can't link the plugin, as it needs to be present for script/generate to find
0
@@ -74,6 +121,7 @@ namespace :test do
0
# TODO: find and +1/create issue for loading generators from symlinked plugins
0
desc 'Mirror the engines plugin into the test application'
0
task :copy_engines_plugin do
0
+ puts "> Copying engines plugin into test application"
0
engines_plugin = File.join(test_app_dir, "vendor", "plugins", "engines")
0
FileUtils.rm_r(engines_plugin) if File.exist?(engines_plugin)
0
FileUtils.mkdir_p(engines_plugin)
0
@@ -82,33 +130,6 @@ namespace :test do
0
- # desc 'Ensure helper methods used by the engines plugin test suite are available'
0
- # task :append_engines_test_helper do
0
- # engines_test_helper_line = "require 'engines_test_helper'"
0
- # test_helper_rb = File.join(test_app_dir, "test", "test_helper.rb")
0
- # test_helper_lines = File.readlines(test_helper_rb)
0
- # return if test_helper_lines.include?(engines_test_helper_line)
0
- # test_helper_lines << engines_test_helper_line
0
- # File.open(test_helper_rb, 'w') { |f| f.write test_helper_lines }
0
- # desc 'Add the engines bootstrap line to the environment.rb file if it is missing'
0
- # task :insert_engines_boot_loader_line do
0
- # engines_boot_line = "require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')"
0
- # environment_rb_file = File.join(test_app_dir, 'config', 'environment.rb')
0
- # environment_rb_lines = File.readlines(environment_rb_file)
0
- # return if environment_rb_lines.include?(engines_boot_line)
0
- # first_initializer_line = environment_rb_lines.find { |line| line =~ /\ARails::Initializer/ }
0
- # index = environment_rb_lines.index(first_initializer_line)
0
- # environment_rb_lines.insert(index, engines_boot_line + "\n\n")
0
- # File.open(environment_rb_file, 'w') { |f| f.write environment_rb_lines }
0
def insert_line(line, options)
0
target_file = File.join(test_app_dir, options[:into])
0
@@ -138,7 +159,7 @@ namespace :test do
0
desc 'Update the plugin and tests files in the test application from the plugin'
0
task :mirror_engine_files => [:copy_engines_plugin] do
0
+
puts "> Modifying default config files to load engines plugin"0
insert_line("require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')",
0
:into => 'config/environment.rb',
0
:after => "require File.join(File.dirname(__FILE__), 'boot')")
0
@@ -148,6 +169,7 @@ namespace :test do
0
insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')
0
+ puts "> mirroring test application files into #{test_app_dir}"
0
mirror_test_files('app')
0
mirror_test_files('lib')
0
mirror_test_files('plugins', 'vendor')
Comments
No one has commented yet.