Use with-simulated-input for tests
This commit is contained in:
parent
2475965b80
commit
8aada5b29a
3 changed files with 37 additions and 6 deletions
1
Eask
1
Eask
|
|
@ -15,4 +15,5 @@
|
||||||
(depends-on "counsel")
|
(depends-on "counsel")
|
||||||
|
|
||||||
(development
|
(development
|
||||||
|
(depends-on "with-simulated-input")
|
||||||
(depends-on "buttercup"))
|
(depends-on "buttercup"))
|
||||||
|
|
|
||||||
|
|
@ -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)."
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue