Module: Thaum::Snapshot
- Defined in:
- lib/thaum/minitest.rb
Overview
Internal helpers — not part of the public API.
Class Method Summary collapse
- .compare(test:, actual:, path:, name:) ⇒ Object
- .path_for(name:, actual:) ⇒ Object
- .write(path:, actual:) ⇒ Object
Class Method Details
.compare(test:, actual:, path:, name:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/thaum/minitest.rb', line 40 def compare(test:, actual:, path:, name:) missing = !File.exist?(path) if missing || SnapshotMatcher.update_mode? write(path: path, actual: actual) warn "[Thaum] wrote new snapshot #{name} (#{path})" if missing test.assert(true) return end expected = File.read(path) test.assert_equal( expected, actual, "Snapshot \"#{name}\" mismatch (#{path}). " \ "Run with UPDATE_SNAPSHOTS=1 to rewrite if the new output is correct." ) end |
.path_for(name:, actual:) ⇒ Object
34 35 36 37 38 |
# File 'lib/thaum/minitest.rb', line 34 def path_for(name:, actual:) ext = actual.include?(SnapshotMatcher::ANSI_INDICATOR) ? "ans" : "txt" root = SnapshotMatcher::SNAPSHOT_ROOT_CANDIDATES.find { |d| Dir.exist?(d) } || "test/snapshots" File.join(root, "#{name}.#{ext}") end |
.write(path:, actual:) ⇒ Object
57 58 59 60 |
# File 'lib/thaum/minitest.rb', line 57 def write(path:, actual:) FileUtils.mkdir_p(File.dirname(path)) File.write(path, actual) end |