doc_rspec 0.2.4 → 0.3.0
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 +18 -10
- data/lib/doc_rspec/parser.rb +3 -1
- data/lib/doc_rspec/version.rb +1 -1
- data/lib/doc_rspec.rb +18 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf085449bc26e2d09d22632b684aa0bf3ed785332fb48dec6bc9b2c4d34dc8a7
|
4
|
+
data.tar.gz: 9a2128d91d1bde271e6c3cc466cf1a0dcae7eef7fd9409afc3f62321dec261ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df3db0c9bd84ef659cc36e244785e0a17c2978149032f3414938a47204548413df52d57e2af8841663dde41d52a6f91b60ff29d8a85268894116dcf4aad309a
|
7
|
+
data.tar.gz: 65407d9582ec987d6ebafd1aed813212d2ea33c79e635ea277d8b3bd41b4ecad6183943ab5232d54a94f6ce43b03d4ec06eacf0a58730e0e2122605ea52c1eaa
|
data/lib/doc_rspec/compiler.rb
CHANGED
@@ -22,10 +22,18 @@ class DocRSpec
|
|
22
22
|
# Inside the block of example_group.context we are not
|
23
23
|
# in this instances context anymore, therefore we need
|
24
24
|
# to access the `compile_example` method via a closure
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
inner_lines =
|
26
|
+
context_spec
|
27
|
+
.examples
|
28
|
+
.flat_map { compile_example it }
|
29
|
+
|
30
|
+
code = [
|
31
|
+
%{context #{context_spec.context_name(path).inspect} do},
|
32
|
+
*inner_lines,
|
33
|
+
'end'
|
34
|
+
]
|
35
|
+
|
36
|
+
example_group.instance_eval(code.join("\n"))
|
29
37
|
end
|
30
38
|
|
31
39
|
def compile_example(example_spec)
|
@@ -33,21 +41,21 @@ class DocRSpec
|
|
33
41
|
# this method as a function into a closure
|
34
42
|
code = example_spec
|
35
43
|
.lines
|
36
|
-
.join("\n")
|
37
44
|
return if code.empty?
|
38
45
|
|
39
46
|
example_name = example_spec.it_name(path)
|
40
47
|
if debug_level > 1
|
41
48
|
puts "Example: #{example_name}"
|
42
|
-
puts
|
49
|
+
puts code.map { "> #{it}" }
|
43
50
|
puts "=" * 72
|
44
51
|
end
|
45
52
|
return if debug_level > 2
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
[
|
55
|
+
%{it #{example_name.inspect} do},
|
56
|
+
code,
|
57
|
+
'end'
|
58
|
+
]
|
51
59
|
end
|
52
60
|
|
53
61
|
def compile_example_line(line, example)
|
data/lib/doc_rspec/parser.rb
CHANGED
@@ -13,7 +13,7 @@ class DocRSpec
|
|
13
13
|
CONTEXT_DEFINITION = %r{\A \s* \# \s ={1,7} \s (.*)}x
|
14
14
|
|
15
15
|
EXAMPLE_LINE = %r{\A \s* \# \s{4,} (.*)}x
|
16
|
-
|
16
|
+
|
17
17
|
SHORT_EQUALS = %r{\s \=\=\> \s}x
|
18
18
|
SHORT_MATCHES = %r{\s \~\> \s}x
|
19
19
|
SHORT_PREDICATE = %r{\s is\! \s}x
|
@@ -62,6 +62,8 @@ class DocRSpec
|
|
62
62
|
code = match[1]
|
63
63
|
return if code.empty?
|
64
64
|
|
65
|
+
return if COMMENT_LINE === code
|
66
|
+
|
65
67
|
compiled =
|
66
68
|
SHORTCUTS.find_value(default: code) do |shtct_def|
|
67
69
|
shtct_def => [rgx, to_or_not, rhs_template]
|
data/lib/doc_rspec/version.rb
CHANGED
data/lib/doc_rspec.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'doc_rspec/parser'
|
|
8
8
|
RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
9
9
|
|
10
10
|
##
|
11
|
+
#
|
11
12
|
# = Code
|
12
13
|
#
|
13
14
|
# can be found [at Codeberg](https://codeberg.org/lab419/doc_rspec)
|
@@ -93,12 +94,14 @@ RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
|
93
94
|
# require 'ostruct'
|
94
95
|
# OpenStruct.new(ok?: false) not! ok
|
95
96
|
#
|
96
|
-
# === End of Example
|
97
97
|
#
|
98
|
-
#
|
99
|
-
|
100
|
-
# #
|
101
|
-
#
|
98
|
+
# === Comments inside examples
|
99
|
+
#
|
100
|
+
# # example: comments are removed
|
101
|
+
#
|
102
|
+
# # so this works
|
103
|
+
# expect(1).to eq(1)
|
104
|
+
# # and this ==> too
|
102
105
|
#
|
103
106
|
class DocRSpec
|
104
107
|
|
@@ -117,4 +120,14 @@ class DocRSpec
|
|
117
120
|
end
|
118
121
|
|
119
122
|
end
|
123
|
+
|
124
|
+
##
|
125
|
+
#
|
126
|
+
# === End of Example
|
127
|
+
#
|
128
|
+
# the code does not continue after the rdoc comment
|
129
|
+
|
130
|
+
# # not a problem
|
131
|
+
# raise "This should never happen"
|
132
|
+
#
|
120
133
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|