Package 'mochita'

Title: Test R Web Applications
Description: Write so-called 'Integration Tests' for your R web applications by declaring an HTTP request and the expectations its response should meet.
Authors: Julio Collazos [aut, cre], supertest contributors [ctb, cph] (authors listed in <https://github.com/forwardemail/supertest/graphs/contributors>)
Maintainer: Julio Collazos <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2026-09-22 11:04:18 UTC
Source: https://github.com/juliocollazos64/mochita

Help Index


Test an HTTP server

Description

mochita() builds the specification for testing an httpuv app. It returns a Mochita object whose methods can be chained together to build up a request, describe the expectations it should meet, and finally send it with ⁠$perform()⁠.

Usage

mochita(app)

Arguments

app

App definition, see httpuv::startServer.

Value

A Mochita R6 class object.

Mochita Methods

A Mochita is an R6 Class with the following methods:

  • ⁠$get(path)⁠, ⁠$head(path)⁠, ⁠$post(path)⁠, ⁠$put(path)⁠, ⁠$delete(path)⁠, ⁠$connect(path)⁠, ⁠$options(path)⁠, ⁠$trace(path)⁠, ⁠$patch(path)⁠ Set the HTTP Method and path of the request.

  • ⁠$set(name,value)⁠ Set a request header.

  • ⁠$expect()⁠ Add an expectation to check against the response, once performed. Accepts a status code (optionally with a body to match), a header name/value pair, a body to match, or a custom function taking the response.

  • ⁠$perform()⁠ Send the request and run the recorded expectations against the response.

Examples

## Not run: 
mochita(app)$get("/")$
  set("Accept", "text/plain")$
  expect(200)$
  expect("Content-Type", "text/plain")$
  perform()

## End(Not run)