Skip to content
Browse files

- update tests

  • Loading branch information...
1 parent 8cf663a commit 9c704c395ab950920e6bdab7c71bf0ab652288e9 @adamsalter adamsalter committed Sep 14, 2009
Showing with 80 additions and 15 deletions.
  1. +35 −2 .autotest
  2. +9 −8 Rakefile
  3. +6 −5 tasks/sitemap_generator_tasks.rake
  4. +19 −0 test/sitemap_generator_test.rb
  5. +11 −0 test/test_helper.rb
View
37 .autotest
@@ -1,3 +1,36 @@
-Autotest.add_discovery do
- "rspec"
+class Autotest
+ ##
+ # Convert a path in a string, s, into a class name, changing
+ # underscores to CamelCase, etc.
+
+ def path_to_classname(s)
+ sep = File::SEPARATOR
+ f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
+ f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
+ f = f.map { |path| path =~ /Test$/ ? path : "#{path}Test" }
+ f.join('::')
+ end
end
+
+Autotest.add_hook :initialize do |at|
+ unless ARGV.empty?
+ if ARGV[0] == '-d'
+ at.find_directories = ARGV[1..-1].dup
+ else
+ at.find_directories = []
+ at.extra_files = ARGV.dup
+ end
+ end
+
+ # doesn't seem to work
+ # at.clear_mappings
+
+ at.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
+ possible = File.basename(filename, 'rb').gsub '_', '_?'
+ files_matching %r%^test/.*#{possible}_test\.rb$%
+ end
+
+ at.add_mapping(/^test.*\/.*test\.rb$/) do |filename, _|
+ filename
+ end
+end
View
17 Rakefile
@@ -1,12 +1,13 @@
-require 'rake'
-require 'spec/rake/spectask'
+require 'rake/testtask'
+require 'find'
-desc 'Default: run specs.'
-task :default => :spec
+desc 'Default: run unit tests.'
+task :default => :test
-desc 'Run the specs'
-Spec::Rake::SpecTask.new(:spec) do |t|
+desc 'Test ActiveScaffold.'
+Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
- t.spec_files = FileList['spec/**/*_spec.rb']
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
end
+
View
11 tasks/sitemap_generator_tasks.rake
@@ -14,6 +14,7 @@ namespace :sitemap do
end
desc "Create Sitemap XML files in public/ directory"
+ desc "Create Sitemap XML files in public/ directory (set SILENT=true for no output)"
task :refresh => ['sitemap:create'] do
ping_search_engines("sitemap_index.xml.gz")
end
@@ -49,8 +50,8 @@ namespace :sitemap do
Zlib::GzipWriter.open(filename) do |gz|
gz.write buffer
end
- puts "+ #{filename}"
- puts "** Sitemap too big! The uncompressed size exceeds 10Mb" if buffer.size > 10 * 1024 * 1024
+ puts "+ #{filename}" unless ENV['SILENT'].present?
+ puts "** Sitemap too big! The uncompressed size exceeds 10Mb" if (buffer.size > 10 * 1024 * 1024) && ENV['SILENT'].blank?
sitemap_files << filename
end
@@ -63,11 +64,11 @@ namespace :sitemap do
Zlib::GzipWriter.open(filename) do |gz|
gz.write buffer
end
- puts "+ #{filename}"
- puts "** Sitemap Index too big! The uncompressed size exceeds 10Mb" if buffer.size > 10 * 1024 * 1024
+ puts "+ #{filename}" unless ENV['SILENT'].present?
+ puts "** Sitemap Index too big! The uncompressed size exceeds 10Mb" if (buffer.size > 10 * 1024 * 1024) && ENV['SILENT'].blank?
stop_time = Time.now
- puts "Sitemap stats: #{number_with_delimiter(SitemapGenerator::Sitemap.links.length)} links, " + ("%dm%02ds" % (stop_time - start_time).divmod(60))
+ puts "Sitemap stats: #{number_with_delimiter(SitemapGenerator::Sitemap.links.length)} links, " + ("%dm%02ds" % (stop_time - start_time).divmod(60)) unless ENV['SILENT'].present?
end
end
View
19 test/sitemap_generator_test.rb
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class SitemapGeneratorTest < Test::Unit::TestCase
+ context "SitemapGenerator Rake Task" do
+ setup do
+ ::Rake::Task['sitemap:refresh'].invoke
+ end
+
+ should "fail if hostname not defined" do
+ end
+ end
+
+ context "SitemapGenerator library" do
+ should "be have x elements" do
+ assert_equal SitemapGenerator::Sitemap.links.size, 14
+ end
+ end
+end
+
View
11 test/test_helper.rb
@@ -0,0 +1,11 @@
+ENV['RAILS_ENV'] = 'test'
+ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app')
+
+require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
+
+require 'rake'
+require 'shoulda'
+
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'tasks/rails'

0 comments on commit 9c704c3

Please sign in to comment.
Something went wrong with that request. Please try again.