tdoc 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +4 -14
  2. data/bin/tdoc.rb +39 -9
  3. metadata +2 -2
data/README.rdoc CHANGED
@@ -10,6 +10,7 @@ Tdoc combines rdoc, test::unit and shoulda, and concepts from rubytestdoc.
10
10
  - Tdoc understands the following directives:
11
11
  - tdoc_require
12
12
  - tdoc_context
13
+ - RDoc's standard :include: directive now does the same thing as tdoc_context
13
14
  - tdoc_setup
14
15
  - examples
15
16
  - within each examples block, Tdoc will convert cut and pastes from irb into assert_equal blocks, so
@@ -19,22 +20,11 @@ Tdoc combines rdoc, test::unit and shoulda, and concepts from rubytestdoc.
19
20
  assert_equal "asdf","asdf"
20
21
  Tdoc will then include all assertions within the context created from the example block
21
22
 
22
- tdoc_require: rubygems
23
+ :include:rdoc/example.rdoc
23
24
 
24
- examples: simple irb with 1 assertion
25
-
26
- >> "asdf"
27
- => "asdf"
28
- >> x="foo"
29
- => "foo"
30
- >> x
31
- => "foo"
32
- assert_raise ZeroDivisionError do; 1/0 ;end
33
-
34
-
35
- usage:
25
+ usage:
36
26
 
37
- tdoc [test_directory] [extention]
27
+ tdoc [test_directory] [extention]
38
28
 
39
29
 
40
30
 
data/bin/tdoc.rb CHANGED
@@ -2,26 +2,56 @@
2
2
  require 'rubygems'
3
3
  require 'test/unit'
4
4
  require 'shoulda'
5
+ require 'optparse'
5
6
 
6
7
  $: << 'lib'
7
8
 
8
- TEST_DIR=ARGV[0] || 'tdoc/'
9
- EXTENTION=ARGV[1] || '.tdoc'
10
9
  LINST='^[#|\s]*'
11
10
 
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)}
34
+ end
12
35
  def mk_context(file,test_case=nil)
13
36
  test_name=File.basename(file).sub(EXTENTION,'')
14
37
  unless test_case
15
- test_case=eval "::Test#{test_name.capitalize}=Class.new(Test::Unit::TestCase)"
38
+ test_case=Class.new(Test::Unit::TestCase)
39
+ Object.const_set(:"Test#{test_name.capitalize}", test_case)
16
40
  end
17
41
  text=File.read(file)
18
42
  directives=text.scan(/#{LINST}tdoc_(.+?):\s*(.+)/).inject({}) {|h,d| h[d[0].to_sym]||=[];h[d[0].to_sym] << d[1];h}
19
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/)
48
+ end
49
+ end
20
50
  directives[:context].to_a.each {|c| mk_context "#{TEST_DIR}#{c}", test_case}
21
51
  tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
22
52
  test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m| "assert_equal #{$1}, #{$2}"}
23
53
  lines=test.split(/\n/)
24
- test_text=lines.map {|l| l.match(/#{LINST}(assert.+)/) && $1}.compact.join ";"
54
+ test_text=lines.map {|l| l.match(/#{LINST}(assert.+)/) && $1}.compact.join ";\n"
25
55
  [lines[0], test_text]
26
56
  end
27
57
  test_case.context test_name do
@@ -30,16 +60,16 @@ def mk_context(file,test_case=nil)
30
60
  end
31
61
  tests.each do |test|
32
62
  should test[0] do
33
- eval test[1]
63
+ eval test[1]
34
64
  end
35
65
  end
36
66
  end
37
67
  end
38
- def mk_tests(test_dir)
39
- files=Dir.glob("#{test_dir}*#{EXTENTION}")
40
- files.each { |file| mk_context(file)}
68
+ if Object.const_defined?(:TEST_DIR)
69
+ mk_tests(TEST_DIR)
70
+ else
71
+ process
41
72
  end
42
- mk_tests(TEST_DIR)
43
73
 
44
74
 
45
75
 
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.2.0
4
+ version: 0.3.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-25 00:00:00 -03:00
12
+ date: 2011-11-26 00:00:00 -03:00
13
13
  default_executable: tdoc.rb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency