aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/test_case.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-03 16:34:32 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-03 17:14:50 +0100
commit271e7c803f116b77f0df48115036421242eb9b32 (patch)
tree8d1a7b52076c30fb4d445aa6ad61111942fd760c /railties/lib/rails/generators/test_case.rb
parent441227a10f42fcd28b65ab416495ff8f4fc45b52 (diff)
downloadrails-271e7c803f116b77f0df48115036421242eb9b32.tar.gz
rails-271e7c803f116b77f0df48115036421242eb9b32.tar.bz2
rails-271e7c803f116b77f0df48115036421242eb9b32.zip
Move all generators tests to use new test case syntax.
Diffstat (limited to 'railties/lib/rails/generators/test_case.rb')
-rw-r--r--railties/lib/rails/generators/test_case.rb23
1 files changed, 19 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb
index 8918a4eb42..643d7856c5 100644
--- a/railties/lib/rails/generators/test_case.rb
+++ b/railties/lib/rails/generators/test_case.rb
@@ -29,12 +29,13 @@ module Rails
class TestCase < ActiveSupport::TestCase
include FileUtils
- extlib_inheritable_accessor :destination_root, :current_path, :instance_writer => false
- extlib_inheritable_accessor :generator_class
+ extlib_inheritable_accessor :destination_root, :current_path, :generator_class,
+ :default_arguments, :instance_writer => false
# Generators frequently change the current path using +FileUtils.cd+.
# So we need to store the path at file load and revert back to it after each test.
self.current_path = File.expand_path(Dir.pwd)
+ self.default_arguments = []
setup :destination_root_is_set?, :ensure_current_path
teardown :ensure_current_path
@@ -47,6 +48,15 @@ module Rails
self.generator_class = klass
end
+ # Sets default arguments on generator invocation. This can be overwritten when
+ # invoking it.
+ #
+ # arguments %w(app_name --skip-activerecord)
+ #
+ def self.arguments(array)
+ self.default_arguments = array
+ end
+
# Sets the destination of generator files:
#
# destination File.expand_path("../tmp", File.dirname(__FILE__))
@@ -195,8 +205,13 @@ module Rails
#
# You can provide a configuration hash as second argument. This method returns the output
# printed by the generator.
- def run_generator(args=[], config={})
- capture(:stdout) { self.generator_class.start args, config.reverse_merge(:destination_root => destination_root) }
+ def run_generator(args=self.default_arguments, config={})
+ capture(:stdout) { self.generator_class.start(args, config.reverse_merge(:destination_root => destination_root)) }
+ end
+
+ # Instantiate the generator.
+ def generator(args=self.default_arguments, options={}, config={})
+ @generator ||= self.generator_class.new(args, options, config.reverse_merge(:destination_root => destination_root))
end
protected