speculate_about 0.5.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/speculate_about.rb +27 -0
- data/lib/speculations/parser/context.rb +6 -15
- data/lib/speculations/parser/state/triggers.rb +1 -1
- data/lib/speculations/version.rb +1 -1
- data/lib/speculations.rb +16 -1
- metadata +9 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68c9156823395a28b426d374248458dd846e438e3ab0d6b31330e0357db4473e
|
4
|
+
data.tar.gz: 6ac9fb5014c33af83186983cf26f0770ebf7f4f2ef07c070d067f2f30477e658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee238e533857ea54f7bc47059824e06f264018419e07551338a33b8f319a64c070d59169f37e2c4f266a750cea7603c9d5fc9b45caf5ef3d9f94359fa37aed5d
|
7
|
+
data.tar.gz: b84407b46a432412f6a78e84e2cc3d07c3f381a6a93cbc18a45d5d3ea9c19b5f77209aa79bf8cef4cc9f811a1806ea7f84c6e8e208d025ccc3312475f75d4566
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require_relative 'speculations/parser'
|
3
|
+
module SpeculateAbout
|
4
|
+
|
5
|
+
def speculate_about(infile)
|
6
|
+
raise ArgumentError, "#{infile} not found" unless File.readable? infile
|
7
|
+
ast = Speculations::Parser.new.parse_from_file(infile)
|
8
|
+
code = ast.to_code.join("\n")
|
9
|
+
ENV["SPECULATE_ABOUT_DEBUG"] ? _show(code, infile) : instance_eval(code, infile)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def _show(code, path)
|
14
|
+
message = "Generated code for #{path}"
|
15
|
+
_underline(message)
|
16
|
+
puts code
|
17
|
+
end
|
18
|
+
def _underline(message, ul: "=")
|
19
|
+
puts message
|
20
|
+
puts message.gsub(/./, ul)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec.configure do |conf|
|
26
|
+
conf.extend SpeculateAbout
|
27
|
+
end
|
@@ -4,15 +4,6 @@ module Speculations
|
|
4
4
|
require_relative './context/include'
|
5
5
|
require_relative './context/example'
|
6
6
|
|
7
|
-
DISCLAIMER = <<-EOD
|
8
|
-
# DO NOT EDIT!!!
|
9
|
-
# This file was generated from FILENAME with the speculate_about gem, if you modify this file
|
10
|
-
# one of two bad things will happen
|
11
|
-
# - your documentation specs are not correct
|
12
|
-
# - your modifications will be overwritten by the speculate rake task
|
13
|
-
# YOU HAVE BEEN WARNED
|
14
|
-
EOD
|
15
|
-
|
16
7
|
attr_reader :filename, :level, :lnb, :title, :parent, :root, :tree_level
|
17
8
|
|
18
9
|
def new_context(title:, lnb:, level: )
|
@@ -94,14 +85,10 @@ module Speculations
|
|
94
85
|
if parent
|
95
86
|
map_lines(%{# #{filename}:#{lnb}}, %{context "#{title}" do}, indent: -1)
|
96
87
|
else
|
97
|
-
|
88
|
+
[]
|
98
89
|
end
|
99
90
|
end
|
100
91
|
|
101
|
-
def _root_header
|
102
|
-
map_lines(DISCLAIMER.gsub("FILENAME", filename.inspect).split("\n"), %{RSpec.describe #{filename.inspect} do}, indent: -1)
|
103
|
-
end
|
104
|
-
|
105
92
|
def _init_from_parent
|
106
93
|
@root = parent.root
|
107
94
|
@filename = parent.filename
|
@@ -109,7 +96,11 @@ module Speculations
|
|
109
96
|
end
|
110
97
|
|
111
98
|
def _footer
|
112
|
-
|
99
|
+
if parent
|
100
|
+
map_lines("end", indent: -1)
|
101
|
+
else
|
102
|
+
[]
|
103
|
+
end
|
113
104
|
end
|
114
105
|
|
115
106
|
def _realign_levels new_parent
|
@@ -6,7 +6,7 @@ module Speculations::Parser::State::Triggers
|
|
6
6
|
GIVEN_RGX = %r[\A\s{0,3}(?:Given|When)\b]
|
7
7
|
EXAMPLE_RGX = %r[\A\s{0,3}Example:?\s+(<?title>.*)]
|
8
8
|
RUBY_RGX = %r[\A\s{0,3}```ruby]
|
9
|
-
THEN_RGX = %r[\A\s{0,3}(?:Then|But|And|Also)\b\s*(?<title>.*)]
|
9
|
+
THEN_RGX = %r[\A\s{0,3}(?:Then|But|And|Also|Or)\b\s*(?<title>.*)]
|
10
10
|
|
11
11
|
def blank_line line
|
12
12
|
BLANK_RGX.match(line)
|
data/lib/speculations/version.rb
CHANGED
data/lib/speculations.rb
CHANGED
@@ -2,18 +2,33 @@ require 'fileutils'
|
|
2
2
|
require_relative 'speculations/parser'
|
3
3
|
module Speculations extend self
|
4
4
|
|
5
|
+
DISCLAIMER = <<-EOD
|
6
|
+
# DO NOT EDIT!!!
|
7
|
+
# This file was generated from FILENAME with the speculate_about gem, if you modify this file
|
8
|
+
# one of two bad things will happen
|
9
|
+
# - your documentation specs are not correct
|
10
|
+
# - your modifications will be overwritten by the speculate rake task
|
11
|
+
# YOU HAVE BEEN WARNED
|
12
|
+
EOD
|
13
|
+
|
5
14
|
def compile(infile, outfile=nil)
|
6
15
|
raise ArgumentError, "#{infile} not found" unless File.readable? infile
|
7
16
|
outfile ||= _speculation_path(infile)
|
8
17
|
if _out_of_date?(outfile, infile)
|
9
18
|
ast = Speculations::Parser.new.parse_from_file(infile)
|
10
|
-
|
19
|
+
code = _decorated_ast_code ast, infile
|
20
|
+
File.write(outfile, code.join("\n"))
|
11
21
|
end
|
12
22
|
outfile
|
13
23
|
end
|
14
24
|
|
15
25
|
private
|
16
26
|
|
27
|
+
def _decorated_ast_code ast, filename
|
28
|
+
[DISCLAIMER.gsub("FILENAME", filename.inspect).split("\n"), %{RSpec.describe #{filename.inspect} do}] +
|
29
|
+
ast.to_code + ["end"]
|
30
|
+
end
|
31
|
+
|
17
32
|
def _out_of_date?(outf, inf)
|
18
33
|
return true unless File.exists? outf
|
19
34
|
return File.lstat(outf).mtime <= File.lstat(inf).mtime
|
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speculate_about
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '13.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '13.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.10'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.10'
|
11
|
+
date: 2022-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: Allows Markdown or other text files to be used as literal specs, à la
|
42
14
|
Elixr doctest, but from any file.
|
43
15
|
email: robert.dober@gmail.com
|
@@ -47,6 +19,7 @@ extensions: []
|
|
47
19
|
extra_rdoc_files: []
|
48
20
|
files:
|
49
21
|
- bin/speculate
|
22
|
+
- lib/speculate_about.rb
|
50
23
|
- lib/speculations.rb
|
51
24
|
- lib/speculations/cli.rb
|
52
25
|
- lib/speculations/parser.rb
|
@@ -63,7 +36,7 @@ homepage: https://github.com/robertdober/speculate
|
|
63
36
|
licenses:
|
64
37
|
- Apache-2.0
|
65
38
|
metadata: {}
|
66
|
-
post_install_message:
|
39
|
+
post_install_message:
|
67
40
|
rdoc_options: []
|
68
41
|
require_paths:
|
69
42
|
- lib
|
@@ -71,15 +44,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
44
|
requirements:
|
72
45
|
- - ">="
|
73
46
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
47
|
+
version: 3.1.0
|
75
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
49
|
requirements:
|
77
50
|
- - ">="
|
78
51
|
- !ruby/object:Gem::Version
|
79
52
|
version: '0'
|
80
53
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
54
|
+
rubygems_version: 3.3.3
|
55
|
+
signing_key:
|
83
56
|
specification_version: 4
|
84
57
|
summary: Extract RSpecs from Markdown
|
85
58
|
test_files: []
|