speculate_about 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50dd660d1e2e984b66f854df6f71e1f280ddef2e162d2848a3cf363ffe5751a4
4
- data.tar.gz: 56ed0de10d7ee9751ae86deb247e7f8ad8d6b90f3a2e71623d83b0d169f18f59
3
+ metadata.gz: 691aa57b9ad1035ca6eb20fe75f89b818414dcd33e05acd9d6621e13ee1cfb23
4
+ data.tar.gz: 286766d1c5243bc9c1c6eb205c6e38ee97b3d06c90f4d77b6d84638a56d465e2
5
5
  SHA512:
6
- metadata.gz: cd78c231bd7ab5eb1146c8d1f2fb3b19bea52951c30001d373981b748a77404bd5a5b87477bef989fa9707ff1049d9d7d6a91e2c3a0fa1cdc4533351c2a214bc
7
- data.tar.gz: dbb334195b9354655edc06a11e52a0e77bee6be0961cc545fafc19ca6f2e0de5ba2c7c818ccde14bbf0fc2b2ba14b42f10fa02b114eb3f39b679763ea8427e2e
6
+ metadata.gz: cea1cc7dc006a7315fac53026959d444ae5a9bdcad161a94f57df7fdf3bead8cf5ee23aac5b9eaecdd68bc888cbf0df9e290acc4e09435f2b5bd771113ce38c3
7
+ data.tar.gz: 6dcd950c3ea0bace47c8ecf3e42dd38ff41d747ac92918c30c08e2403e0c6c2471dcf69c1f3eddc04049988c40d555b07f470ee6a3e873cf8c36aa1223828690
@@ -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
- _root_header
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
- map_lines("end", indent: -1)
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
@@ -11,17 +11,17 @@ module Speculations
11
11
  new_parent = node.parent_of_level(level.pred)
12
12
  node = new_parent.new_context(title: match[2], lnb: lnb, level: level)
13
13
  [:out, node]
14
- when match = State.maybe_example(line)
15
- [:candidate, node, match[:title]]
16
14
  when match = State.maybe_include(line)
17
15
  [:candidate, node, :inc]
16
+ when match = State.maybe_example(line)
17
+ [:candidate, node, match[:title]]
18
18
  when match = State.ruby_code_block(line)
19
19
  if ctxt == :inc
20
20
  node = node.new_include(lnb: lnb)
21
21
  else
22
22
  node = node.new_example(title: ctxt, lnb: lnb)
23
23
  end
24
- [:in, node]
24
+ [:in, node, (ctxt == :inc ? :includes : :out)]
25
25
  else
26
26
  [:out, node]
27
27
  end
@@ -6,9 +6,9 @@ module Speculations
6
6
  def parse line, _lnb, node, ctxt
7
7
  case
8
8
  when State.eoblock_match(line)
9
- [:out, node.parent]
9
+ [ctxt, node.parent]
10
10
  else
11
- [:in, node.add_line(line)]
11
+ [:in, node.add_line(line), ctxt]
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,31 @@
1
+ module Speculations
2
+ class Parser
3
+ module State
4
+ module Includes extend self
5
+
6
+ def parse line, lnb, node, _ctxt
7
+ case
8
+ when match = State.context_match(line)
9
+ make_new_context(lnb: lnb, node: node, match: match)
10
+ when match = State.maybe_include(line)
11
+ [:candidate, node, :inc]
12
+ when match = State.maybe_example(line)
13
+ [:candidate, node, match[:title]]
14
+ else
15
+ [:includes, node]
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def make_new_context(lnb:, match:, node:)
22
+ level = match[:level].size
23
+ new_parent = node.parent_of_level(level.pred)
24
+ node = new_parent.new_context(title: match[:title], lnb: lnb, level: level)
25
+ [:out, node]
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,10 +3,10 @@ module Speculations::Parser::State::Triggers
3
3
  BLANK_RGX = %r{\A\s*\z}
4
4
  CONTEXT_RGX = %r[\A\s{0,3}(?<level>\#{1,7})\s+Context:?\s+(?<title>.*)]
5
5
  EOBLOCK_RGX = %r[\A\s{0,3}```\s*\z]
6
- GIVEN_RGX = %r[\A\s{0,3}(?:Given|When)\b]
6
+ GIVEN_RGX = %r[\A\s{0,3}(?:Given|When|And)\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)
@@ -1,6 +1,7 @@
1
1
  module Speculations::Parser::State extend self
2
2
  require_relative './state/candidate'
3
3
  require_relative './state/in'
4
+ require_relative './state/includes'
4
5
  require_relative './state/out'
5
6
  require_relative './state/triggers'
6
7
 
@@ -8,6 +8,7 @@ module Speculations
8
8
  @__parsers__ ||= {
9
9
  candidate: State::Candidate,
10
10
  in: State::In,
11
+ includes: State::Includes,
11
12
  out: State::Out
12
13
  }
13
14
  end
@@ -31,7 +32,8 @@ module Speculations
31
32
  root = node = Context.new(filename: @filename)
32
33
  ctxt = nil
33
34
  @input.each_with_index do |line, lnb|
34
- @state, node, ctxt = self.class.parsers.fetch(@state).parse(line, lnb.succ, node, ctxt)
35
+ parser = self.class.parsers.fetch(@state)
36
+ @state, node, ctxt = parser.parse(line, lnb.succ, node, ctxt)
35
37
  end
36
38
  root
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module Speculations
2
- VERSION = "0.5.1"
2
+ VERSION = "1.0.0"
3
3
  end
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
- File.write(outfile, ast.to_code.join("\n"))
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.5.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
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-30 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
@@ -57,6 +29,7 @@ files:
57
29
  - lib/speculations/parser/state.rb
58
30
  - lib/speculations/parser/state/candidate.rb
59
31
  - lib/speculations/parser/state/in.rb
32
+ - lib/speculations/parser/state/includes.rb
60
33
  - lib/speculations/parser/state/out.rb
61
34
  - lib/speculations/parser/state/triggers.rb
62
35
  - lib/speculations/version.rb
@@ -72,14 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
45
  requirements:
73
46
  - - ">="
74
47
  - !ruby/object:Gem::Version
75
- version: 2.7.0
48
+ version: 3.1.0
76
49
  required_rubygems_version: !ruby/object:Gem::Requirement
77
50
  requirements:
78
51
  - - ">="
79
52
  - !ruby/object:Gem::Version
80
53
  version: '0'
81
54
  requirements: []
82
- rubygems_version: 3.2.3
55
+ rubygems_version: 3.3.3
83
56
  signing_key:
84
57
  specification_version: 4
85
58
  summary: Extract RSpecs from Markdown