public
Description: Utility for inlining unit tests with the code under test.
Homepage: http://projects.gregweber.info/quicktest.html
Clone URL: git://github.com/gregwebs/quicktest.git
Click here to lend your support to: quicktest and make a donation at www.pledgie.com !
quicktest / Rakefile
100644 104 lines (90 sloc) 2.435 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
$project = 'quicktest'
require 'tasks/helpers'
$rcov_index_html = 'coverage/lib-quicktest_rb.html'
 
def test_dir; Dir.chdir('spec') {|dir| yield dir } end
 
class String
  def split_join( splitter=$/ )
    yield( split( splitter ) ).join( splitter )
  end
end
 
desc "test"
task :test do
  t = 'spec -r ../lib/quicktest test.rb'
  test_dir do
    (puts (run "#{t} >| test_result.txt || #{t}"))
    (puts (run '../bin/quickspec test.rb'))
    (puts (run '../bin/quickspec __test.rb --quicktest __test'))
  end
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
 
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'
    require 'htmlentities'
    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("<coderay lang='ruby'>#{HTMLEntities.new.decode ex.inner_html}</coderay>")
    end
    puts doc.at('#description').to_html
  end
end
 
require 'rubygems'
require 'rake/gempackagetask'
require 'quicktest.gemspec.rb'
 
Rake::GemPackageTask.new($gem_specification) do |pkg|
  pkg.need_tar = false
end
 
desc "generate the gem specification"
task :gem_specification do
  File.open('quicktest.gemspec', 'w') do |fh|
    fh.puts $gem_specification.to_ruby
  end
end