Scrubbers

Introduction

Scrubber Overview

Scrubber Overview

If you are having trouble getting tests running reproducibly, you might need to use a “scrubber” to convert the non-deterministic text to something stable.

Interface

Fundamentally, a scrubber is function that takes a string and returns a string. You can create ones by passing in a function or a lambda. We also have some pre-made ones for your convenience.

How to use Scrubbers

You can scrub text manually, before passing it in to Approvals::verify(), but the preferred method is to include a Scrubber as an option.

ApprovalTests::Approvals::verify(input,
                                 ApprovalTests::Options().withScrubber(scrubber));

(See snippet source)

Scrubber concepts

There are several patterns that are commonly used when scrubbing:

  • Replace troublesome text

  • Replace troublesome text, tracking duplicates

  • Combining scrubbers

  • Deleting troublesome lines