doc_rspec 0.2.0 → 0.2.1
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 +3 -5
- data/lib/doc_rspec/context/example.rb +2 -2
- data/lib/doc_rspec/context.rb +2 -2
- data/lib/doc_rspec/parser.rb +17 -4
- data/lib/doc_rspec/version.rb +1 -1
- data/lib/doc_rspec.rb +32 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fb556df1f9e8f00edb81eb6fc6db4c0d86d7864dbaedda0a9e559625df7fe98
|
4
|
+
data.tar.gz: 69296b360896f5a2258884bc59dc26b115648b107242f8f877eecca507b3b371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 641237f09a349ea510b93a562d3548e8398409af64c58f03be21499ce42eee8053f0b2fa4d596befdb6ac035747ba761f3e6e494de5c317966554756c74921cc
|
7
|
+
data.tar.gz: b7100cb9cf8d8b016c4466409fd4a608d569f022e62e20a30bacf90031e65f7047fad2d7d3e758504db4fb64d732a072c4cbb1a8fef853a40e8588a4a17b0230
|
data/lib/doc_rspec/compiler.rb
CHANGED
@@ -30,15 +30,13 @@ class DocRSpec
|
|
30
30
|
def compile_example(example_spec)
|
31
31
|
# See comment above for an explanation why we capture
|
32
32
|
# this method as a function into a closure
|
33
|
-
compile_example_line = method(:compile_example_line)
|
34
33
|
example_group.it example_spec.it_name(path) do
|
35
34
|
example = self
|
36
|
-
|
35
|
+
code = example_spec
|
37
36
|
.lines
|
38
|
-
.
|
39
|
-
.compact
|
37
|
+
.join("\n")
|
40
38
|
|
41
|
-
eval(
|
39
|
+
eval(code) unless code.empty?
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
data/lib/doc_rspec/context.rb
CHANGED
data/lib/doc_rspec/parser.rb
CHANGED
@@ -10,9 +10,11 @@ class DocRSpec
|
|
10
10
|
|
11
11
|
CONTEXT_DEFINITION = %r{\A \s* \# \s ={1,7} \s (.*)}x
|
12
12
|
|
13
|
-
EQUALS_OP = %r{\s+ => \s+}x
|
14
13
|
EXAMPLE_LINE = %r{\A \s* \# \s{4,} (.*)}x
|
15
14
|
|
15
|
+
SHORT_EQUALS = %r{\s eq\! \s}x
|
16
|
+
SHORT_MATCHES = %r{\s \= \~ \s}x
|
17
|
+
SHORT_PREDICATE = %r{\s is\! \s}x
|
16
18
|
START_EXAMPLE = %r{\A \s* \# \s{4,} \# \s example: \s (.*)}x
|
17
19
|
|
18
20
|
attr_reader :ast, :lines, :state
|
@@ -48,12 +50,23 @@ class DocRSpec
|
|
48
50
|
|
49
51
|
def parse_example_line(match)
|
50
52
|
code = match[1]
|
53
|
+
return if code.empty?
|
51
54
|
|
52
|
-
case code.split(
|
55
|
+
case code.split(SHORT_EQUALS)
|
53
56
|
in [lhs, rhs]
|
54
|
-
ast.last.add_example_line(
|
57
|
+
ast.last.add_example_line("expect(#{lhs}).to eq(#{rhs})")
|
55
58
|
else
|
56
|
-
|
59
|
+
case code.split(SHORT_MATCHES)
|
60
|
+
in [lhs, rhs]
|
61
|
+
ast.last.add_example_line("expect(#{lhs}).to match(#{rhs})")
|
62
|
+
else
|
63
|
+
case code.split(SHORT_PREDICATE)
|
64
|
+
in [lhs, rhs]
|
65
|
+
ast.last.add_example_line("expect(#{lhs}).to be_#{rhs}")
|
66
|
+
else
|
67
|
+
ast.last.add_example_line(code)
|
68
|
+
end
|
69
|
+
end
|
57
70
|
end
|
58
71
|
end
|
59
72
|
|
data/lib/doc_rspec/version.rb
CHANGED
data/lib/doc_rspec.rb
CHANGED
@@ -7,6 +7,10 @@ require_relative 'doc_rspec/parser'
|
|
7
7
|
RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
8
8
|
|
9
9
|
##
|
10
|
+
# = Code
|
11
|
+
#
|
12
|
+
# can be found [at Codeberg](https://codeberg.org/lab419/doc_rspec)
|
13
|
+
#
|
10
14
|
# = Usage
|
11
15
|
#
|
12
16
|
# Install the gem <tt>gem install doc_rspec</tt> or put +doc_rspec+ in your Gemfile
|
@@ -18,7 +22,6 @@ RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
|
18
22
|
#
|
19
23
|
# Inside your +RSpec+ file, at the example group level then call
|
20
24
|
#
|
21
|
-
# # Usage example
|
22
25
|
# docspec '<path_to_file>'
|
23
26
|
#
|
24
27
|
# Where +path_to_file+ is relative to the +lib+ directory
|
@@ -41,15 +44,7 @@ RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
|
41
44
|
#
|
42
45
|
# # example: We have access to the wrapping context
|
43
46
|
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
# Although this gem is named +doc_rspec+ and its goal is certainly to document behavior
|
47
|
-
# of Ruby code inside the +RDoc+ documentation of that code, and _most_ _importantly_
|
48
|
-
# backing the claims made in this documentation up with *actual* +RSpec+ examples,
|
49
|
-
# in this _MVP_ the parser will simply generate code for all lines matching
|
50
|
-
# <tt>/\A \s* \# \s{3,}/x</tt> after a triggering line macthing
|
51
|
-
# <tt>/\A \s* \# \s{3,} \# \s example: \s (.+)/x</tt>
|
52
|
-
# and potentially ended with the aforementioned <tt>/\A \s* \# \s{3,} \# \s end \s of \s example/x</tt>
|
47
|
+
# this_is_available(22) eq! 44
|
53
48
|
#
|
54
49
|
# This implies two thing
|
55
50
|
#
|
@@ -63,6 +58,33 @@ RSpec.configure { it.extend DocRSpec::RSpecExampleGroup }
|
|
63
58
|
# # example: equality
|
64
59
|
# expect(41 + 1).to eq(42)
|
65
60
|
#
|
61
|
+
# == Shortcuts
|
62
|
+
#
|
63
|
+
# In addition to _standard_ +RSpec+ code, one can use 3 shorthand forms that are compiled as follows
|
64
|
+
#
|
65
|
+
# === +eq!+
|
66
|
+
#
|
67
|
+
# # example: eq! shorthand for eq
|
68
|
+
#
|
69
|
+
# answer = 42
|
70
|
+
#
|
71
|
+
# answer eq! 42
|
72
|
+
#
|
73
|
+
# this was compiled to <tt>expect(answer).to eq(42)</tt>
|
74
|
+
#
|
75
|
+
# === +=~+ for match
|
76
|
+
#
|
77
|
+
# # example: =~ shorthand for match
|
78
|
+
#
|
79
|
+
# "alpha" =~ /\Aa.+a\z/
|
80
|
+
#
|
81
|
+
# === +is!+ for be_
|
82
|
+
#
|
83
|
+
# # example: =~ shorthand for be
|
84
|
+
#
|
85
|
+
# require 'ostruct'
|
86
|
+
# OpenStruct.new(ok?: true) is! ok
|
87
|
+
#
|
66
88
|
class DocRSpec
|
67
89
|
|
68
90
|
attr_reader :example_group, :lines, :path
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.6.
|
73
|
+
rubygems_version: 3.6.8
|
74
74
|
specification_version: 4
|
75
75
|
summary: '["Extract RSpec Examples from RDocs formatted with RDoc::Markup (the default)"]'
|
76
76
|
test_files: []
|