docu 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/lib/docu/executes_examples.rb +8 -4
- data/lib/docu/version.rb +1 -1
- data/spec/docu/executes_examples_spec.rb +23 -3
- metadata +4 -4
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Docu
|
2
2
|
class ExecutesExamples
|
3
|
-
def initialize output
|
3
|
+
def initialize output, kernel = Kernel
|
4
4
|
@output = output
|
5
|
+
@kernel = kernel
|
5
6
|
end
|
6
7
|
|
7
8
|
def execute path
|
@@ -10,10 +11,12 @@ module Docu
|
|
10
11
|
successes = 0
|
11
12
|
|
12
13
|
contents = File.read(path)
|
14
|
+
|
13
15
|
contents.scan(/:example:((?:(?!^:end:).)*)/m).flatten.each do |example|
|
14
|
-
if example
|
15
|
-
|
16
|
-
|
16
|
+
if example =~ /#\s*=>\s*(.+)/
|
17
|
+
expected = $1
|
18
|
+
actual = eval(example).inspect
|
19
|
+
|
17
20
|
if actual == expected
|
18
21
|
successes += 1
|
19
22
|
else
|
@@ -28,6 +31,7 @@ module Docu
|
|
28
31
|
errors.each do |error|
|
29
32
|
@output.puts error
|
30
33
|
end
|
34
|
+
@kernel.exit 1
|
31
35
|
else
|
32
36
|
File.open(path.chomp(File.extname(path)), "w") do |file|
|
33
37
|
file.write contents.gsub(":example:\n", "").gsub(":end:\n", "")
|
data/lib/docu/version.rb
CHANGED
@@ -16,18 +16,29 @@ module Docu
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
class SpyKernel
|
20
|
+
attr_accessor :exit_status
|
21
|
+
def exit status
|
22
|
+
@exit_status = status
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
describe ExecutesExamples do
|
20
27
|
after do
|
21
28
|
File.delete("TEST_README.md") if File.exist?("TEST_README.md")
|
22
29
|
File.delete("TEST_README.md.docu") if File.exist?("TEST_README.md.docu")
|
23
30
|
end
|
24
31
|
|
32
|
+
let :kernel do
|
33
|
+
SpyKernel.new
|
34
|
+
end
|
35
|
+
|
25
36
|
it "writes out some text" do
|
26
37
|
output_spy = OutputSpy.new
|
27
38
|
File.open("TEST_README.md.docu", "w") do |file|
|
28
39
|
file.puts
|
29
40
|
end
|
30
|
-
Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
|
41
|
+
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
31
42
|
output_spy.output.must_include "Executing Examples"
|
32
43
|
end
|
33
44
|
|
@@ -48,19 +59,28 @@ module Docu
|
|
48
59
|
|
49
60
|
it "mentions failure and success" do
|
50
61
|
output_spy = OutputSpy.new
|
51
|
-
Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
|
62
|
+
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
52
63
|
output_spy.output.must_include "1 example(s) failed, 1 example(s) passed"
|
53
64
|
end
|
54
65
|
|
55
66
|
it "outputs errors" do
|
56
67
|
output_spy = OutputSpy.new
|
57
|
-
Docu::ExecutesExamples.new(output_spy).execute("TEST_README.md.docu")
|
68
|
+
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
58
69
|
output_spy.output.must_include "Assertion does not match example. Expected \"2\" to equal \"23\""
|
59
70
|
end
|
60
71
|
|
61
72
|
it "does not write the file" do
|
73
|
+
output_spy = OutputSpy.new
|
74
|
+
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
62
75
|
File.exist?("TEST_README.md").must_equal false
|
63
76
|
end
|
77
|
+
|
78
|
+
it "exits with non-zero exit status" do
|
79
|
+
output_spy = OutputSpy.new
|
80
|
+
executes_examples = Docu::ExecutesExamples.new(output_spy, kernel)
|
81
|
+
Docu::ExecutesExamples.new(output_spy, kernel).execute("TEST_README.md.docu")
|
82
|
+
kernel.exit_status.must_equal 1
|
83
|
+
end
|
64
84
|
end
|
65
85
|
|
66
86
|
describe "one passing example" do
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
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: &70235153514700 !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: *70235153514700
|
25
25
|
description: ''
|
26
26
|
email:
|
27
27
|
- andrew.vos@gmail.com
|