tdoc 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tdoc.rb +11 -14
- metadata +1 -1
data/bin/tdoc.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'test/unit'
|
4
4
|
require 'shoulda'
|
5
|
+
require 'irb'
|
5
6
|
|
6
7
|
$: << 'lib'
|
7
8
|
|
@@ -10,6 +11,8 @@ LINSTM='[#|\s]*'
|
|
10
11
|
EXTENSIONS={:tests => '.rdoc',:requires => '.rb'}
|
11
12
|
DEFAULT_FILE="README#{EXTENSIONS[:tests]}"
|
12
13
|
|
14
|
+
START_IRB="IRB.setup nil; IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context; require 'irb/ext/multi-irb'; IRB.irb nil, self"
|
15
|
+
|
13
16
|
def process(file) #called at end of script
|
14
17
|
files=Dir.glob(file)
|
15
18
|
if files.count > 1
|
@@ -48,7 +51,13 @@ def mk_test_context(file, test_case=nil)
|
|
48
51
|
"assert_equal #{expected}, #{actual}"
|
49
52
|
}
|
50
53
|
lines=test.split(/\n/)
|
51
|
-
test_text=lines.map {|l|
|
54
|
+
test_text=lines.map {|l|
|
55
|
+
if l.match(/#{LINST}!!!/)
|
56
|
+
START_IRB
|
57
|
+
else
|
58
|
+
l.match(/#{LINST}(assert.+)/) && $1
|
59
|
+
end
|
60
|
+
}.compact.join ";\n"
|
52
61
|
[lines[0], test_text]
|
53
62
|
end
|
54
63
|
context_proc=lambda {
|
@@ -68,19 +77,7 @@ def mk_test_context(file, test_case=nil)
|
|
68
77
|
}
|
69
78
|
opts[:test_cases].each {|c| process(c)}
|
70
79
|
if test_case
|
71
|
-
test_case.
|
72
|
-
setup do
|
73
|
-
eval setup_text.to_a.join ';'
|
74
|
-
end
|
75
|
-
tests.each do |test|
|
76
|
-
should test[0] do
|
77
|
-
eval test[1]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
opts[:contexts].compact.each do |c|
|
81
|
-
mk_test_context(c).call
|
82
|
-
end
|
83
|
-
end
|
80
|
+
test_case.module_eval {mk_test_context(file).call}
|
84
81
|
else
|
85
82
|
context_proc
|
86
83
|
end
|