Skip to content

Commit 2fcc251

Browse files
committed
Handle the absence of a connection in cider-find-ns
This commit also adds a few tests for connection & op presence. We should have such tests for all similar commands.
1 parent 6201fcb commit 2fcc251

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cider-interaction.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ Invert meaning of `cider-prompt-for-symbol' if PREFIX indicates it should be."
451451
A prefix ARG of `-` or a double prefix argument causes
452452
the results to be displayed in a different window."
453453
(interactive "P")
454+
(cider-ensure-connected)
454455
(cider-ensure-op-supported "ns-path")
455456
(if ns
456457
(cider--find-ns ns)

test/cider-tests.el

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,39 @@
710710
(should (string= (cider-refcard-url) "https://github.com/clojure-emacs/cider/raw/v0.11.0/doc/cider-refcard.pdf")))
711711
(let ((cider-version "0.11.0-snapshot"))
712712
(should (string= (cider-refcard-url) "https://github.com/clojure-emacs/cider/raw/master/doc/cider-refcard.pdf"))))
713+
714+
(ert-deftest cider-ensure-connected ()
715+
(noflet ((cider-connected-p () t))
716+
(should-not (cider-ensure-connected)))
717+
(noflet ((cider-connected-p () nil))
718+
(should-error (cider-ensure-connected) :type 'user-error)))
719+
720+
(ert-deftest cider-ensure-op-supported ()
721+
(noflet ((cider-nrepl-op-supported-p (op) t))
722+
(should-not (cider-ensure-op-supported "foo")))
723+
(noflet ((cider-nrepl-op-supported-p (op) nil))
724+
(should-error (cider-ensure-op-supported "foo") :type 'user-error)))
725+
726+
(ert-deftest cider-refresh-not-connected ()
727+
(noflet ((cider-connected-p () nil))
728+
(should-error (cider-refresh) :type 'user-error)))
729+
730+
(ert-deftest cider-classpath-not-connected ()
731+
(noflet ((cider-connected-p () nil))
732+
(should-error (cider-classpath) :type 'user-error)))
733+
734+
(ert-deftest cider-quit-not-connected ()
735+
(noflet ((cider-connected-p () nil))
736+
(should-error (cider-quit) :type 'user-error)))
737+
738+
(ert-deftest cider-restart-not-connected ()
739+
(noflet ((cider-connected-p () nil))
740+
(should-error (cider-restart) :type 'user-error)))
741+
742+
(ert-deftest cider-find-ns-not-connected ()
743+
(noflet ((cider-connected-p () nil))
744+
(should-error (cider-find-ns) :type 'user-error)))
745+
746+
(ert-deftest cider-find-ns-unsupported-op ()
747+
(noflet ((cider-ensure-op-supported (op) nil))
748+
(should-error (cider-find-ns) :type 'user-error)))

0 commit comments

Comments
 (0)