public
Fork of lazyatom/engines
Description: The Rails Engines plugin
Homepage: http://rails-engines.org
Clone URL: git://github.com/tekkub/engines.git
More tweaks to the test tasks
lazyatom (author)
Sun Apr 20 04:50:57 -0700 2008
commit  e15e849fc068fc4bd3f86ebfffd5fc8e4d2e58fd
tree    0803d8ffc794faeb558490b52a4c53dbce2d42d9
parent  380abeb79d707026bc2a71f2debe9bc9ee9ea10b
...
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
 
 
 
 
 
 
40
41
42
43
 
44
45
46
47
48
49
50
51
52
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
70
71
72
...
74
75
76
 
77
78
79
...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
138
139
140
141
 
142
143
144
...
148
149
150
 
151
152
153
...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
64
65
66
67
68
69
70
71
72
73
74
75
 
 
 
 
 
 
 
 
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
 
117
118
119
...
121
122
123
124
125
126
127
...
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
...
159
160
161
 
162
163
164
165
...
169
170
171
172
173
174
175
0
@@ -33,40 +33,87 @@ end
0
 
0
 namespace :test do
0
   
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
+ # streams, i.e.
0
+ #
0
+ # silence do |o, e|
0
+ # puts 'hello!' # no output produced
0
+ # o.puts 'hello!' # output on STDOUT
0
+ # end
0
+ #
0
+ # (based on silence_stream in ActiveSupport.)
0
+ def silence
0
+ yield(STDOUT, STDERR) if ENV['VERBOSE']
0
+ streams = [STDOUT, STDERR]
0
+ actual_stdout = STDOUT.dup
0
+ actual_stderr = STDERR.dup
0
+ streams.each do |s|
0
+ s.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
0
+ s.sync = true
0
+ end
0
+ yield actual_stdout, actual_stderr
0
+ ensure
0
+ STDOUT.reopen(actual_stdout)
0
+ STDERR.reopen(actual_stderr)
0
+ end
0
+
0
   def test_app_dir
0
     File.join(File.dirname(__FILE__), 'test_app')
0
   end
0
-
0
+
0
+ def run(cmd)
0
+ system(cmd) || raise("failed running '#{cmd}'")
0
+ end
0
+
0
+ desc 'Remove the test application'
0
   task :clean do
0
     FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
0
   end
0
   
0
+ desc 'Build the test rails application (use RAILS=[edge,<directory>] to test against specific version)'
0
   task :generate_app do
0
- # if ENV['edge']
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
- # else
0
- # system "rails #{test_app_dir}"
0
- # end
0
+ silence do |out, err|
0
     
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
-
0
- # get the database config and schema in place
0
- require 'yaml'
0
- File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
- f.write({
0
- "development" => {"adapter" => "sqlite3", "database" => "engines_development.sqlite3"},
0
- "test" => {"adapter" => "sqlite3", "database" => "engines_test.sqlite3"}
0
- }.to_yaml)
0
+ out.puts "> Creating test application at #{test_app_dir}"
0
+
0
+ if ENV['RAILS']
0
+ vendor_dir = File.join(test_app_dir, 'vendor')
0
+ FileUtils.mkdir_p vendor_dir
0
+
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
+ else
0
+ raise "Couldn't build test application from '#{ENV['RAILS']}'"
0
+ end
0
+
0
+ out.puts ">>> generating rails default directory structure"
0
+ run "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+ else
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
+ end
0
+
0
+ # get the database config and schema in place
0
+ out.puts ">>> writing database.yml"
0
+ require 'yaml'
0
+ File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
+ f.write({
0
+ "development" => {"adapter" => "sqlite3", "database" => "engines_development.sqlite3"},
0
+ "test" => {"adapter" => "sqlite3", "database" => "engines_test.sqlite3"}
0
+ }.to_yaml)
0
+ end
0
+
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
+
0
     end
0
- FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
- File.join(test_app_dir, 'db'))
0
   end
0
   
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
     end
0
   end
0
   
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
- #
0
- # test_helper_rb = File.join(test_app_dir, "test", "test_helper.rb")
0
- # test_helper_lines = File.readlines(test_helper_rb)
0
- #
0
- # return if test_helper_lines.include?(engines_test_helper_line)
0
- #
0
- # test_helper_lines << engines_test_helper_line
0
- # File.open(test_helper_rb, 'w') { |f| f.write test_helper_lines }
0
- # end
0
- #
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
- #
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
- #
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
- # end
0
-
0
   def insert_line(line, options)
0
     line = line + "\n"
0
     target_file = File.join(test_app_dir, options[:into])
0
@@ -138,7 +159,7 @@ namespace :test do
0
   
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
-
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
                 
0
     insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')
0
     
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')
...
9
10
11
 
 
 
12
13
14
...
9
10
11
12
13
14
15
16
17
0
@@ -9,6 +9,9 @@
0
 #
0
 # It's strongly recommended to check this file into your version control system.
0
 
0
+puts "> Loading engines test application base schema"
0
+ActiveRecord::Migration.verbose = ENV['VERBOSE'] || false
0
+
0
 ActiveRecord::Schema.define(:version => 3) do
0
 
0
   %w(aardvarks accounts apples banjos clowns dogs elephants

Comments

    No one has commented yet.