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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88e3a986df1d2228b1455a425584ffa80e6ca725961a5e86e2cf14eb7d600b0c
4
- data.tar.gz: ccbe8af928c2762e281e776b451d7a14a981d8f28fef39ac2ceb72f447b297de
3
+ metadata.gz: 2fb556df1f9e8f00edb81eb6fc6db4c0d86d7864dbaedda0a9e559625df7fe98
4
+ data.tar.gz: 69296b360896f5a2258884bc59dc26b115648b107242f8f877eecca507b3b371
5
5
  SHA512:
6
- metadata.gz: 9a1a4f71792902e0454f2e857471f0122f06c2cea648401cdee47e7c6e743fbcd52ea689771edd675d3d69a529c77b2a602b130bbb2246dce045a3e51a020df2
7
- data.tar.gz: 0f51c159a2cdde070fc6339c4bf7c2fab713047d391b649f887337c24544ee039f5493df0e66d8172d228b49d630767e61d4a9bf470aed31da3518458970d346
6
+ metadata.gz: 641237f09a349ea510b93a562d3548e8398409af64c58f03be21499ce42eee8053f0b2fa4d596befdb6ac035747ba761f3e6e494de5c317966554756c74921cc
7
+ data.tar.gz: b7100cb9cf8d8b016c4466409fd4a608d569f022e62e20a30bacf90031e65f7047fad2d7d3e758504db4fb64d732a072c4cbb1a8fef853a40e8588a4a17b0230
@@ -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
- code_lines = example_spec
35
+ code = example_spec
37
36
  .lines
38
- .map { compile_example_line.(it, example) }
39
- .compact
37
+ .join("\n")
40
38
 
41
- eval(code_lines.join("\n")) unless code_lines.empty?
39
+ eval(code) unless code.empty?
42
40
  end
43
41
  end
44
42
 
@@ -5,8 +5,8 @@ class DocRSpec
5
5
  class Example
6
6
  attr_reader :lines, :lnb, :name
7
7
 
8
- def add(op, lhs, rhs)
9
- lines << [op, lhs, rhs].compact
8
+ def add(code)
9
+ lines << code
10
10
  end
11
11
 
12
12
  def it_name(path)
@@ -10,8 +10,8 @@ class DocRSpec
10
10
  examples << Example.new(lnb, name:)
11
11
  end
12
12
 
13
- def add_example_line(op, lhs, rhs=nil)
14
- examples.last.add(op, lhs, rhs)
13
+ def add_example_line(code)
14
+ examples.last.add(code)
15
15
  end
16
16
 
17
17
  def context_name(path)
@@ -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(EQUALS_OP)
55
+ case code.split(SHORT_EQUALS)
53
56
  in [lhs, rhs]
54
- ast.last.add_example_line(:eq, lhs, rhs)
57
+ ast.last.add_example_line("expect(#{lhs}).to eq(#{rhs})")
55
58
  else
56
- ast.last.add_example_line(:verb, code) unless code.empty?
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  class DocRSpec
4
4
  module Version
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: AGPL-3.0-or-later
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
- # this_is_available(22) => 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.0
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.7
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: []