tdoc 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tdoc.rb +35 -15
- metadata +2 -2
data/bin/tdoc.rb
CHANGED
@@ -15,16 +15,15 @@ def process(file) #called at end of script
|
|
15
15
|
if files.count > 1
|
16
16
|
files.each {|f| system("#{$PROGRAM_NAME} #{f} #{ARGV}")}
|
17
17
|
else
|
18
|
-
|
18
|
+
test_name=File.basename(file).sub(/\..*?$/,'')
|
19
|
+
test_case=Class.new(Test::Unit::TestCase)
|
20
|
+
Object.const_set(:"Test#{test_name.capitalize}", test_case)
|
21
|
+
mk_test_context(files[0], test_case)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
def mk_test_context(file, test_case=nil)
|
22
25
|
test_name=File.basename(file).sub(/\..*?$/,'')
|
23
26
|
test_dir=File.dirname(file)
|
24
|
-
unless test_case
|
25
|
-
test_case=Class.new(Test::Unit::TestCase)
|
26
|
-
Object.const_set(:"Test#{test_name.capitalize}", test_case)
|
27
|
-
end
|
28
27
|
text=File.read(file)
|
29
28
|
opts={
|
30
29
|
:requires => Dir.glob("#{test_dir}/#{test_name}#{EXTENSIONS[:requires]}"),
|
@@ -40,7 +39,7 @@ def mk_test_context(file, test_case=nil)
|
|
40
39
|
end
|
41
40
|
opts[:requires].each {|r| require "#{r}" if FileTest.exist? "#{r}" }
|
42
41
|
opts[:test_cases].delete_if {|c| c.match(/#{test_name}/)}
|
43
|
-
|
42
|
+
setup_text=text.match(/#{LINSTM}setup\s+(.*?)#{LINSTM}end\s+/m).to_a[1]
|
44
43
|
tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
|
45
44
|
test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m|
|
46
45
|
expected, actual=[$2,$1]
|
@@ -52,17 +51,38 @@ def mk_test_context(file, test_case=nil)
|
|
52
51
|
test_text=lines.map {|l| l.match(/#{LINST}(assert.+)/) && $1}.compact.join ";\n"
|
53
52
|
[lines[0], test_text]
|
54
53
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
54
|
+
context_proc=lambda {
|
55
|
+
context test_name do
|
56
|
+
setup do
|
57
|
+
eval setup_text.to_a.join ';'
|
58
|
+
end
|
59
|
+
tests.each do |test|
|
60
|
+
should test[0] do
|
61
|
+
eval test[1]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
opts[:contexts].compact.each do |c|
|
65
|
+
mk_test_context(c).call
|
62
66
|
end
|
63
67
|
end
|
64
|
-
|
65
|
-
opts[:contexts].compact.each {|c| mk_test_context "#{c}", test_case}
|
68
|
+
}
|
66
69
|
opts[:test_cases].each {|c| process(c)}
|
70
|
+
if test_case
|
71
|
+
test_case.context test_name do
|
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
|
84
|
+
else
|
85
|
+
context_proc
|
86
|
+
end
|
67
87
|
end
|
68
88
|
process(ARGV.shift || DEFAULT_FILE)
|
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.9.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-29 00:00:00 -03:00
|
13
13
|
default_executable: tdoc.rb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|