docu 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -0
- data/bin/docu +1 -1
- data/lib/docu/executes_examples.rb +4 -5
- data/lib/docu/rake/task.rb +24 -0
- data/lib/docu/version.rb +1 -1
- data/spec/docu/executes_examples_spec.rb +12 -21
- data/spec/docu/rake/task_spec.rb +41 -0
- metadata +6 -3
data/README.md
CHANGED
data/bin/docu
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module Docu
|
2
2
|
class ExecutesExamples
|
3
|
-
def initialize
|
4
|
-
@output = output
|
3
|
+
def initialize kernel = Kernel
|
5
4
|
@kernel = kernel
|
6
5
|
end
|
7
6
|
|
8
7
|
def execute path
|
9
|
-
@
|
8
|
+
@kernel.puts "Executing Examples"
|
10
9
|
errors = []
|
11
10
|
successes = 0
|
12
11
|
|
@@ -25,11 +24,11 @@ module Docu
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
@
|
27
|
+
@kernel.puts "#{errors.size} example(s) failed, #{successes} example(s) passed"
|
29
28
|
|
30
29
|
if errors.any?
|
31
30
|
errors.each do |error|
|
32
|
-
@
|
31
|
+
@kernel.puts error
|
33
32
|
end
|
34
33
|
@kernel.exit 1
|
35
34
|
else
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../../')
|
2
|
+
|
3
|
+
require "rake"
|
4
|
+
require "rake/tasklib"
|
5
|
+
require "docu"
|
6
|
+
|
7
|
+
module Docu
|
8
|
+
module Rake
|
9
|
+
class Task < ::Rake::TaskLib
|
10
|
+
include ::Rake::DSL if defined?(::Rake::DSL)
|
11
|
+
|
12
|
+
attr_accessor :name, :file
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
@name = args.shift || :docu
|
16
|
+
desc "Execute examples in documentation" unless ::Rake.application.last_comment
|
17
|
+
yield self if block_given?
|
18
|
+
task name do
|
19
|
+
ExecutesExamples.new.execute(file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/docu/version.rb
CHANGED
@@ -6,18 +6,16 @@ require "minitest/autorun"
|
|
6
6
|
require "minitest/spec"
|
7
7
|
|
8
8
|
module Docu
|
9
|
-
class
|
10
|
-
attr_accessor :output
|
9
|
+
class SpyKernel
|
10
|
+
attr_accessor :output, :exit_status
|
11
|
+
|
11
12
|
def puts(*a)
|
12
13
|
@output ||= []
|
13
14
|
a.each do |i|
|
14
15
|
@output << i
|
15
16
|
end
|
16
17
|
end
|
17
|
-
end
|
18
18
|
|
19
|
-
class SpyKernel
|
20
|
-
attr_accessor :exit_status
|
21
19
|
def exit status
|
22
20
|
@exit_status = status
|
23
21
|
end
|
@@ -34,12 +32,11 @@ module Docu
|
|
34
32
|
end
|
35
33
|
|
36
34
|
it "writes out some text" do
|
37
|
-
output_spy = OutputSpy.new
|
38
35
|
File.open("TEST_README.md.docu", "w") do |file|
|
39
36
|
file.puts
|
40
37
|
end
|
41
|
-
Docu::ExecutesExamples.new(
|
42
|
-
|
38
|
+
Docu::ExecutesExamples.new(kernel).execute("TEST_README.md.docu")
|
39
|
+
kernel.output.must_include "Executing Examples"
|
43
40
|
end
|
44
41
|
|
45
42
|
describe "one failing example and one passing example" do
|
@@ -58,27 +55,22 @@ module Docu
|
|
58
55
|
end
|
59
56
|
|
60
57
|
it "mentions failure and success" do
|
61
|
-
|
62
|
-
|
63
|
-
output_spy.output.must_include "1 example(s) failed, 1 example(s) passed"
|
58
|
+
Docu::ExecutesExamples.new(kernel).execute("TEST_README.md.docu")
|
59
|
+
kernel.output.must_include "1 example(s) failed, 1 example(s) passed"
|
64
60
|
end
|
65
61
|
|
66
62
|
it "outputs errors" do
|
67
|
-
|
68
|
-
|
69
|
-
output_spy.output.must_include "Assertion does not match example. Expected \"2\" to equal \"23\""
|
63
|
+
Docu::ExecutesExamples.new(kernel).execute("TEST_README.md.docu")
|
64
|
+
kernel.output.must_include "Assertion does not match example. Expected \"2\" to equal \"23\""
|
70
65
|
end
|
71
66
|
|
72
67
|
it "does not write the file" do
|
73
|
-
|
74
|
-
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
68
|
+
Docu::ExecutesExamples.new(kernel).execute("TEST_README.md.docu")
|
75
69
|
File.exist?("TEST_README.md").must_equal false
|
76
70
|
end
|
77
71
|
|
78
72
|
it "exits with non-zero exit status" do
|
79
|
-
|
80
|
-
executes_examples = Docu::ExecutesExamples.new(output_spy, kernel)
|
81
|
-
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
73
|
+
Docu::ExecutesExamples.new(kernel).execute("TEST_README.md.docu")
|
82
74
|
kernel.exit_status.must_equal 1
|
83
75
|
end
|
84
76
|
end
|
@@ -94,8 +86,7 @@ module Docu
|
|
94
86
|
end
|
95
87
|
|
96
88
|
it "writes out the file removing all :example: and :end: markers" do
|
97
|
-
|
98
|
-
Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
|
89
|
+
Docu::ExecutesExamples.new(kernel).execute("TEST_README.md.docu")
|
99
90
|
File.exist?("TEST_README.md").must_equal true
|
100
91
|
contents = File.read("TEST_README.md").to_s
|
101
92
|
contents.must_equal "1 + 1\n#=> 2\n"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../../lib")))
|
2
|
+
require "minitest/pride"
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "minitest/spec"
|
5
|
+
require "rake"
|
6
|
+
require "docu/rake/task"
|
7
|
+
|
8
|
+
module Docu
|
9
|
+
module Rake
|
10
|
+
describe Task do
|
11
|
+
before do
|
12
|
+
File.delete "TEST-README.md.docu" if File.exist? "TEST-README.md.docu"
|
13
|
+
File.delete "TEST-README.md" if File.exist? "TEST-README.md"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a default name" do
|
17
|
+
Task.new.name.must_equal :docu
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can have any name" do
|
21
|
+
Task.new(:execute_scripts).name.must_equal :execute_scripts
|
22
|
+
end
|
23
|
+
|
24
|
+
it "yields self" do
|
25
|
+
yielded_task = nil
|
26
|
+
task = Task.new do |t|
|
27
|
+
yielded_task = t
|
28
|
+
end
|
29
|
+
yielded_task.must_equal task
|
30
|
+
end
|
31
|
+
|
32
|
+
it "executes documentation" do
|
33
|
+
task = Task.new(:docu_test)
|
34
|
+
task.file = "TEST-README.md.docu"
|
35
|
+
File.open("TEST-README.md.docu", "w") { |f| f.write("example") }
|
36
|
+
::Rake::Task[:docu_test].invoke
|
37
|
+
File.exist?("TEST-README.md").must_equal true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-24 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70339569711840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70339569711840
|
25
25
|
description: ''
|
26
26
|
email:
|
27
27
|
- andrew.vos@gmail.com
|
@@ -40,8 +40,10 @@ files:
|
|
40
40
|
- docu.gemspec
|
41
41
|
- lib/docu.rb
|
42
42
|
- lib/docu/executes_examples.rb
|
43
|
+
- lib/docu/rake/task.rb
|
43
44
|
- lib/docu/version.rb
|
44
45
|
- spec/docu/executes_examples_spec.rb
|
46
|
+
- spec/docu/rake/task_spec.rb
|
45
47
|
homepage: ''
|
46
48
|
licenses: []
|
47
49
|
post_install_message:
|
@@ -68,3 +70,4 @@ specification_version: 3
|
|
68
70
|
summary: ''
|
69
71
|
test_files:
|
70
72
|
- spec/docu/executes_examples_spec.rb
|
73
|
+
- spec/docu/rake/task_spec.rb
|