tdoc 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/tdoc.rb +14 -9
  2. metadata +1 -1
data/bin/tdoc.rb CHANGED
@@ -10,13 +10,13 @@ LINSTM='[#|\s]*'
10
10
  EXTENSIONS={:tests => '.rdoc',:requires => '.rb'}
11
11
  DEFAULT_FILE="README#{EXTENSIONS[:tests]}"
12
12
 
13
- def process(files=nil) #called at end of script
14
- files||=DEFAULT_FILE
15
- if files.class==Array
16
- files.each {|f|`#{$PROGRAM_NAME} #{f}`}
17
- else
18
- mk_test_context(files)
19
- end
13
+ def process(file) #called at end of script
14
+ files=Dir.glob(file)
15
+ if files.count > 1
16
+ files.each {|f| system("#{$PROGRAM_NAME} #{f}")}
17
+ else
18
+ mk_test_context(files[0])
19
+ end
20
20
  end
21
21
  def mk_test_context(file, test_case=nil)
22
22
  test_name=File.basename(file).sub(/\..*?$/,'')
@@ -42,7 +42,12 @@ def mk_test_context(file, test_case=nil)
42
42
  opts[:test_cases].delete_if {|c| c.match(/#{test_name}/)}
43
43
  opts[:setup]=text.match(/#{LINSTM}setup\s+(.*?)#{LINSTM}end\s+/m).to_a[1]
44
44
  tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
45
- test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m| "assert_equal #{$2}, #{$1}"}
45
+ test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m|
46
+ expected, actual=[$2,$1]
47
+ #assert equal cannot take a hash as its first argument
48
+ expected.sub!(/^\{(.*)\}\s*$/) {|m| "Hash[#{$1}]"}
49
+ "assert_equal #{expected}, #{actual}"
50
+ }
46
51
  lines=test.split(/\n/)
47
52
  test_text=lines.map {|l| l.match(/#{LINST}(assert.+)/) && $1}.compact.join ";\n"
48
53
  [lines[0], test_text]
@@ -60,4 +65,4 @@ def mk_test_context(file, test_case=nil)
60
65
  opts[:contexts].compact.each {|c| mk_test_context "#{c}", test_case}
61
66
  opts[:test_cases].each {|c| process(c)}
62
67
  end
63
- process(ARGV.shift)
68
+ 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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herb Daily