tests/testthat/test_func_decoration.R

library(jug)

context("testing function decorator")





test_that("The correct response is returned by a decorated function (using a querystring value)",{
  test_req<-RawTestRequest$new()
  test_req$query_string("?x=test")

  my_func<-function(x){x}

  res<-jug() %>%
    get("/", decorate(my_func)) %>%
    process_test_request(test_req$req)

  expect_equal(res$body, "test")

})

test_that("The correct response is returned by a decorated function (using a querystring value) also when content-type is NULL",{
  test_req<-RawTestRequest$new()
  test_req$req$CONTENT_TYPE <- NULL
  test_req$query_string("?x=test")

  my_func<-function(x){x}

  res<-jug() %>%
    get("/", decorate(my_func)) %>%
    process_test_request(test_req$req)

  expect_equal(res$body, "test")

})

test_that("The correct response is returned by a decorated function (using a header value)",{
  test_req<-RawTestRequest$new()
  test_req$set_header("x", "test")

  my_func<-function(x){x}

  res<-
    jug() %>%
    get("/", decorate(my_func)) %>%
    process_test_request(test_req$req)

  expect_equal(res$body, "test")

})

Try the jug package in your browser

Any scripts or data that you put into this service are public.

jug documentation built on May 1, 2019, 10:31 p.m.