You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ended up needing to do quite a bit of this in gargle, because of temp paths that vary, token hashes that vary by OS or R version, random backoff waiting times, etc.
Observations to guide implementation:
Sometimes you know the random or sensitive thing in advance (e.g. a temp path you've made and stored and used throughout the test). Then you can get away with sub(random_thing, replacement, snapshot_content, fixed = TRUE), which is nice.
More often, you need a regular expression. In fact, I often needed look ahead and look behind, so perl = TRUE needs to be possible.
Sometimes you need multiple replacements for 1 snapshot and they could be a mix of fixed string and regex.
Sometimes you are eliminating a matched expression, i.e. replacing with "".
One big bummer about the workaround is that the code in your snapshot ends up being completely uninformative (writeLines(out)), so you really have to rely on the test name (or use a more informative name than out). It will be much nicer to have this implemented properly in expect_snapshot().