project = 'quicktest' def test_dir; Dir.chdir('spec') {|dir| yield dir } end def run command res = `#{command}` exit $?.exitstatus if $?.exitstatus != 0 res end desc "test" task :test do t = 'spec -r ../lib/quicktest test.rb' test_dir {(puts (run "#{t} >| test_result.txt || #{t}"))} end namespace :test do run = '../bin/quickspec test.rb' task :generate do test_dir {run "#{run} >| test_result.txt"} end desc "test quickspec executable" task :quickspec => :generate do test_dir {(puts (run "#{run}"))} end desc "test readme file" task :readme do (puts (run "./bin/quickspec README")) end end class IO def self.write( file, str ) self.open( file, 'w' ) { |fh| fh.print str } end def self.read_write( file, write_file=file ) self.write(write_file, (yield( self.read( file )))) end end class String def split_join( splitter=$/ ) yield( split( splitter ) ).join( splitter ) end end def decode_readme &block fail unless block_given? begin old_readme = nil File.read_write( 'README' ) do |text| old_readme = text text.split_join do |arr| arr.reject {|l| l =~ /^=(?:begin|end)/} end end block.call ensure File.write( 'README', old_readme ) if old_readme end end desc "generate documentation" task :rdoc do decode_readme do fail unless system 'rdoc --force-update --quiet README lib/*' end end namespace :readme do desc "dump modified README" task :decode do decode_readme do puts File.read('README') end end desc "create html for website using coderay, use --silent option" task :html do rm_rf 'doc' decode_readme do fail unless system 'rdoc --force-update --quiet README' end require 'hpricot' doc = open( 'doc/files/README.html' ) { |f| Hpricot(f) } # find example code doc.at('#description').search('pre'). select {|elem| elem.inner_html =~ /class |module /}.each do |ex| # add coderay and undo what rdoc has done in the example code ex.swap("#{ex.inner_html.gsub('"', '"').gsub('>','>')}") end puts doc.at('#description').to_html end end desc "release a new gem to rubyforge" task :release => [:test,:record,:rdoc,:website,:package] do Dir.chdir('pkg') do release = Dir['*.gem'].sort_by {|file| File.mtime(file)}.last release =~ /^[^-]+-([.0-9]+).gem$/ (puts (run "rubyforge login && rubyforge add_release #{project} #{project} #$1 #{release}")) end Dir.chdir('doc') do run "scp -r ./ gregwebs@rubyforge.org:/var/www/gforge-projects/#{project}" end end desc "update website" file :website => ['README','rakefile'] do Dir.chdir '/home/greg/sites/projects/' do (puts (run 'rake projects:update')) (puts (run 'rake deploy:rsync')) end end desc 'git add and push' task :record do unless `git diff`.chomp.empty? ARGV.clear puts "enter commit message" (puts (run "git commit -a -m #{Kernel.gets}")) puts "committed! now pushing.. " (puts (run 'git push origin master')) end end require 'rubygems' require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.name = project s.rubyforge_project = project s.version = "0.5.6" s.author = "Greg Weber" s.email = "greg@gregweber.info" s.homepage = "http://quicktest.rubyfore.org/" s.platform = Gem::Platform::RUBY s.summary = "utility for inlining tests with the code tested" s.executables = ['quickspec'] s.files = FileList.new('./**', '*/**') do |fl| fl.exclude('pkg','pkg/*','tmp','tmp/*') end s.require_path = "lib" s.has_rdoc = true s.extra_rdoc_files = ["README"] s.add_dependency('rspec', '>= 1.0.0') s.post_install_message = <<-EOS spec and quickspec are ruby executable scripts, whose directory location must be in your PATH environment variable (or you must invoke the with the full file path). run tests with quickspec [file1 file2 ...] EOS end Rake::GemPackageTask.new(spec) do |pkg| pkg.need_tar = false end