Skip to content

Make it easy to get count of calls matching a given stub #128

@sckott

Description

@sckott

seems quite easy with python's pook (mock.calls), see first example block at https://github.com/h2non/pook?tab=readme-ov-file#examples

in this package, perhaps something like

# use a function so user doesn't have to figure out the 
# incantation for the R6 object
call_count <- function(stub) {
    stub$counter$count()
}

# possibly use the last stub used by default? but would have to show
# the stub then (`last_stub_used` doesn't exist yet)
call_count <- function(stub = last_stub_used()) {
    stub$counter$count()
}

# optionally just give back counts for all stubs if `stub` is `NULL`?
# this uses cli so would have to add that dep, but it doesn't have deps itself
call_count <- function(stub = NULL) {
  reg <- stub_registry()
  stubs <- reg$request_stubs
  cli_alert_info(style_underline(style_bold("count --- stub")))
  for (stub in stubs) {
    cat(
      symbol$info, " ",
      style_bold(stub$counter$count()), " --- ",
      stub$to_s(), "\n",
      sep = ""
    )
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions