varar-rspec 0.7.0 → 0.8.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/varar/rspec.rb +70 -11
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd1931c8d54abf4bdaae28a8e8f136e3d6991b03ba6cf1a22cc49d5f658c8bfe
|
|
4
|
+
data.tar.gz: 0dd3622959aa6b187cc593223850229ab598fd0870c24f943f87e4779b8d31c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc553518b90a17dc6bd813462ccdea3bd1a4f004b1dc0cd6ec1de78c4879522eb3e6c55c73964f4cbbfed577dd8c7cedda22b12955756a9f60b2dcb3362674ef
|
|
7
|
+
data.tar.gz: 5a38ebeb4b9cfb4c78bf3ebd54327875f509ca74dc0de2926f8f1ae45daf59f98365b61d8389d8348817193c4bea8fca014e5e1ab0df91bd937fc86f13a472a5
|
data/lib/varar/rspec.rb
CHANGED
|
@@ -4,48 +4,102 @@ require 'rspec/core'
|
|
|
4
4
|
require 'varar/runner'
|
|
5
5
|
|
|
6
6
|
module Varar
|
|
7
|
-
# RSpec adapter. One call defines an RSpec example group per
|
|
7
|
+
# RSpec adapter. One call defines an RSpec example group per oath matched by
|
|
8
8
|
# varar.config.json, with one `it` per Markdown example (header-bound rows are
|
|
9
9
|
# separate examples) and a drift gate. See ADR 0005.
|
|
10
10
|
#
|
|
11
|
-
# # spec/
|
|
11
|
+
# # spec/varar_spec.rb
|
|
12
12
|
# require "varar/rspec"
|
|
13
13
|
# Varar::RSpec.generate
|
|
14
14
|
module RSpec
|
|
15
|
-
VERSION = '0.
|
|
15
|
+
VERSION = '0.8.1'
|
|
16
16
|
|
|
17
17
|
module_function
|
|
18
18
|
|
|
19
19
|
def generate(root: nil)
|
|
20
20
|
root ||= File.dirname(caller_locations(1, 1).first.path)
|
|
21
21
|
root = File.expand_path(root)
|
|
22
|
-
cfg = Config.
|
|
22
|
+
cfg = Config.read_config(root)
|
|
23
23
|
loaded = Runner.load_steps(cfg.steps, root)
|
|
24
24
|
store = Runner.create_file_baseline_store(root)
|
|
25
25
|
update = %w[1 true].include?(ENV.fetch('VARAR_UPDATE', nil))
|
|
26
26
|
|
|
27
|
-
Runner.
|
|
28
|
-
|
|
27
|
+
oaths = Runner.find_oaths(cfg.docs_include, cfg.docs_exclude, root)
|
|
28
|
+
# Run results for the language server (ADR 0014). RSpec has no per-oath
|
|
29
|
+
# completion hook here, so each group flushes its own oath in after(:all).
|
|
30
|
+
results = Runner::Results.new
|
|
31
|
+
|
|
32
|
+
# Drop baselines for oaths the config no longer discovers. Reconciliation is
|
|
33
|
+
# per-oath and never sees a path that has gone, so the lock would otherwise
|
|
34
|
+
# accumulate dead entries forever (#70). Once per run, keyed off the config
|
|
35
|
+
# globs — which here IS the full set, since generate always discovers
|
|
36
|
+
# everything.
|
|
37
|
+
Core::Drifts.prune_baselines(store, oaths.map { |p| Runner.rel_posix(p, root) }, update: update)
|
|
38
|
+
|
|
39
|
+
workspace = project_workspace(oaths, root)
|
|
40
|
+
|
|
41
|
+
oaths.each do |oath_path|
|
|
42
|
+
define_group(oath_path, root, loaded, store, update, results, workspace)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Whether a section is a standalone example depends on whether another oath
|
|
47
|
+
# references it, which is whole-project knowledge (ADR 0016). Built from the
|
|
48
|
+
# config globs — the full set, for the same reason baseline pruning is.
|
|
49
|
+
# The sources of every oath this plan's steps were spliced in from (ADR
|
|
50
|
+
# 0016). Their hashes go in the run record, so a consumer can tell a stale
|
|
51
|
+
# failure from a live one.
|
|
52
|
+
def referenced_sources(plan, workspace)
|
|
53
|
+
plan.examples.flat_map { |ex| ex.steps.map(&:doc_path) }.compact.uniq.each_with_object({}) do |path, out|
|
|
54
|
+
doc = workspace.docs[path]
|
|
55
|
+
out[path] = doc.source if doc
|
|
29
56
|
end
|
|
30
57
|
end
|
|
31
58
|
|
|
32
|
-
def
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
def project_workspace(oaths, root)
|
|
60
|
+
docs = oaths.filter_map do |path|
|
|
61
|
+
Core::Parse.parse(Runner.rel_posix(path, root), File.read(path, encoding: 'UTF-8'))
|
|
62
|
+
rescue SystemCallError
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
Core::Reference.build_workspace(docs)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def define_group(oath_path, root, loaded, store, update, results, workspace)
|
|
69
|
+
rel = Runner.rel_posix(oath_path, root)
|
|
70
|
+
source = File.read(oath_path, encoding: 'UTF-8')
|
|
71
|
+
# `rel`, not the basename: doc.path is an oath's identity in every port,
|
|
72
|
+
# so a relative reference resolves alike and two same-named oaths in
|
|
73
|
+
# different directories stay distinct (ADR 0016).
|
|
74
|
+
plan = Runner.plan_oath(rel, source, loaded.registry, workspace)
|
|
75
|
+
referenced = referenced_sources(plan, workspace)
|
|
36
76
|
pairs = Runner.examples_with_runs(plan, loaded.create_context, Runner::RecordingReporter.new)
|
|
37
|
-
drifts = Core::Drifts.reconcile_drift(store, rel, source, plan.
|
|
77
|
+
drifts = Core::Drifts.reconcile_drift(store, rel, source, plan.doc, plan, update: update)
|
|
38
78
|
|
|
39
79
|
::RSpec.describe(rel) do
|
|
40
80
|
pairs.each do |example, run|
|
|
81
|
+
# Lines in THIS oath: a step a reference block spliced in from
|
|
82
|
+
# another oath (ADR 0016) contributes none, since its line is not in
|
|
83
|
+
# this file.
|
|
84
|
+
lines = example.steps.reject(&:doc_path).map { |s| s.match_span.start_line }.uniq
|
|
41
85
|
# A var diff surfaces as a failure carrying the span-anchored render;
|
|
42
86
|
# any other exception propagates. RSpec reports both as failures.
|
|
43
87
|
it(example.name) do
|
|
44
88
|
run.call
|
|
45
89
|
rescue StandardError => e
|
|
90
|
+
# Recorded here, where the error object is still in hand: to_failure
|
|
91
|
+
# reads the anchor the executor attached to it.
|
|
92
|
+
results.record(rel, source, Core::ExampleResult.new(
|
|
93
|
+
name: example.name, status: 'failed', lines: lines,
|
|
94
|
+
failure: Core::Failures.to_failure(e, rel, lines.first || 0)
|
|
95
|
+
), referenced)
|
|
46
96
|
raise Runner.render_failure(e, source, rel) if RSpec.var_diff_error?(e)
|
|
47
97
|
|
|
48
98
|
raise
|
|
99
|
+
else
|
|
100
|
+
results.record(rel, source, Core::ExampleResult.new(
|
|
101
|
+
name: example.name, status: 'passed', lines: lines, failure: nil
|
|
102
|
+
), referenced)
|
|
49
103
|
end
|
|
50
104
|
end
|
|
51
105
|
|
|
@@ -53,6 +107,11 @@ module Varar
|
|
|
53
107
|
message = Core::Diagnostics.drift_detected(drift.name, drift.span).message
|
|
54
108
|
it("var drift at line #{drift.line}") { raise message }
|
|
55
109
|
end
|
|
110
|
+
|
|
111
|
+
# This oath's examples are all in — write its results. A passing oath is
|
|
112
|
+
# written too: a stale file would keep a diagnostic on screen that this
|
|
113
|
+
# run has just cleared.
|
|
114
|
+
after(:all) { results.flush(root, rel) }
|
|
56
115
|
end
|
|
57
116
|
end
|
|
58
117
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: varar-rspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aslak Hellesøy
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - '='
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.
|
|
32
|
+
version: 0.8.1
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - '='
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.
|
|
39
|
+
version: 0.8.1
|
|
40
40
|
description: 'RSpec adapter: one selectable example per Markdown example, with a drift
|
|
41
41
|
gate.'
|
|
42
42
|
email:
|
|
@@ -67,5 +67,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
67
67
|
requirements: []
|
|
68
68
|
rubygems_version: 4.0.16
|
|
69
69
|
specification_version: 4
|
|
70
|
-
summary: Markdown-native BDD — run Markdown
|
|
70
|
+
summary: Markdown-native BDD — run Markdown oaths as RSpec examples
|
|
71
71
|
test_files: []
|