test/test_helper.rb in big_sitemap-1.0.1 vs test/test_helper.rb in big_sitemap-1.0.2

- old
+ new

@@ -7,6 +7,64 @@ require 'test/fixtures/test_model' require 'big_sitemap' class Test::Unit::TestCase + + #TestHelper + private + def generate_sitemap(options={}, &block) + BigSitemap.generate(options.merge(:base_url => 'http://example.com', :document_root => tmp_dir), &block) + end + + def delete_tmp_files + Dir["#{sitemaps_dir}/sitemap*"].each do |f| + FileUtils.rm_rf f + end + end + + def sitemaps_index_file + "#{unzipped_sitemaps_index_file}.gz" + end + + def unzipped_sitemaps_index_file + "#{sitemaps_dir}/sitemap_index.xml" + end + + def unzipped_first_sitemap_file + "#{sitemaps_dir}/sitemap.xml" + end + + def first_sitemap_file + "#{sitemaps_dir}/sitemap.xml.gz" + end + + def second_sitemap_file + "#{sitemaps_dir}/sitemap_1.xml.gz" + end + + def third_sitemap_file + "#{sitemaps_dir}/sitemap_2.xml.gz" + end + + def sitemaps_dir + tmp_dir + end + + def tmp_dir + '/tmp' + end + + def ns + {'s' => 'http://www.sitemaps.org/schemas/sitemap/0.9'} + end + + def elements(filename, el) + file_class = filename.include?('.gz') ? Zlib::GzipReader : File + data = Nokogiri::XML.parse(file_class.open(filename).read) + data.search("//s:#{el}", ns) + end + + def num_elements(filename, el) + elements(filename, el).size + end end