提交 8a0f4564 编写于 作者: C Carl Lerche

Refactored railties' isolation tests to be able to run script/* scripts.

上级 3e35d30c
......@@ -81,7 +81,6 @@ module Generation
def build_app(options = {})
FileUtils.rm_rf(app_path)
FileUtils.cp_r(tmp_path('app_template'), app_path)
FileUtils.ln_s(RAILS_FRAMEWORK_ROOT, app_path('vendor/rails'))
# Delete the initializers unless requested
unless options[:initializers]
......@@ -93,6 +92,12 @@ def build_app(options = {})
add_to_config 'config.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }'
end
def script(script)
Dir.chdir(app_path) do
`#{Gem.ruby} #{app_path}/script/#{script}`
end
end
def add_to_config(str)
environment = File.read("#{app_path}/config/application.rb")
if environment =~ /(\n\s*end\s*)\Z/
......@@ -149,8 +154,12 @@ class Test::Unit::TestCase
if File.exist?(tmp_path)
FileUtils.rm_rf(tmp_path)
end
FileUtils.mkdir(tmp_path)
root = File.expand_path('../../../..', __FILE__)
`#{Gem.ruby} -r #{root}/vendor/gems/environment #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
environment = File.expand_path('../../../../vendor/gems/environment', __FILE__)
`#{Gem.ruby} -r #{environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
f.puts "require '#{environment}' ; require 'rails'"
end
end
require "isolation/abstract_unit"
module ApplicationTests
class PluginTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
build_app
end
test "generates the plugin" do
script "generate plugin my_plugin"
File.open("#{app_path}/vendor/plugins/my_plugin/init.rb", 'w') do |f|
f.puts "OMG = 'hello'"
end
require "#{app_path}/config/environment"
end
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册