tdoc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +14 -2
  2. data/bin/tdoc.rb +12 -13
  3. metadata +1 -1
data/README.rdoc CHANGED
@@ -12,13 +12,25 @@ Tdoc combines rdoc, test::unit and shoulda, and concepts from rubytestdoc.
12
12
  - tdoc_context
13
13
  - tdoc_setup
14
14
  - examples
15
+ - within each examples block, Tdoc will convert cut and pastes from irb into assert_equal blocks, so
16
+ >> "asdf"
17
+ => "asdf"
18
+ turns into:
19
+ assert_equal "asdf","asdf"
20
+ Tdoc will then include all assertions within the context created from the example block
15
21
 
16
22
  tdoc_require: rubygems
17
23
 
18
- examples:
24
+ examples: simple irb with 1 assertion
19
25
 
20
26
  >> "asdf"
21
- -> "asdf"
27
+ => "asdf"
28
+ >> x="foo"
29
+ => "foo"
30
+ >> x
31
+ => "foo"
32
+ assert_raise ZeroDivisionError do; 1/0 ;end
33
+
22
34
 
23
35
  usage:
24
36
 
data/bin/tdoc.rb CHANGED
@@ -18,20 +18,19 @@ def mk_context(file,test_case=nil)
18
18
  directives=text.scan(/#{LINST}tdoc_(.+?):\s*(.+)/).inject({}) {|h,d| h[d[0].to_sym]||=[];h[d[0].to_sym] << d[1];h}
19
19
  directives[:require].to_a.each {|r| require r}
20
20
  directives[:context].to_a.each {|c| mk_context "#{TEST_DIR}#{c}", test_case}
21
- tests=text.split(/#{LINST}[Ee]xamples:/).to_a[1..-1].to_a.map do |test|
22
- [test.split(/\n/)[0], test.scan(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) ]
21
+ tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
22
+ test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m| "assert_equal #{$1}, #{$2}"}
23
+ lines=test.split(/\n/)
24
+ test_text=lines.map {|l| l.match(/#{LINST}(assert.+)/) && $1}.compact.join ";"
25
+ [lines[0], test_text]
23
26
  end
24
- test_case.class_eval do
25
- context test_name do
26
- setup do
27
- eval directives[:setup].to_a.join ';'
28
- end
29
- tests.each do |test|
30
- should test[0] do
31
- test[1].each do |assertion|
32
- assert_equal eval(assertion[0]), eval(assertion[1])
33
- end
34
- end
27
+ test_case.context test_name do
28
+ setup do
29
+ eval directives[:setup].to_a.join ';'
30
+ end
31
+ tests.each do |test|
32
+ should test[0] do
33
+ eval test[1]
35
34
  end
36
35
  end
37
36
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herb Daily