docspec 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -19
- data/bin/docspec +1 -1
- data/lib/docspec/cli.rb +8 -12
- data/lib/docspec/document.rb +2 -3
- data/lib/docspec/example.rb +5 -3
- data/lib/docspec/testable.rb +6 -8
- data/lib/docspec/version.rb +2 -2
- metadata +16 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8a5c9b5152aec40381604f7b29473d9df865cba3cd650cd1b70dda2115e9165
|
4
|
+
data.tar.gz: 618428c8f9733ee701f6e2fb4babd5c1da39e85c0db601ae8b0f07e9f942e864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a2eacb5a463a059419863bf58676146b73e9398c5ec94563e444525865764bf2ba1814bc4cdb9980983a1314d7c8951c3be0b23f7cb3a6a4b7e312d46761164
|
7
|
+
data.tar.gz: 5de5e31541b08ba45594da601462db482b6c677eae357026b75678fb0d50dbaad861f4e86e339f2dbcdd5760fc13ae22f47d4577e39e604be83e971ef598e75a
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
Docspec
|
2
|
-
==================================================
|
1
|
+
# Docspec
|
3
2
|
|
4
3
|
[![Gem Version](https://badge.fury.io/rb/docspec.svg)](https://badge.fury.io/rb/docspec)
|
5
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/DannyBen/docspec/workflows/Test/badge.svg)](https://github.com/DannyBen/docspec/actions?query=workflow%3ATest)
|
6
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/e0c15c1f33fa4aa45f70/maintainability)](https://codeclimate.com/github/DannyBen/docspec/maintainability)
|
7
6
|
|
8
7
|
Docspec lets you reuse your Markdown documents as the unit tests for your
|
@@ -11,30 +10,29 @@ Ruby library.
|
|
11
10
|
---
|
12
11
|
|
13
12
|
|
14
|
-
Installation
|
15
|
-
--------------------------------------------------
|
13
|
+
## Installation
|
16
14
|
|
17
|
-
|
15
|
+
```
|
16
|
+
$ gem install docspec
|
17
|
+
```
|
18
18
|
|
19
19
|
|
20
|
-
Demo
|
21
|
-
--------------------------------------------------
|
20
|
+
## Demo
|
22
21
|
|
23
|
-
![Demo](demo/cast.
|
22
|
+
![Demo](demo/cast.gif)
|
24
23
|
|
25
24
|
|
26
|
-
Usage
|
27
|
-
--------------------------------------------------
|
25
|
+
## Usage
|
28
26
|
|
29
27
|
Docspec expects one or more Markdown files with embedded code snippets to
|
30
28
|
test.
|
31
29
|
|
32
30
|
Code snippets should be enclosed in a `ruby` or `shell` code fence:
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
```ruby
|
33
|
+
puts "code to test (should output something)"
|
34
|
+
#=> code to test (should output something)
|
35
|
+
```
|
38
36
|
|
39
37
|
This document itself serves as the test suite for this gem, so you can take a
|
40
38
|
look at its source.
|
@@ -86,13 +84,19 @@ success = runner.run
|
|
86
84
|
#=> file : test/sample.md
|
87
85
|
#=> pass : Sample Test
|
88
86
|
#=>
|
89
|
-
#=>
|
87
|
+
#=> file : test/sample2.md
|
88
|
+
#=> pass : echo shell
|
89
|
+
#=> void : echo shell
|
90
|
+
#=> pass : puts "ruby"
|
91
|
+
#=> void : puts "ruby"
|
92
|
+
#=>
|
93
|
+
#=> 6 tests, 0 failed
|
94
|
+
|
90
95
|
```
|
91
96
|
|
92
97
|
|
93
98
|
|
94
|
-
Examples
|
95
|
-
--------------------------------------------------
|
99
|
+
## Examples
|
96
100
|
|
97
101
|
Code examples that you want to test, should output something to stdout.
|
98
102
|
Specify the expected output by prefixing it with `#=>`:
|
@@ -211,4 +215,3 @@ SOME_ENV_VAR=yes
|
|
211
215
|
echo $SOME_ENV_VAR
|
212
216
|
#=> yes
|
213
217
|
```
|
214
|
-
|
data/bin/docspec
CHANGED
data/lib/docspec/cli.rb
CHANGED
@@ -5,7 +5,7 @@ module Docspec
|
|
5
5
|
class CLI
|
6
6
|
attr_reader :target, :exit_code, :total_examples, :failed_examples
|
7
7
|
|
8
|
-
def initialize(target=nil)
|
8
|
+
def initialize(target = nil)
|
9
9
|
@target = target || 'README.md'
|
10
10
|
end
|
11
11
|
|
@@ -33,9 +33,9 @@ module Docspec
|
|
33
33
|
|
34
34
|
def run_dir
|
35
35
|
all_success = true
|
36
|
-
Dir["#{target}/**/*.md"].each do |file|
|
36
|
+
Dir["#{target}/**/*.md"].sort.each do |file|
|
37
37
|
say ''
|
38
|
-
say "
|
38
|
+
say "c`file : #{file}`"
|
39
39
|
success = run_file file
|
40
40
|
all_success = false unless success
|
41
41
|
end
|
@@ -45,27 +45,23 @@ module Docspec
|
|
45
45
|
def run_file(file)
|
46
46
|
document = Docspec::Document.from_file file
|
47
47
|
document.test
|
48
|
-
|
48
|
+
|
49
49
|
@failed_examples += document.failed_examples.count
|
50
50
|
@total_examples += document.examples.count
|
51
|
-
|
51
|
+
|
52
52
|
document.success?
|
53
53
|
end
|
54
54
|
|
55
55
|
def show_footer
|
56
56
|
say ''
|
57
57
|
|
58
|
-
if failed_examples
|
59
|
-
say "
|
58
|
+
if failed_examples.zero?
|
59
|
+
say "g`#{total_examples} tests, #{failed_examples} failed`\n"
|
60
60
|
true
|
61
61
|
else
|
62
|
-
say "
|
62
|
+
say "r`#{total_examples} tests, #{failed_examples} failed`\n"
|
63
63
|
false
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
66
|
end
|
68
67
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
data/lib/docspec/document.rb
CHANGED
@@ -25,16 +25,15 @@ module Docspec
|
|
25
25
|
result = []
|
26
26
|
markdown.scan(/```(ruby|shell)\s*\n(.*?)```/m) do |type, code|
|
27
27
|
example = Example.new(type: type, code: code, before: before[type])
|
28
|
-
|
28
|
+
|
29
29
|
next if example.skip?
|
30
30
|
|
31
31
|
before[type] ||= []
|
32
32
|
before[type] << example.code if example.empty?
|
33
|
-
|
33
|
+
|
34
34
|
result << example
|
35
35
|
end
|
36
36
|
result
|
37
37
|
end
|
38
|
-
|
39
38
|
end
|
40
39
|
end
|
data/lib/docspec/example.rb
CHANGED
@@ -6,7 +6,9 @@ module Docspec
|
|
6
6
|
attr_reader :code, :type, :before
|
7
7
|
|
8
8
|
def initialize(type:, code:, before: nil)
|
9
|
-
@code
|
9
|
+
@code = code
|
10
|
+
@type = type
|
11
|
+
@before = before
|
10
12
|
end
|
11
13
|
|
12
14
|
def actual
|
@@ -30,7 +32,7 @@ module Docspec
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def failed?
|
33
|
-
!success?
|
35
|
+
!success? && !empty?
|
34
36
|
end
|
35
37
|
|
36
38
|
def first_line
|
@@ -76,12 +78,12 @@ module Docspec
|
|
76
78
|
|
77
79
|
def full_code!
|
78
80
|
return code unless before
|
81
|
+
|
79
82
|
[before.join("\n\n"), code].join "\n"
|
80
83
|
end
|
81
84
|
|
82
85
|
def label!
|
83
86
|
first_line.gsub(/^#\s*/, '').strip
|
84
87
|
end
|
85
|
-
|
86
88
|
end
|
87
89
|
end
|
data/lib/docspec/testable.rb
CHANGED
@@ -5,7 +5,7 @@ module Docspec
|
|
5
5
|
include Colsole
|
6
6
|
|
7
7
|
def success?
|
8
|
-
failed_examples.count
|
8
|
+
failed_examples.count.zero?
|
9
9
|
end
|
10
10
|
|
11
11
|
def failed_examples
|
@@ -15,18 +15,16 @@ module Docspec
|
|
15
15
|
def test
|
16
16
|
examples.each do |example|
|
17
17
|
if example.empty?
|
18
|
-
say "
|
18
|
+
say "m`void :` #{example.label}"
|
19
19
|
elsif example.success?
|
20
|
-
say "
|
20
|
+
say "g`pass :` #{example.label}"
|
21
21
|
else
|
22
|
-
say "
|
23
|
-
say
|
22
|
+
say "r`FAIL : #{example.label}`"
|
23
|
+
say '---'
|
24
24
|
puts example.diff
|
25
|
-
say
|
25
|
+
say '---'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
29
|
end
|
31
30
|
end
|
32
|
-
|
data/lib/docspec/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Docspec
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.1.3'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.1
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
22
|
+
version: '2.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.1
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: diffy
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,7 +63,8 @@ files:
|
|
57
63
|
homepage: https://github.com/dannyben/docspec
|
58
64
|
licenses:
|
59
65
|
- MIT
|
60
|
-
metadata:
|
66
|
+
metadata:
|
67
|
+
rubygems_mfa_required: 'true'
|
61
68
|
post_install_message:
|
62
69
|
rdoc_options: []
|
63
70
|
require_paths:
|
@@ -66,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
73
|
requirements:
|
67
74
|
- - ">="
|
68
75
|
- !ruby/object:Gem::Version
|
69
|
-
version: 2.
|
76
|
+
version: '2.7'
|
70
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
78
|
requirements:
|
72
79
|
- - ">="
|
73
80
|
- !ruby/object:Gem::Version
|
74
81
|
version: '0'
|
75
82
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.4.8
|
77
84
|
signing_key:
|
78
85
|
specification_version: 4
|
79
86
|
summary: Embedded tests in Markdown documents
|