tdoc 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +16 -6
  2. data/bin/tdoc.rb +31 -42
  3. metadata +2 -2
data/README.rdoc CHANGED
@@ -3,9 +3,19 @@
3
3
 
4
4
  == Test oriented documentation
5
5
 
6
- Tdoc combines rdoc, test::unit and shoulda, and concepts from rubytestdoc.
7
-
8
- - Tdoc files (default extention: .tdoc) map to Test::Unit::TestCase classes with a single context
6
+ *note:* Version 0.4.0 completely breaks the API from 0.3.0
7
+
8
+ Tdoc takes a single argument specifying the file or glob to be processed. If no arguments are given, Tdoc will process "README.rdoc" in the working directory.
9
+
10
+ - Tdoc will map each file given to a Test::Unit::TestCase.
11
+ - For each such file, named e.g. '_filename_.rdoc', Tdoc will:
12
+ - require '<i>filename</i>_include.rb' if it exists
13
+ - create a context with the test case for each file in the directory named '_filename_' if it exists.
14
+ - process all :include: directives as follows:
15
+ -
16
+
17
+
18
+
9
19
  - Tdoc directives take up 1 line, with the exception of the "examples" directive. They may be preceded by any number of whitespace characters and terminate with a colon.
10
20
  - Tdoc understands the following directives:
11
21
  - tdoc_require
@@ -20,11 +30,11 @@ Tdoc combines rdoc, test::unit and shoulda, and concepts from rubytestdoc.
20
30
  assert_equal "asdf","asdf"
21
31
  Tdoc will then include all assertions within the context created from the example block
22
32
 
23
- :include:rdoc/example.rdoc
24
-
25
33
  usage:
26
34
 
27
- tdoc [test_directory] [extention]
35
+ tdoc [FILE_GLOB]
28
36
 
37
+ examples:
29
38
 
39
+ :include:rdoc/example.rdoc
30
40
 
data/bin/tdoc.rb CHANGED
@@ -2,52 +2,46 @@
2
2
  require 'rubygems'
3
3
  require 'test/unit'
4
4
  require 'shoulda'
5
- require 'optparse'
6
5
 
7
6
  $: << 'lib'
8
7
 
9
8
  LINST='^[#|\s]*'
9
+ LINSTM='[#|\s]*'
10
+ EXTENSIONS={:tests => '.rdoc',:requires => '_require.rb'}
11
+ DEFAULT_FILE="README#{EXTENSIONS[:tests]}"
10
12
 
11
- def process
12
- mk_context(@opts[:filename])
13
- end
14
- @opts={}
15
- OptionParser.new do |o|
16
- o.on('-d DIRECTORY') { |d| @opts[:directory]=d}
17
- o.on('-f FILENAME') { |f| @opts[:filename]=f}
18
- o.on('-e EXTENTION') { |e| @opts[:extension]=e}
19
- o.on('-h') { puts o; exit }
20
- o.parse!
21
- end
22
-
23
- if @opts.empty?#for backward compatibility
24
- TEST_DIR=ARGV[0] || 'tdoc/'
25
- EXTENTION=ARGV[1] || '.tdoc'
26
- else
27
- TEST_DIR=@opts[:directory] || 'rdoc/'
28
- EXTENTION=@opts[:extension] || '.rdoc'
29
- end
30
-
31
- def mk_tests(test_dir)
32
- files=Dir.glob("#{test_dir}*#{EXTENTION}")
33
- files.each { |file| mk_context(file)}
13
+ def process(files=nil) #called at end of script
14
+ files=ARGV.shift if ARGV
15
+ files||=DEFAULT_FILE
16
+ if files.class==Array
17
+ files.each {|f|`#{$PROGRAM_NAME} #{f}`}
18
+ else
19
+ mk_test_context(files)
20
+ end
34
21
  end
35
- def mk_context(file,test_case=nil)
36
- test_name=File.basename(file).sub(EXTENTION,'')
22
+ def mk_test_context(file, test_case=nil)
23
+ test_name=File.basename(file).sub(/\..*?$/,'')
24
+ test_dir=File.dirname(file)
37
25
  unless test_case
38
26
  test_case=Class.new(Test::Unit::TestCase)
39
27
  Object.const_set(:"Test#{test_name.capitalize}", test_case)
40
28
  end
41
29
  text=File.read(file)
42
- directives=text.scan(/#{LINST}tdoc_(.+?):\s*(.+)/).inject({}) {|h,d| h[d[0].to_sym]||=[];h[d[0].to_sym] << d[1];h}
43
- directives[:require].to_a.each {|r| require r}
44
- directives[:context]||=[]
45
- text.scan(/#{LINST}:include:\s*(.+)/).each do |i|
46
- i[0].split(',').each do |file|
47
- directives[:context] << file unless file.match(/^blob/)
30
+ opts={
31
+ :requires => Dir.glob("#{test_dir}/#{test_name}#{EXTENSIONS[:requires]}"),
32
+ :contexts => Dir.glob("#{test_dir}/#{test_name}/*#{EXTENSIONS[:tests]}"),
33
+ :test_cases => [],
34
+ }
35
+ [:requires, :test_cases].each do |opt|
36
+ text.scan(/#{LINST}:include:\s*(.+#{EXTENSIONS[opt]})/).each do |files|
37
+ files[0].split(',').each do |f|
38
+ opts[opt] << f unless f.match(/^blob/)
39
+ end
48
40
  end
49
41
  end
50
- directives[:context].to_a.each {|c| mk_context "#{TEST_DIR}#{c}", test_case}
42
+ opts[:requires].each {|r| require "#{r}" if FileTest.exist? "#{r}" }
43
+ opts[:test_cases].delete_if {|c| c.match(/#{test_name}/)}
44
+ opts[:setup]=text.match(/#{LINSTM}setup\s+(.*?)#{LINSTM}end\s+/m).to_a[1]
51
45
  tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
52
46
  test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m| "assert_equal #{$1}, #{$2}"}
53
47
  lines=test.split(/\n/)
@@ -56,7 +50,7 @@ def mk_context(file,test_case=nil)
56
50
  end
57
51
  test_case.context test_name do
58
52
  setup do
59
- eval directives[:setup].to_a.join ';'
53
+ eval opts[:setup].to_a.join ';'
60
54
  end
61
55
  tests.each do |test|
62
56
  should test[0] do
@@ -64,12 +58,7 @@ def mk_context(file,test_case=nil)
64
58
  end
65
59
  end
66
60
  end
61
+ opts[:contexts].compact.each {|c| mk_test_context "#{c}", test_case}
62
+ opts[:test_cases].each {|c| process(c)}
67
63
  end
68
- if Object.const_defined?(:TEST_DIR)
69
- mk_tests(TEST_DIR)
70
- else
71
- process
72
- end
73
-
74
-
75
-
64
+ process
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herb Daily
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2011-11-26 00:00:00 -03:00
12
+ date: 2011-11-28 00:00:00 -03:00
13
13
  default_executable: tdoc.rb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency