docspec 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -7
- data/bin/docspec +10 -22
- data/lib/docspec/cli.rb +71 -0
- data/lib/docspec/example.rb +1 -1
- data/lib/docspec/output_capturer.rb +2 -0
- data/lib/docspec/version.rb +1 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330b6b64b2112f4c04771bb41f1d2baaba6040a8154f8d8d21538792c9e5531a
|
4
|
+
data.tar.gz: 59df2785073b757fe4d444ab143632fa853d64f685fd9f59f967db6e338ef6d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 760aa463ba9ca213098e0dcd54b087e8f394d367ba25e19c5971fdc60db69849b2a45c50a2df4d2ff97464e34ed302ef18cb485cea52873fa7c0a7b4661d8fda
|
7
|
+
data.tar.gz: 8e7010b439685d276d166e1906eaacc652b2e4bcb30bb612f0d00618b5de9c9da3bb927687f72e5c1b4992be4963c9e3b935613049e408f36940808909b44b39
|
data/README.md
CHANGED
@@ -17,6 +17,12 @@ Installation
|
|
17
17
|
$ gem install docspec
|
18
18
|
|
19
19
|
|
20
|
+
Demo
|
21
|
+
--------------------------------------------------
|
22
|
+
|
23
|
+
![Demo](demo/cast.svg)
|
24
|
+
|
25
|
+
|
20
26
|
Usage
|
21
27
|
--------------------------------------------------
|
22
28
|
|
@@ -36,20 +42,20 @@ look at its source.
|
|
36
42
|
|
37
43
|
### Testing with the `docspec` command line
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
- Running `docspec` without arguments will run on `./README.md`
|
46
|
+
- Running `docspec` with a filename, will run on that filename
|
47
|
+
- Running `docspec` with a directory, will run on all the markdown files in
|
48
|
+
that directory.
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
$ docspec TESTS.md
|
50
|
+
If your bundle includes the `simplecov` gem, it will be automatically loaded
|
51
|
+
and generate coverage report in the `coverage` directory.
|
46
52
|
|
47
53
|
|
48
54
|
### Testing from Ruby code
|
49
55
|
|
50
56
|
```ruby
|
51
57
|
# Running from Ruby code
|
52
|
-
document = Docspec::Document.from_file 'sample.md'
|
58
|
+
document = Docspec::Document.from_file 'test/sample.md'
|
53
59
|
document.test
|
54
60
|
#=> pass : Sample Test
|
55
61
|
|
@@ -58,6 +64,33 @@ puts document.success?
|
|
58
64
|
```
|
59
65
|
|
60
66
|
|
67
|
+
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Test a file using the CLI class
|
71
|
+
runner = Docspec::CLI.new 'test/sample.md'
|
72
|
+
success = runner.run
|
73
|
+
#=> pass : Sample Test
|
74
|
+
#=>
|
75
|
+
#=> 1 tests, 0 failed
|
76
|
+
```
|
77
|
+
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# Test a folder using the CLI class
|
81
|
+
runner = Docspec::CLI.new 'test'
|
82
|
+
success = runner.run
|
83
|
+
#=> file : test/folder/another.md
|
84
|
+
#=> pass : Another Sample Test
|
85
|
+
#=>
|
86
|
+
#=> file : test/sample.md
|
87
|
+
#=> pass : Sample Test
|
88
|
+
#=>
|
89
|
+
#=> 2 tests, 0 failed
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
|
61
94
|
Examples
|
62
95
|
--------------------------------------------------
|
63
96
|
|
data/bin/docspec
CHANGED
@@ -1,27 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
if Gem.loaded_specs.has_key?('simplecov') and !ENV['DISABLE_SIMPLECOV']
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.configure do
|
5
|
+
command_name ENV['SIMPLECOV_COMMAND'] || 'Docspec'
|
6
|
+
end
|
7
|
+
SimpleCov.start
|
5
8
|
end
|
6
|
-
SimpleCov.start
|
7
9
|
|
8
10
|
require 'docspec'
|
9
|
-
require '
|
10
|
-
include Colsole
|
11
|
-
|
12
|
-
document = ARGV[0] || 'README.md'
|
13
|
-
abort "File not found #{document}" unless File.exist? document
|
14
|
-
document = Docspec::Document.from_file document
|
15
|
-
document.test
|
16
|
-
|
17
|
-
say ''
|
18
|
-
|
19
|
-
if document.success?
|
20
|
-
say "!txtgrn!#{document.examples.count} tests, #{document.failed_examples.count} failed\n"
|
21
|
-
exit 0
|
22
|
-
else
|
23
|
-
say "!txtred!#{document.examples.count} tests, #{document.failed_examples.count} failed\n"
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
11
|
+
require 'docspec/cli'
|
27
12
|
|
13
|
+
runner = Docspec::CLI.new ARGV[0]
|
14
|
+
success = runner.run
|
15
|
+
exit success ? 0 : 1
|
data/lib/docspec/cli.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'colsole'
|
2
|
+
include Colsole
|
3
|
+
|
4
|
+
module Docspec
|
5
|
+
class CLI
|
6
|
+
attr_reader :target, :exit_code, :total_examples, :failed_examples
|
7
|
+
|
8
|
+
def initialize(target=nil)
|
9
|
+
@target = target || 'README.md'
|
10
|
+
end
|
11
|
+
|
12
|
+
def mode
|
13
|
+
File.directory?(target) ? :dir : :file
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
abort "Target not found: #{target}" unless File.exist? target
|
18
|
+
|
19
|
+
@exit_code = 0
|
20
|
+
@total_examples = 0
|
21
|
+
@failed_examples = 0
|
22
|
+
|
23
|
+
if mode == :dir
|
24
|
+
run_dir
|
25
|
+
else
|
26
|
+
run_file target
|
27
|
+
end
|
28
|
+
|
29
|
+
show_footer
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def run_dir
|
35
|
+
all_success = true
|
36
|
+
Dir["#{target}/**/*.md"].each do |file|
|
37
|
+
say ''
|
38
|
+
say "!txtcyn!file : #{file}"
|
39
|
+
success = run_file file
|
40
|
+
all_success = false unless success
|
41
|
+
end
|
42
|
+
all_success
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_file(file)
|
46
|
+
document = Docspec::Document.from_file file
|
47
|
+
document.test
|
48
|
+
|
49
|
+
@failed_examples += document.failed_examples.count
|
50
|
+
@total_examples += document.examples.count
|
51
|
+
|
52
|
+
document.success?
|
53
|
+
end
|
54
|
+
|
55
|
+
def show_footer
|
56
|
+
say ''
|
57
|
+
|
58
|
+
if failed_examples == 0
|
59
|
+
say "!txtgrn!#{total_examples} tests, #{failed_examples} failed\n"
|
60
|
+
true
|
61
|
+
else
|
62
|
+
say "!txtred!#{total_examples} tests, #{failed_examples} failed\n"
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
data/lib/docspec/example.rb
CHANGED
data/lib/docspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
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: 2019-
|
11
|
+
date: 2019-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.3'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: simplecov
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.17'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.17'
|
55
41
|
description: Make your READMEs testable
|
56
42
|
email: db@dannyben.com
|
57
43
|
executables:
|
@@ -62,6 +48,7 @@ files:
|
|
62
48
|
- README.md
|
63
49
|
- bin/docspec
|
64
50
|
- lib/docspec.rb
|
51
|
+
- lib/docspec/cli.rb
|
65
52
|
- lib/docspec/document.rb
|
66
53
|
- lib/docspec/example.rb
|
67
54
|
- lib/docspec/output_capturer.rb
|
@@ -86,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
73
|
- !ruby/object:Gem::Version
|
87
74
|
version: '0'
|
88
75
|
requirements: []
|
89
|
-
rubygems_version: 3.0.
|
76
|
+
rubygems_version: 3.0.3
|
90
77
|
signing_key:
|
91
78
|
specification_version: 4
|
92
79
|
summary: Embedded tests in Markdown documents
|