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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59e8d3ee3246fe4e1840227fee649981f2f57fb6be5ef1b9c02e2fb9a2ebb9ab
4
- data.tar.gz: e470857001bff3657ae5ab05c269d00369f89111e292d5678de760dd53771265
3
+ metadata.gz: bf085449bc26e2d09d22632b684aa0bf3ed785332fb48dec6bc9b2c4d34dc8a7
4
+ data.tar.gz: 9a2128d91d1bde271e6c3cc466cf1a0dcae7eef7fd9409afc3f62321dec261ba
5
5
  SHA512:
6
- metadata.gz: 410226d89424038b7c58c1a971e20942af897472b6a9d4825e1b08aebe8e3a0f876bcec58c9205c0c3720006e63acd9a0654aaea8ba7693f84bbae3bacafae48
7
- data.tar.gz: 9f73f46d97b292a6e7e8c0c198186b29021adeb50bcbfcb7c8e7901d8f7640ac360f1789c073c34e4f9e36d5acaafcc755579c5e7df3495ea0625f9be5aa63f1
6
+ metadata.gz: 4df3db0c9bd84ef659cc36e244785e0a17c2978149032f3414938a47204548413df52d57e2af8841663dde41d52a6f91b60ff29d8a85268894116dcf4aad309a
7
+ data.tar.gz: 65407d9582ec987d6ebafd1aed813212d2ea33c79e635ea277d8b3bd41b4ecad6183943ab5232d54a94f6ce43b03d4ec06eacf0a58730e0e2122605ea52c1eaa
@@ -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
- compile_example = method(:compile_example)
26
- example_group.context context_spec.context_name(path) do
27
- context_spec.examples.each { compile_example.(it) }
28
- end
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 example_spec.lines.map { "> #{it}" }
49
+ puts code.map { "> #{it}" }
43
50
  puts "=" * 72
44
51
  end
45
52
  return if debug_level > 2
46
53
 
47
- example_group.it example_name do
48
- example = self
49
- eval(code)
50
- end
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)
@@ -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]
@@ -2,7 +2,7 @@
2
2
 
3
3
  class DocRSpec
4
4
  module Version
5
- VERSION = '0.2.4'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: AGPL-3.0-or-later
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
- # the code does not continue after the rdoc comment
99
-
100
- # # not a problem
101
- # raise "This should never happen"
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
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
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober