| Class | Webgen::PluginTestCase |
| In: |
lib/webgen/test.rb
|
| Parent: | TestCase |
Base class for all plugin test cases. It ensures that all needed plugins are loaded and initalized before each test and that the original environment is restored afterwards.
Specifies files as the plugin files which define the plugin which should be tested and its dependencies.
# File lib/webgen/test.rb, line 78
78: def plugin_files( files = nil )
79: (files.nil? ? @plugin_files.to_a + ['webgen/plugins/coreplugins/configuration.rb'] : @plugin_files = files )
80: end
The name of the plugin which should be tested.
# File lib/webgen/test.rb, line 83
83: def plugin_to_test( plugin = nil )
84: @plugin_name ||= nil
85: (plugin.nil? ? @plugin_name : @plugin_name = plugin )
86: end
# File lib/webgen/test.rb, line 128
128: def self.sample_site( filename = '' )
129: path_helper( :@base_fixture_path, File.join( 'sample_site', filename ) )
130: end
# File lib/webgen/test.rb, line 161
161: def self.suite
162: if self == PluginTestCase
163: return Test::Unit::TestSuite.new('Webgen::TestCase')
164: else
165: super
166: end
167: end
# File lib/webgen/test.rb, line 145
145: def find_in_sample_site
146: files = Set.new
147: Find.find( sample_site( Webgen::SRC_DIR ) ) do |path|
148: Find.prune if File.basename( path ) =~ /^\./
149: path += '/' if FileTest.directory?(path)
150: files << path if yield( path )
151: end
152: files
153: end
# File lib/webgen/test.rb, line 136
136: def param_for_plugin( plugin_name, param )
137: case [plugin_name, param]
138: when ['Core/Configuration', 'srcDir'] then sample_site( Webgen::SRC_DIR )
139: when ['Core/Configuration', 'outDir'] then sample_site( 'out' )
140: when ['Core/Configuration', 'websiteDir'] then sample_site
141: else PluginParamValueNotFound
142: end
143: end
# File lib/webgen/test.rb, line 155
155: def remove_consts( obj, constants )
156: constants.each do |c|
157: obj.remove_const( c )
158: end
159: end
# File lib/webgen/test.rb, line 132
132: def sample_site( filename = '' )
133: self.class.sample_site( filename )
134: end
# File lib/webgen/test.rb, line 94
94: def setup
95: @loader = PluginLoader.new( @wrapper = Module.new )
96:
97: begin
98: self.class.plugin_files.each {|p| @loader.load_from_file( p ) }
99: rescue Exception => e
100: puts "Caught exception during loading of plugins in #setup: #{e.message} - #{e.backtrace.first}"
101: end
102:
103: @manager = PluginManager.new( [@loader], @loader.plugin_classes )
104: if $VERBOSE
105: @manager.logger = Webgen::Logger.new
106: @manager.logger.level = ::Logger::DEBUG
107: end
108: @manager.plugin_config = self
109: @manager.init
110:
111: if !@manager.plugins.has_key?( 'ContentConverter/Default' )
112: x = @manager.plugins['ContentConverter/Default'] = Object.new
113: def x.registered_handlers
114: formatters = Hash.new {|h, k| h[k] = proc {|c| c} }
115: def formatters.has_key?( value ); true; end
116: formatters
117: end
118: end
119:
120: @plugin = @manager[self.class.plugin_to_test] if self.class.plugin_to_test
121: end