module Webgen::TestHelper

Public Instance Methods

assert_error_on_line(error_class, line) { || ... } click to toggle source

Fails if the given block does not raise error_class and the error is not on the line.

   # File lib/webgen/test_helper.rb
43 def assert_error_on_line(error_class, line)
44   begin
45     yield
46   rescue error_class => e
47     assert_equal(line, (e.respond_to?(:line) ? e.line : Webgen::Error.error_line(e)))
48   else
49     fail "No exception raised though #{error_class} expected"
50   end
51 end
assert_log_match(reg, io = @logio) click to toggle source

Fails if the log string does not match the regular expression.

Uses the StringIO @logio if no other StringIO is given and resets the log string after the check.

   # File lib/webgen/test_helper.rb
64 def assert_log_match(reg, io = @logio)
65   assert_match(reg, io.string)
66   @logio.string = ''
67 end
assert_nothing_logged(io = @logio) click to toggle source

Fails if the log string is not empty.

Uses the StringIO @logio if no other StringIO is given.

   # File lib/webgen/test_helper.rb
56 def assert_nothing_logged(io = @logio)
57   assert_equal('', io.string)
58 end
setup_context() click to toggle source

Creates a Webgen::Context object that is returned and accessible via @context.

The needed website object is created using setup_website and the :chain is set to a mock node that responds to :alcn with '/test'.

    # File lib/webgen/test_helper.rb
162 def setup_context
163   setup_website
164   node = Object.new
165   node.define_singleton_method(:alcn) { '/test' }
166   @context = Webgen::Context.new(@website, :chain => [node], :doit => 'hallo')
167 end
setup_default_nodes(tree, klass = Webgen::Node) click to toggle source

Adds the following nodes (showing alcn=dest_path, title, other meta info) to the tree which has to be empty:

/
/file.en.html            'file en' sort_info=3
/file.en.html#frag       'frag'
/file.en.html#nested     'fragnested' routing_path="/routed.html"
/file.de.html            'file de' sort_info=5
/file.de.html#frag       'frag'
/other.html              'other'
/other.en.html           'other en'
/german.de.html          'german' dest_path='/german.other.html'
/dir/                    'dir'
/dir/subfile.html        'subfile'
/dir/subfile.html#frag   'frag'
/dir/dir/                'dir'
/dir/dir/file.html       'file'
/dir2/                   'dir2' proxy_path='index.html'
/dir2/index.en.html      'index en' routed_title='routed en' link_attrs={'class' => 'help'}
/dir2/index.de.html      'index de' routed_title='routed de'
    # File lib/webgen/test_helper.rb
131 def setup_default_nodes(tree, klass = Webgen::Node)
132   root = klass.new(tree.dummy_root, '/', '/')
133 
134   file_en = klass.new(root, 'file.html', '/file.en.html', {'lang' => 'en', 'title' => 'file en', 'sort_info' => 3})
135   frag_en = klass.new(file_en, '#frag', '/file.en.html#frag', {'title' => 'frag'})
136   klass.new(frag_en, '#nested', '/file.en.html#nested', {'title' => 'fragnested', 'routing_path' => '/routed.html'})
137   file_de = klass.new(root, 'file.html', '/file.de.html', {'lang' => 'de', 'title' => 'file de', 'sort_info' => 5})
138   klass.new(file_de, '#frag', '/file.de.html#frag', {'title' => 'frag'})
139 
140   klass.new(root, 'other.html', '/other.html', {'title' => 'other'})
141   klass.new(root, 'other.html', '/other.en.html', {'lang' => 'en', 'title' => 'other en'})
142 
143   klass.new(root, 'german.html', '/german.other.html', {'title' => 'german', 'lang' => 'de'})
144 
145   dir = klass.new(root, 'dir/', '/dir/', {'title' => 'dir'})
146   dir_file = klass.new(dir, 'subfile.html', '/dir/subfile.html', {'title' => 'subfile'})
147   klass.new(dir_file, '#frag', '/dir/subfile.html#frag', {'title' => 'frag'})
148   dir_dir = klass.new(dir, 'dir/' , '/dir/dir/', {'title' => 'dir'})
149   klass.new(dir_dir, 'file.html', '/dir/dir/file.html', {'title' => 'file'})
150 
151   dir2 = klass.new(root, 'dir2/', '/dir2/', {'proxy_path' => 'index.html', 'title' => 'dir2'})
152   klass.new(dir2, 'index.html', '/dir2/index.en.html',
153                    {'lang' => 'en', 'routed_title' => 'routed', 'title' => 'index en', 'link_attrs' => {'class'=>'help'}})
154   klass.new(dir2, 'index.html', '/dir2/index.de.html',
155                    {'lang' => 'de', 'routed_title' => 'routed de', 'title' => 'index de'})
156 end
setup_tag_template(root) click to toggle source

Creates and returns a RenderNode /tag.template using the default tag template.

    # File lib/webgen/test_helper.rb
170 def setup_tag_template(root)
171   template_data = File.read(File.join(Webgen::Utils.data_dir, 'passive_sources', 'templates', 'tag.template'))
172   RenderNode.new(template_data, root, 'tag.template', '/tag.template')
173 end
setup_website(config = {}) click to toggle source

Creates a basic stub website that is accessible via @website with the following methods:

@website.config

The given config object or {} if none specified

@website.directory

Set to a non-existent temporary directory

@website.tmpdir

Set to @website.directory/tmp

@website.ext

OpenStruct instance. The accessor item_tracker is set to an object that responds to add.

@website.blackboard

A Webgen::Blackboard instance

@website.logger

Webgen::Logger instance with a StringIO as target. The StringIO target is also available via @logio.

@website.tree

Webgen::Tree instance

    # File lib/webgen/test_helper.rb
 92 def setup_website(config = {})
 93   @website = OpenStruct.new
 94   @website.config = config
 95   @website.directory = Dir::Tmpname.create("test-webgen-website") {|path| raise Errno::EEXIST if File.directory?(path)}
 96   @website.define_singleton_method(:tmpdir) do |path='', create=false|
 97     tmp = File.join(self.directory, 'tmp')
 98     FileUtils.mkdir_p(tmp) if create
 99     File.join(tmp, path)
100   end
101   @website.ext = OpenStruct.new
102   @website.blackboard = Webgen::Blackboard.new
103   @website.cache = Webgen::Cache.new
104   @logio = StringIO.new
105   @website.logger = Webgen::Logger.new(@logio)
106   @website.tree = Webgen::Tree.new(@website)
107   @website.ext.item_tracker = Object.new
108   @website.ext.item_tracker.define_singleton_method(:add) {|*args|}
109 end