tdoc 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +31 -22
- data/bin/tdoc.rb +2 -1
- data/lib/rdoc/discover +2 -0
- data/lib/rdoc/parsers/tdoc.rb +27 -0
- data/rdoc/example.rb +3 -0
- data/rdoc/example.rdoc +6 -0
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -1,40 +1,49 @@
|
|
1
1
|
|
2
2
|
=Tdoc
|
3
3
|
|
4
|
-
|
4
|
+
*WARNING*: As of version 0.11.0 Tdoc contains an rdoc/discover file which parses .rdoc files by default. I am not aware of any issues that this causes but I haven't tested it with any complex rdoc. So, for now, if your rdoc executable is behaving in an unexpected way, remove this gem and try it again. If it works, please file a bug report. If it doesn't, then it's not my fault :).
|
5
5
|
|
6
|
-
|
6
|
+
== Test oriented documentation
|
7
7
|
|
8
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
9
|
|
10
10
|
- Tdoc will map each file given to a Test::Unit::TestCase.
|
11
11
|
- For each such file, named e.g. '_filename_.rdoc', Tdoc will:
|
12
|
-
- require '<i>filename</i
|
13
|
-
- create a context
|
12
|
+
- require '<i>filename</i>.rb' if it exists
|
13
|
+
- create a context within the test case for each file in the directory named '_filename_' if it exists.
|
14
14
|
- process all :include: directives as follows:
|
15
|
-
-
|
15
|
+
- If the included file has a .rb extention, it will be required in the context of the test case
|
16
|
+
- If it has a .rdoc extention it will map to a context within the test case
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- tdoc_setup
|
25
|
-
- examples
|
26
|
-
- within each examples block, Tdoc will convert cut and pastes from irb into assert_equal blocks, so
|
27
|
-
>> "asdf"
|
28
|
-
=> "asdf"
|
29
|
-
turns into:
|
30
|
-
assert_equal "asdf","asdf"
|
18
|
+
- In addition to ':include:', Tdoc understands the following directives:
|
19
|
+
- example(s): - Text between these directives maps to a Shoulda #should block
|
20
|
+
- within each examples block, Tdoc will convert cut and pastes from irb into assert_equal blocks, so
|
21
|
+
>> "asdf"
|
22
|
+
=> "asdf"
|
23
|
+
turns into:
|
24
|
+
assert_equal "asdf","asdf"
|
31
25
|
Tdoc will then include all assertions within the context created from the example block
|
26
|
+
- setup/end - The first setup/end block is passed to the context's setup method
|
32
27
|
|
33
28
|
usage:
|
34
29
|
|
35
|
-
tdoc [
|
30
|
+
tdoc [file_glob]
|
31
|
+
|
32
|
+
setup
|
33
|
+
@foo='bar'
|
34
|
+
end
|
35
|
+
|
36
|
+
The text between the horizontal lines is included with the ':include:' directive from rdoc/example.rdoc:
|
37
|
+
|
38
|
+
----
|
39
|
+
|
40
|
+
:include:rdoc/example.rdoc
|
41
|
+
|
42
|
+
----
|
36
43
|
|
37
|
-
|
44
|
+
==Now we are back in the README.rdoc file.
|
38
45
|
|
39
|
-
|
46
|
+
example:
|
47
|
+
>>FOOBAR
|
48
|
+
=>'foobar'
|
40
49
|
|
data/bin/tdoc.rb
CHANGED
@@ -27,6 +27,7 @@ end
|
|
27
27
|
def mk_test_context(file, test_case=nil)
|
28
28
|
test_name=File.basename(file).sub(/\..*?$/,'')
|
29
29
|
test_dir=File.dirname(file)
|
30
|
+
$: << test_dir unless $:.include?(test_dir)
|
30
31
|
text=File.read(file)
|
31
32
|
opts={
|
32
33
|
:requires => Dir.glob("#{test_dir}/#{test_name}#{EXTENSIONS[:requires]}"),
|
@@ -46,7 +47,7 @@ def mk_test_context(file, test_case=nil)
|
|
46
47
|
tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
|
47
48
|
test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m|
|
48
49
|
expected, actual=[$2,$1]
|
49
|
-
#
|
50
|
+
#assert_equal cannot take a hash as its first argument
|
50
51
|
expected.sub!(/^\{(.*)\}\s*$/) {|m| "Hash[#{$1}]"}
|
51
52
|
"assert_equal #{expected}, #{actual}"
|
52
53
|
}
|
data/lib/rdoc/discover
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class RDoc::Parser::Tdoc < RDoc::Parser::Simple
|
2
|
+
LINST='^[#|\s]*'
|
3
|
+
LINSTM='[#|\s]*'
|
4
|
+
parse_files_matching(/\.rdoc/)
|
5
|
+
def initialize(top_level, file_name, content, options, stats)
|
6
|
+
super
|
7
|
+
@content=process_includes(file_name)
|
8
|
+
end
|
9
|
+
def process_includes(file_name)
|
10
|
+
content=File.read(file_name)
|
11
|
+
test_name=File.basename(file_name,'.rdoc')
|
12
|
+
test_dir=File.dirname(file_name)
|
13
|
+
content.gsub!(/(#{LINST}):include:\s*(.+)/) {|foo| indent=$1;process_includes($2).sub(/^/,indent)}
|
14
|
+
content.sub!(/(#{LINST})setup\s+(.*?)#{LINSTM}end\s+/m) {|foo|
|
15
|
+
indent=$1
|
16
|
+
"The following code: \n#{$2.gsub(/^/,indent+' ')}\nprecedes each of the following examples.\n\n"
|
17
|
+
}
|
18
|
+
Dir.glob("#{test_dir}/#{test_name}.rb").each do |fn|
|
19
|
+
tests=content.split(/#{LINST}[Ee]xamples?:/,2)
|
20
|
+
content="#{tests[0]}\nThe following examples require the file '#{fn}', whose contents follow:\n#{process_includes(fn).gsub(/^/,' ')}\nExamples: #{tests[1]}"
|
21
|
+
end
|
22
|
+
Dir.glob("#{test_dir}/#{test_name}/*.rdoc").each do |fn|
|
23
|
+
content+="\n#{process_includes(fn)}\n"
|
24
|
+
end
|
25
|
+
content
|
26
|
+
end
|
27
|
+
end
|
data/rdoc/example.rb
ADDED
data/rdoc/example.rdoc
CHANGED
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.
|
4
|
+
version: 0.11.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-
|
12
|
+
date: 2011-11-30 00:00:00 -03:00
|
13
13
|
default_executable: tdoc.rb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,10 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- README.rdoc
|
35
35
|
- bin/tdoc.rb
|
36
|
+
- rdoc/example.rb
|
36
37
|
- rdoc/example.rdoc
|
38
|
+
- lib/rdoc/parsers/tdoc.rb
|
39
|
+
- lib/rdoc/discover
|
37
40
|
has_rdoc: true
|
38
41
|
homepage: http://github.com/herbdaily/tdoc
|
39
42
|
licenses: []
|