Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-14458

[R] Use expect_snapshot() to improve tests

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Later
    • None
    • 9.0.0
    • R

    Description

      Update (2022, January 20):
      Hadley's suggestion would be to move away from the

      expect_snapshot({
        (expect_error())
      }) 
      

      pattern and use one of 3 options:

       

      • If you want to inspect the error message, use expect_snapshot(error = TRUE).
      • If you want to check the class, use expect_error(class = )
      • If you want to expect the message and check the class, use expect_snapshot_error(class = ).

      I have being using option 1 and it seems to do most of what we want. For example, see the left_join by arg PR.

      ==============
      This comes from Romain's suggestion to transform the test that rely on capturing a string by using a snapshot test (added in testthat's 3rd edition).

      A test like:

      expect_error(expression, message)
      

      becomes

      expect_snapshot({
        (expect_error(expression))
      })
      

      This is probably a more general improvement we can make to our unit tests (i.e. to make more extensive use of the snapshot functionality), but I thought I'd focus on one test file to begin with.

      Attachments

        Issue Links

          Activity

            People

              dragosmg Dragoș Moldovan-Grünfeld
              dragosmg Dragoș Moldovan-Grünfeld
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 8h 10m
                  8h 10m