Use with-simulated-input for tests
All checks were successful
/ Test on 28.2 (push) Successful in 3m27s
/ Test on 29.1 (push) Successful in 3m32s
/ Test on snapshot (push) Successful in 6m19s

This commit is contained in:
Maciej 2024-08-18 19:02:36 +03:00
parent 2475965b80
commit 8aada5b29a
Signed by: maciej
GPG key ID: 41D62D42D3B0D765
3 changed files with 37 additions and 6 deletions

1
Eask
View file

@ -15,4 +15,5 @@
(depends-on "counsel") (depends-on "counsel")
(development (development
(depends-on "with-simulated-input")
(depends-on "buttercup")) (depends-on "buttercup"))

View file

@ -58,7 +58,7 @@
with default value ACTION, to be used as `:action' parameter for with default value ACTION, to be used as `:action' parameter for
COMMAND's `ivy-read' call. COMMAND's `ivy-read' call.
This variable holds either a single action function, or an action ;; This variable holds either a single action function, or an action
list whose first element is the index of the default action in list whose first element is the index of the default action in
the list and the remaining elements are the actions (a key, a the list and the remaining elements are the actions (a key, a
function, and a name for each action)." function, and a name for each action)."

View file

@ -1,13 +1,43 @@
;;; test-counsel-projectile.el --- Buttercup tests for counsel-projectile -*- lexical-binding: t; -*- ;;; test-counsel-projectile.el --- Buttercup tests for counsel-projectile -*- lexical-binding: t; -*-
;;; Commentary: ;;; Commentary:
;;; Code: ;;; Code:
(require 'with-simulated-input)
(require 'buttercup)
(require 'counsel-projectile) (require 'counsel-projectile)
;; Example test! ;; Example test!
(describe "A suite" (describe "counsel-projectile-switch-project with a mock"
(it "contains a spec with an expectation" (before-each
(expect counsel-projectile--buffers :to-be nil))) (spy-on 'ivy-read)
(spy-on 'projectile-project-root :and-return-value "/usr/fake-project")
(setq
projectile-known-projects '("/usr/fake-project" "~/some-project")
counsel-projectile-switch-project-action 'counsel-projectile-switch-project-action))
(it "spies on ivy-read arguments"
(counsel-projectile-switch-project)
(expect 'projectile-project-root :to-have-been-called)
(expect 'ivy-read :to-have-been-called-with
"[fake-project] Switch to project: "
'("/usr/fake-project" "~/some-project")
:preselect "/usr/fake-project"
:action counsel-projectile-switch-project-action
:require-match t
:sort nil
:caller 'counsel-projectile-switch-project)))
(describe "counsel-projectile-switch-project with the real ivy-read"
(before-each
(spy-on 'projectile-project-root :and-return-value "/usr/fake-project")
(setq
counsel-projectile-switch-project-action 'counsel-projectile-switch-project-action))
(it "signals error when project is unknown"
(expect
(with-simulated-input "/usr/fake RET"
(condition-case err
(counsel-projectile-switch-project)
(file-missing
(error-message-string err))))
:to-equal "Setting current directory: No such file or directory, /usr/fake-project")))
;;; test-counsel-projectile.el ends here ;;; test-counsel-projectile.el ends here