Skip to content

Commit

Permalink
Improve snapshot mismatch error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 committed Aug 7, 2023
1 parent 3a9b830 commit a691632
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package org.spockframework.specs.extension

import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.opentest4j.AssertionFailedError
import org.spockframework.runtime.Condition
import org.spockframework.runtime.ConditionNotSatisfiedError
import org.spockframework.runtime.model.IterationInfo
import org.spockframework.runtime.model.TextPosition

import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -67,13 +71,14 @@ class Snapshotter {

void matchesSnapshot() {
String snapshotValue = loadSnapshot()
try {
assert value == snapshotValue
} catch (AssertionError e) {
if (!Objects.equals(value, snapshotValue)) {
if (updateSnapshots) {
saveSnapshot(value)
} else {
throw e
// manually construct a ConditionNotSatisfiedError, as the native groovy assert doesn't get properly rendered by Intellij
throw new ConditionNotSatisfiedError(
new Condition([value, snapshotValue] as List<Object>, 'value == snapshotValue', TextPosition.create(-1, -1), null, null, null)
)
}
}
}
Expand Down

0 comments on commit a691632

Please sign in to comment.