doc_rspec 0.2.3 → 0.2.5
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.
- checksums.yaml +4 -4
- data/lib/doc_rspec/compiler.rb +16 -6
- data/lib/doc_rspec/debugging.rb +21 -0
- data/lib/doc_rspec/parser.rb +25 -20
- data/lib/doc_rspec/version.rb +1 -1
- data/lib/doc_rspec.rb +17 -0
- data/lib/enumerable.rb +12 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e2ea270de14b4a37fd648bde29d59a4f0a2244159d22a06e798c2387faa96f8
|
4
|
+
data.tar.gz: b3588a664c869b921e789c778be7508f8189628281d2c65796be3c3b31c1d060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a3129c0e172feaaae26d3d15cee20df6199d43d9d76676eab7b579038fbbd97c5f129fd4e72ac3ece19be2a4a01b260b60e255d765aa5f5b60478808ef2bfa
|
7
|
+
data.tar.gz: 31d6850d1534204007cf3953800c9d5a9f1cdf4e2f7e4450e93ca4dbfa44af7ea76fd8bf2e1fc03697f50a248c21eefe1f5d3d2693f76c30b9f564d18cbd59cc
|
data/lib/doc_rspec/compiler.rb
CHANGED
@@ -4,6 +4,7 @@ class DocRSpec
|
|
4
4
|
class Compiler
|
5
5
|
class IncorrectSpec < RuntimeError; end
|
6
6
|
|
7
|
+
include DocRSpec::Debugging
|
7
8
|
attr_reader :example_group, :path, :spec_definitions
|
8
9
|
|
9
10
|
def compile
|
@@ -30,13 +31,22 @@ class DocRSpec
|
|
30
31
|
def compile_example(example_spec)
|
31
32
|
# See comment above for an explanation why we capture
|
32
33
|
# this method as a function into a closure
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
code = example_spec
|
35
|
+
.lines
|
36
|
+
.join("\n")
|
37
|
+
return if code.empty?
|
38
|
+
|
39
|
+
example_name = example_spec.it_name(path)
|
40
|
+
if debug_level > 1
|
41
|
+
puts "Example: #{example_name}"
|
42
|
+
puts example_spec.lines.map { "> #{it}" }
|
43
|
+
puts "=" * 72
|
44
|
+
end
|
45
|
+
return if debug_level > 2
|
38
46
|
|
39
|
-
|
47
|
+
example_group.it example_name do
|
48
|
+
example = self
|
49
|
+
eval(code)
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DocRSpec
|
4
|
+
module Debugging
|
5
|
+
|
6
|
+
DEBUG_ENV_VAR_NAME = 'DEBUG_DOC_RSPEC'
|
7
|
+
def debug_level
|
8
|
+
@__debug_level__ ||=
|
9
|
+
case ENV[DEBUG_ENV_VAR_NAME]
|
10
|
+
in nil
|
11
|
+
0
|
12
|
+
in value
|
13
|
+
value.to_i.succ
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def debugging? = debug_level.positive?
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/doc_rspec/parser.rb
CHANGED
@@ -1,23 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'context'
|
4
|
+
require_relative '../enumerable'
|
4
5
|
|
5
6
|
class DocRSpec
|
6
7
|
class Parser
|
7
8
|
class InternalError < RuntimeError; end
|
8
9
|
class SyntaxError < RuntimeError; end
|
10
|
+
include DocRSpec::Debugging
|
9
11
|
|
10
|
-
|
12
|
+
COMMENT_LINE = %r{\A \s* \#}x
|
11
13
|
CONTEXT_DEFINITION = %r{\A \s* \# \s ={1,7} \s (.*)}x
|
12
14
|
|
13
15
|
EXAMPLE_LINE = %r{\A \s* \# \s{4,} (.*)}x
|
14
|
-
|
16
|
+
|
15
17
|
SHORT_EQUALS = %r{\s \=\=\> \s}x
|
16
18
|
SHORT_MATCHES = %r{\s \~\> \s}x
|
17
19
|
SHORT_PREDICATE = %r{\s is\! \s}x
|
18
20
|
SHORT_ANTIPREDICATE = %r{\s not\! \s}x
|
19
21
|
START_EXAMPLE = %r{\A \s* \# \s{4,} \# \s example: \s (.*)}x
|
20
22
|
|
23
|
+
SHORTCUTS = [
|
24
|
+
[ SHORT_EQUALS, "to", "eq(%%%)" ],
|
25
|
+
[ SHORT_MATCHES, "to", "match(%%%)" ],
|
26
|
+
[ SHORT_PREDICATE, "to", "be_%%%" ],
|
27
|
+
[ SHORT_ANTIPREDICATE, "not_to", "be_%%%" ],
|
28
|
+
]
|
29
|
+
|
21
30
|
attr_reader :ast, :lines, :state
|
22
31
|
|
23
32
|
def parse
|
@@ -53,31 +62,23 @@ class DocRSpec
|
|
53
62
|
code = match[1]
|
54
63
|
return if code.empty?
|
55
64
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
ast.last.add_example_line("expect(#{lhs}).to match(#{rhs})")
|
63
|
-
else
|
64
|
-
case code.split(SHORT_PREDICATE)
|
65
|
+
return if COMMENT_LINE === code
|
66
|
+
|
67
|
+
compiled =
|
68
|
+
SHORTCUTS.find_value(default: code) do |shtct_def|
|
69
|
+
shtct_def => [rgx, to_or_not, rhs_template]
|
70
|
+
case code.split(rgx)
|
65
71
|
in [lhs, rhs]
|
66
|
-
|
72
|
+
"expect(#{lhs}).#{to_or_not} #{rhs_template.sub("%%%", rhs)}"
|
67
73
|
else
|
68
|
-
|
69
|
-
in [lhs, rhs]
|
70
|
-
ast.last.add_example_line("expect(#{lhs}).not_to be_#{rhs}")
|
71
|
-
else
|
72
|
-
ast.last.add_example_line(code)
|
73
|
-
end
|
74
|
+
nil
|
74
75
|
end
|
75
76
|
end
|
76
|
-
|
77
|
+
ast.last.add_example_line(compiled)
|
77
78
|
end
|
78
79
|
|
79
80
|
def parse_line(line, lnb)
|
80
|
-
p(state:, lnb:, line:) if
|
81
|
+
p(state:, lnb:, line:) if debugging?
|
81
82
|
case state
|
82
83
|
when :outside
|
83
84
|
parse_line_outside(line, lnb)
|
@@ -96,6 +97,10 @@ class DocRSpec
|
|
96
97
|
add_example(lnb, Regexp.last_match)
|
97
98
|
when EXAMPLE_LINE
|
98
99
|
parse_example_line(Regexp.last_match)
|
100
|
+
when COMMENT_LINE
|
101
|
+
nil
|
102
|
+
else
|
103
|
+
@state = :outside
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
data/lib/doc_rspec/version.rb
CHANGED
data/lib/doc_rspec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rspec'
|
4
|
+
require_relative 'doc_rspec/debugging'
|
4
5
|
require_relative 'doc_rspec/compiler'
|
5
6
|
require_relative 'doc_rspec/rspec_example_group'
|
6
7
|
require_relative 'doc_rspec/parser'
|
@@ -92,6 +93,22 @@ RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
|
92
93
|
# require 'ostruct'
|
93
94
|
# OpenStruct.new(ok?: false) not! ok
|
94
95
|
#
|
96
|
+
#
|
97
|
+
# === Comments inside examples
|
98
|
+
#
|
99
|
+
# # example: comments are removed
|
100
|
+
#
|
101
|
+
# # so this works
|
102
|
+
# expect(1).to eq(1)
|
103
|
+
# # and this ==> too
|
104
|
+
#
|
105
|
+
# === End of Example
|
106
|
+
#
|
107
|
+
# the code does not continue after the rdoc comment
|
108
|
+
|
109
|
+
# # not a problem
|
110
|
+
# raise "This should never happen"
|
111
|
+
#
|
95
112
|
class DocRSpec
|
96
113
|
|
97
114
|
attr_reader :example_group, :lines, :path
|
data/lib/enumerable.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doc_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -49,9 +49,11 @@ files:
|
|
49
49
|
- lib/doc_rspec/compiler.rb
|
50
50
|
- lib/doc_rspec/context.rb
|
51
51
|
- lib/doc_rspec/context/example.rb
|
52
|
+
- lib/doc_rspec/debugging.rb
|
52
53
|
- lib/doc_rspec/parser.rb
|
53
54
|
- lib/doc_rspec/rspec_example_group.rb
|
54
55
|
- lib/doc_rspec/version.rb
|
56
|
+
- lib/enumerable.rb
|
55
57
|
homepage: https://codeberg.org/lab419/doc_rspec
|
56
58
|
licenses:
|
57
59
|
- AGPL-3.0-or-later
|