tdoc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +28 -0
  2. data/bin/tdoc.rb +46 -0
  3. metadata +65 -0
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+
2
+ =Tdoc
3
+
4
+ == Test oriented documentation
5
+
6
+ Tdoc combines rdoc, test::unit and shoulda, and concepts from rubytestdoc.
7
+
8
+ - Tdoc files (default extention: .tdoc) map to Test::Unit::TestCase classes with a single context
9
+ - Tdoc directives take up 1 line, with the exception of the "examples" directive. They may be preceded by any number of whitespace characters and terminate with a colon.
10
+ - Tdoc understands the following directives:
11
+ - tdoc_require
12
+ - tdoc_context
13
+ - tdoc_setup
14
+ - examples
15
+
16
+ tdoc_require: rubygems
17
+
18
+ examples:
19
+
20
+ >> "asdf"
21
+ -> "asdf"
22
+
23
+ usage:
24
+
25
+ tdoc [test_directory] [extention]
26
+
27
+
28
+
data/bin/tdoc.rb ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'test/unit'
4
+ require 'shoulda'
5
+
6
+ $: << 'lib'
7
+
8
+ TEST_DIR=ARGV[0] || 'tdoc/'
9
+ EXTENTION=ARGV[1] || '.tdoc'
10
+ LINST='^[#|\s]*'
11
+
12
+ def mk_context(file,test_case=nil)
13
+ test_name=File.basename(file).sub(EXTENTION,'')
14
+ unless test_case
15
+ test_case=eval "::Test#{test_name.capitalize}=Class.new(Test::Unit::TestCase)"
16
+ end
17
+ text=File.read(file)
18
+ directives=text.scan(/#{LINST}tdoc_(.+?):\s*(.+)/).inject({}) {|h,d| h[d[0].to_sym]||=[];h[d[0].to_sym] << d[1];h}
19
+ directives[:require].to_a.each {|r| require r}
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*(.+)/) ]
23
+ 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
35
+ end
36
+ end
37
+ end
38
+ end
39
+ def mk_tests(test_dir)
40
+ files=Dir.glob("#{test_dir}*#{EXTENTION}")
41
+ files.each { |file| mk_context(file)}
42
+ end
43
+ mk_tests(TEST_DIR)
44
+
45
+
46
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tdoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Herb Daily
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-11-25 00:00:00 -03:00
13
+ default_executable: tdoc.rb
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.11.3
24
+ version:
25
+ description: "Combines Test::Unit, Shoulda, and Rdoc to embed tests inside documentation "
26
+ email: herb.daily@safe-mail.net
27
+ executables:
28
+ - tdoc.rb
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README.rdoc
35
+ - bin/tdoc.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/herbdaily/tdoc
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Test oriented documentation
64
+ test_files: []
65
+