project = 'quicktest' def test_dir; Dir.chdir('test') {|dir| yield dir } end desc "test" task :test do run = 'spec -r ../lib/quicktest test.rb' test_dir {puts `#{run} >| test_result.txt || #{run}`} exit $?.exitstatus if $?.exitstatus != 0 end namespace :test do run = '../bin/quickspec test.rb' task :generate do test_dir {`#{run} >| test_result.txt`} exit $?.exitstatus if $?.exitstatus != 0 end desc "test quickspec executable" task :quickspec => :generate do test_dir {puts `#{run}`} exit $?.exitstatus if $?.exitstatus != 0 end desc "test readme file" task :README do puts `./bin/quickspec README` exit $?.exitstatus if $?.exitstatus != 0 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 => :rdoc do 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 => [:rdoc,:package] do Dir.chdir('pkg') do release = Dir['*.gem'].sort_by {|file| File.mtime(file)}.last release =~ /^[^-]+-([.0-9]+).gem$/ `rubyforge login && rubyforge add_release #{project} #{project} #$1 #{release}` end end require 'rubygems' require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.name = project s.rubyforge_project = project s.version = "0.5.0" 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 = Dir['./**'] + Dir['*/**'] s.require_path = "lib" s.has_rdoc = true s.extra_rdoc_files = ["README"] end Rake::GemPackageTask.new(spec) do |pkg| pkg.need_tar = false end