# File lib/rubigen/helpers/generator_test_helper.rb, line 104
104: def app_root_files
105: Dir[APP_ROOT + '/**/*']
106: end
asserts that the given directory exists
# File lib/rubigen/helpers/generator_test_helper.rb, line 57
57: def assert_directory_exists(path)
58: assert File.directory?("#{APP_ROOT}/#{path}"),"The directory '#{path}' should exist"
59: end
asserts that the given file exists
# File lib/rubigen/helpers/generator_test_helper.rb, line 52
52: def assert_file_exists(path)
53: assert File.exists?("#{APP_ROOT}/#{path}"),"The file '#{path}' should exist"
54: end
asserts that the given class source file was generated. It takes a path without the .rb part and an optional super class. the contents of the class source file is passed to a block.
# File lib/rubigen/helpers/generator_test_helper.rb, line 64
64: def assert_generated_class(path,parent=nil)
65: path=~/\/?(\d+_)?(\w+)$/
66: class_name=$2.camelize
67: assert_generated_file("#{path}.rb") do |body|
68: assert body=~/class #{class_name}#{parent.nil? ? '':" < #{parent}"}/,"the file '#{path}.rb' should be a class"
69: yield body if block_given?
70: end
71: end
asserts that the given file was generated. the contents of the file is passed to a block.
# File lib/rubigen/helpers/generator_test_helper.rb, line 44
44: def assert_generated_file(path)
45: assert_file_exists(path)
46: File.open("#{APP_ROOT}/#{path}") do |f|
47: yield f.read if block_given?
48: end
49: end
asserts that the given module source file was generated. It takes a path without the .rb part. the contents of the class source file is passed to a block.
# File lib/rubigen/helpers/generator_test_helper.rb, line 76
76: def assert_generated_module(path)
77: path=~/\/?(\w+)$/
78: module_name=$1.camelize
79: assert_generated_file("#{path}.rb") do |body|
80: assert body=~/module #{module_name}/,"the file '#{path}.rb' should be a module"
81: yield body if block_given?
82: end
83: end
asserts that the given unit test was generated. It takes a name or symbol without the test_ part and an optional super class. the contents of the class source file is passed to a block.
# File lib/rubigen/helpers/generator_test_helper.rb, line 88
88: def assert_generated_test_for(name, parent="Test::Unit::TestCase")
89: assert_generated_class "test/test_#{name.to_s.underscore}", parent do |body|
90: yield body if block_given?
91: end
92: end
asserts that the given methods are defined in the body. This does assume standard rails code conventions with regards to the source code. The body of each individual method is passed to a block.
# File lib/rubigen/helpers/generator_test_helper.rb, line 97
97: def assert_has_method(body,*methods)
98: methods.each do |name|
99: assert body=~/^ def #{name.to_s}\n((\n| .*\n)*) end/,"should have method #{name.to_s}"
100: yield( name, $1 ) if block_given?
101: end
102: end
# File lib/rubigen/helpers/generator_test_helper.rb, line 123
123: def bare_setup
124: FileUtils.mkdir_p(APP_ROOT)
125: @stdout = StringIO.new
126: end
# File lib/rubigen/helpers/generator_test_helper.rb, line 128
128: def bare_teardown
129: FileUtils.rm_rf TMP_ROOT || APP_ROOT
130: end
Instatiates the Generator
# File lib/rubigen/helpers/generator_test_helper.rb, line 15
15: def build_generator(name, params, sources, options)
16: @stdout ||= StringIO.new
17: options.merge!(:collision => :force) # so no questions are prompted
18: options.merge!(:stdout => @stdout) # so stdout is piped to a StringIO
19: if sources.is_a?(Symbol)
20: if sources == :app
21: RubiGen::Base.use_application_sources!
22: else
23: RubiGen::Base.use_component_sources!
24: end
25: else
26: RubiGen::Base.reset_sources
27: RubiGen::Base.prepend_sources(*sources) unless sources.blank?
28: end
29: RubiGen::Base.instance(name, params, options)
30: end
# File lib/rubigen/helpers/generator_test_helper.rb, line 108
108: def rubygem_folders
109: ]bin examples lib test]
110: end
# File lib/rubigen/helpers/generator_test_helper.rb, line 112
112: def rubygems_setup
113: bare_setup
114: rubygem_folders.each do |folder|
115: Dir.mkdir("#{APP_ROOT}/#{folder}") unless File.exists?("#{APP_ROOT}/#{folder}")
116: end
117: end
# File lib/rubigen/helpers/generator_test_helper.rb, line 119
119: def rubygems_teardown
120: bare_teardown
121: end
Runs the create command (like the command line does)
# File lib/rubigen/helpers/generator_test_helper.rb, line 6
6: def run_generator(name, params, sources, options = {})
7: generator = build_generator(name, params, sources, options)
8: silence_generator do
9: generator.command(:create).invoke!
10: end
11: generator
12: end
Silences the logger temporarily and returns the output as a String
# File lib/rubigen/helpers/generator_test_helper.rb, line 33
33: def silence_generator
34: logger_original = RubiGen::Base.logger
35: myout = StringIO.new
36: RubiGen::Base.logger = RubiGen::SimpleLogger.new(myout)
37: yield if block_given?
38: RubiGen::Base.logger = logger_original
39: myout.string
40: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.