ApprovalTests.Java icon indicating copy to clipboard operation
ApprovalTests.Java copied to clipboard

Scrubbers not enabled for verifyXml

Open emilybache opened this issue 5 years ago • 2 comments

I have this exercise where I'm using verifyXml:

github.com/emilybache/Product-Export-Refactoring-Kata

If you look at the 'with_tests' branch in the java version the fourth test 'exportHistory' works and passes with this code:

@Test
    public void exportHistory() throws Exception {
        Collection<Order> orders = Arrays.asList(RecentOrder, OldOrder);
        String xml = XMLExporter.exportHistory(orders);
        String regex = "createdAt='[^']+'";
        xml = xml.replaceFirst(regex, "createdAt='2018-09-20T00:00Z'");
        Approvals.verifyXml(xml);
    }

I would like to be able to use a scrubber like this:

    Approvals.verifyXml(xml, new Options(new RegExScrubber("createdAt='[^']+'", "createdAt='2018-09-20T00:00Z'")));

Unfortunately that code does not work.

emilybache avatar Jan 08 '21 07:01 emilybache

I investigated a bit. The problem is that we transform&pretty-print the input string before applying the scrubber and this step changes the ' to ". So by the time we scrub, the pattern doesn't find any matches anymore.

I wrote a quick fix and will discuss it with @isidore on Monday night. :)

LarsEckart avatar Jan 09 '21 09:01 LarsEckart

Thankyou! I hadn't realized the regex could be adjusted to make this actually work. I guess what I'd really like is for an xml aware scrubber that you could give an xpath and it would scrub the piece of xml the xpath refers to. Since we're parsing the xml in order to pretty print it, I would have thought this should be possible?

emilybache avatar Jan 11 '21 07:01 emilybache