tdoc 0.9.0 → 0.10.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 +11 -14
  2. 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| l.match(/#{LINST}(assert.+)/) && $1}.compact.join ";\n"
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.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
80
+ test_case.module_eval {mk_test_context(file).call}
84
81
  else
85
82
  context_proc
86
83
  end
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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herb Daily