dragosmg commented on a change in pull request #12486:
URL: https://github.com/apache/arrow/pull/12486#discussion_r813352466



##########
File path: r/tests/testthat/test-duckdb.R
##########
@@ -15,11 +15,25 @@
 # specific language governing permissions and limitations
 # under the License.
 
-skip_if_not_installed("duckdb", minimum_version = "0.3.1")
-skip_if_not_installed("dbplyr")
 skip_if_not_available("dataset")
 skip_on_cran()
 
+# this test needs to be the first one since all other test blocks are skipped
+# if duckdb is not installed
+test_that("meaningful error message when duckdb is not installed", {
+  # skipping if duckdb is installed since we're testing the to_duckdb 
function's
+  # complaint when a user tries to call it, but duckdb isn't available
+  skip_if(requireNamespace("duckdb", quietly = TRUE))
+  ds <- InMemoryDataset$create(example_data)
+  expect_snapshot(
+    to_duckdb(ds),
+    error = TRUE
+  )

Review comment:
       `expect_error()` didn't seem to like the longer error message (it was 
failing even though the message matched). I could've maybe passed `fixed = 
TRUE` via the `...` (but I keep forgetting that argument exists).
   
   The `testthat` crew also recommend using `expect_snapshot()` for these sort 
of use-cases:
   > If you are using expect_error() to check that an error message is 
formatted in such a way that it makes sense to a human, we recommend using 
[expect_snapshot()](http://127.0.0.1:29237/help/library/testthat/help/expect_snapshot)
 instead.
   
   I'm not 100% opposed to using `expect_error()`, but I tend to favour 
snapshots since, at least from my point of view, they're more developer 
friendly.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to