varar-rspec 0.5.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/varar/rspec.rb +64 -0
  3. metadata +71 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b76a0b607c4dc1b8203c124ae93bd454630718a051b309841bcf35bb7a7d2b6d
4
+ data.tar.gz: 884bd2f2f4fc3e623e12130f5e5ef35e2468c7b4ac5e0b0afed4fd3d27fbb96d
5
+ SHA512:
6
+ metadata.gz: 0e4888dc59caba0bd611d8cffb87865be40f2cdf3938b4ef542a4d82a0d160a9716fff7ebc8fad296bf2329eff2da05feaa5781a4f12c6895c5273d058397ba8
7
+ data.tar.gz: 3394c3029ebe391403ba7bb8787ca4bf5bb275a0daf7913ef3bb51f1ddc7bba9a17f973c828b6d9f8600d332ab227a7744e68d920651bed8bf2eecab2917d2ee
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core'
4
+ require 'varar/runner'
5
+
6
+ module Varar
7
+ # RSpec adapter. One call defines an RSpec example group per spec matched by
8
+ # varar.config.json, with one `it` per Markdown example (header-bound rows are
9
+ # separate examples) and a drift gate. See ADR 0005.
10
+ #
11
+ # # spec/var_spec.rb
12
+ # require "varar/rspec"
13
+ # Varar::RSpec.generate
14
+ module RSpec
15
+ VERSION = '0.5.0'
16
+
17
+ module_function
18
+
19
+ def generate(root: nil)
20
+ root ||= File.dirname(caller_locations(1, 1).first.path)
21
+ root = File.expand_path(root)
22
+ cfg = Config.read_var_config(root)
23
+ loaded = Runner.load_steps(cfg.steps, root)
24
+ store = Runner.create_file_baseline_store(root)
25
+ update = %w[1 true].include?(ENV.fetch('VAR_UPDATE', nil))
26
+
27
+ Runner.find_specs(cfg.docs_include, cfg.docs_exclude, root).each do |spec_path|
28
+ define_group(spec_path, root, loaded, store, update)
29
+ end
30
+ end
31
+
32
+ def define_group(spec_path, root, loaded, store, update)
33
+ rel = Runner.rel_posix(spec_path, root)
34
+ source = File.read(spec_path, encoding: 'UTF-8')
35
+ plan = Runner.plan_spec(File.basename(spec_path), source, loaded.registry)
36
+ pairs = Runner.examples_with_runs(plan, loaded.create_context, Runner::RecordingReporter.new)
37
+ drifts = Core::Drifts.reconcile_drift(store, rel, source, plan.var_doc, plan, update: update)
38
+
39
+ ::RSpec.describe(rel) do
40
+ pairs.each do |example, run|
41
+ # A var diff surfaces as a failure carrying the span-anchored render;
42
+ # any other exception propagates. RSpec reports both as failures.
43
+ it(example.name) do
44
+ run.call
45
+ rescue StandardError => e
46
+ raise Runner.render_failure(e, source, rel) if RSpec.var_diff_error?(e)
47
+
48
+ raise
49
+ end
50
+ end
51
+
52
+ drifts.each do |drift|
53
+ message = Core::Diagnostics.drift_detected(drift.name, drift.span).message
54
+ it("var drift at line #{drift.line}") { raise message }
55
+ end
56
+ end
57
+ end
58
+
59
+ def var_diff_error?(error)
60
+ error.is_a?(Core::CellMismatchError) || error.is_a?(Core::DocStringMismatchError) ||
61
+ error.is_a?(Core::ReturnShapeError) || error.is_a?(Core::UnexpectedPassError)
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: varar-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Aslak Hellesøy
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rspec-core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3.13'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '3.13'
26
+ - !ruby/object:Gem::Dependency
27
+ name: varar-runner
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.5.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.5.0
40
+ description: 'RSpec adapter: one selectable example per Markdown example, with a drift
41
+ gate.'
42
+ email:
43
+ - aslak@oselvar.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/varar/rspec.rb
49
+ homepage: https://varar.dev
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ rubygems_mfa_required: 'true'
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 4.0.16
69
+ specification_version: 4
70
+ summary: Markdown-native BDD — run Markdown specs as RSpec examples
71
+ test_files: []