Module: Oselvar::Var::RSpec
- Defined in:
- lib/oselvar/var/rspec.rb
Overview
Constant Summary collapse
- VERSION =
'0.3.2'
Class Method Summary collapse
- .define_group(spec_path, root, loaded, store, update) ⇒ Object
- .generate(root: nil) ⇒ Object
- .var_diff_error?(error) ⇒ Boolean
Class Method Details
.define_group(spec_path, root, loaded, store, update) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/oselvar/var/rspec.rb', line 33 def define_group(spec_path, root, loaded, store, update) rel = Runner.rel_posix(spec_path, root) source = File.read(spec_path, encoding: 'UTF-8') plan = Runner.plan_spec(File.basename(spec_path), source, loaded.registry) pairs = Runner.examples_with_runs(plan, loaded.create_context, Runner::RecordingReporter.new) drifts = Core::Drifts.reconcile_drift(store, rel, source, plan.var_doc, plan, update: update) ::RSpec.describe(rel) do pairs.each do |example, run| # A var diff surfaces as a failure carrying the span-anchored render; # any other exception propagates. RSpec reports both as failures. it(example.name) do run.call rescue StandardError => e raise Runner.render_failure(e, source, rel) if RSpec.var_diff_error?(e) raise end end drifts.each do |drift| = Core::Diagnostics.drift_detected(drift.name, drift.span). it("var drift at line #{drift.line}") { raise } end end end |
.generate(root: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/oselvar/var/rspec.rb', line 20 def generate(root: nil) root ||= File.dirname(caller_locations(1, 1).first.path) root = File.(root) cfg = Config.read_var_config(root) loaded = Runner.load_steps(cfg.steps, root) store = Runner.create_file_baseline_store(root) update = %w[1 true].include?(ENV.fetch('VAR_UPDATE', nil)) Runner.find_specs(cfg.docs_include, cfg.docs_exclude, root).each do |spec_path| define_group(spec_path, root, loaded, store, update) end end |
.var_diff_error?(error) ⇒ Boolean
60 61 62 63 |
# File 'lib/oselvar/var/rspec.rb', line 60 def var_diff_error?(error) error.is_a?(Core::CellMismatchError) || error.is_a?(Core::DocStringMismatchError) || error.is_a?(Core::ReturnShapeError) || error.is_a?(Core::UnexpectedPassError) end |