File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
snapshot-matcher/src/main/java/com/zenika/snapshotmatcher Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 22
22
import difflib .Patch ;
23
23
24
24
public class SnapshotMatcher <T > extends TypeSafeMatcher <T > {
25
+
26
+ private static final String SNAPSHOT_WRITE_VARIABLE = "test.snapshots.write" ;
27
+
25
28
/**
26
29
* Factory method to instantiate a snapshot matcher with the given type
27
30
*
@@ -48,11 +51,14 @@ public boolean matchesSafely(T o) {
48
51
if (Files .exists (snapshotPath )) {
49
52
// File exists => Compare snapshot file to given object
50
53
return compareSnapshot (o , snapshotPath );
51
- } else {
54
+ } else if ( isWriteSnapshotActivated ()) {
52
55
// File doesn't exist => Create snapshot file and return true
53
56
createSnapshot (o , snapshotPath );
54
57
return true ;
55
58
}
59
+ System .out .println ("Snapshot writing is not activated in this environment." );
60
+ System .out .println ("Activate snapshot writing by using -D" + SNAPSHOT_WRITE_VARIABLE );
61
+ return false ;
56
62
}
57
63
58
64
/**
@@ -153,4 +159,7 @@ private StackTraceElement getCaller() {
153
159
.orElse (null );
154
160
}
155
161
162
+ private boolean isWriteSnapshotActivated () {
163
+ return System .getProperty (SNAPSHOT_WRITE_VARIABLE ) != null ;
164
+ }
156
165
}
You can’t perform that action at this time.
0 commit comments