Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sckott opened this issue Oct 8, 2024 · 0 comments
Open

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

sckott opened this issue Oct 8, 2024 · 0 comments

Comments

@sckott
Copy link
Collaborator

sckott commented Oct 8, 2024

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 = ""
    )
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant