From 7f15a1c91edaace0d3392138ebfb514f64c8dbb7 Mon Sep 17 00:00:00 2001 From: John Coene Date: Sat, 26 Mar 2022 19:35:18 +0100 Subject: [PATCH] test: serialiser #48 --- R/ambiorix.R | 7 +------ makefile | 3 +++ man/Ambiorix.Rd | 2 ++ tests/testthat/test-basic.R | 6 ++++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/ambiorix.R b/R/ambiorix.R index a2712a9..94a0620 100644 --- a/R/ambiorix.R +++ b/R/ambiorix.R @@ -208,6 +208,7 @@ Ambiorix <- R6::R6Class( #' if(interactive()) #' app$start() serialiser = function(handler){ + assert_that(is_function(handler)) options(AMBIORIX_SERIALISER = handler) invisible(self) }, @@ -238,12 +239,6 @@ Ambiorix <- R6::R6Class( } ), active = list( - websocket = function(value){ - if(missing(value)) - stop("This is a setter only") - - private$.wss <- value - }, port = function(value) { if(missing(value)) return(private$.port) diff --git a/makefile b/makefile index 75eb67d..2fd53eb 100644 --- a/makefile +++ b/makefile @@ -6,3 +6,6 @@ check: document document: Rscript -e "devtools::document()" + +test: + Rscript -e "devtools::test()" diff --git a/man/Ambiorix.Rd b/man/Ambiorix.Rd index c2774f5..36e4ce8 100644 --- a/man/Ambiorix.Rd +++ b/man/Ambiorix.Rd @@ -97,6 +97,8 @@ if(interactive()) \item{\code{error}}{500 response when the route errors, must a handler function that accepts the request and the response, by default uses \code{\link[=response_500]{response_500()}}.} +\item{\code{websocket}}{A handler function that accepts a websocket which overrides ambiorix internal websocket handling.} + \item{\code{on_stop}}{Callback function to run when the app stops, takes no argument.} } \if{html}{\out{}} diff --git a/tests/testthat/test-basic.R b/tests/testthat/test-basic.R index 5bcd137..c641bab 100644 --- a/tests/testthat/test-basic.R +++ b/tests/testthat/test-basic.R @@ -26,4 +26,10 @@ test_that("Ambiorix", { expect_s3_class(app$set_404(\(req, res) { res$send("Errr") }), "Ambiorix") + + expect_error(app$serialiser("error")) + expect_s3_class(app$serialiser(\(data) { + return("data") + }), "Ambiorix") + })