1
+ (require 'buttercup )
1
2
(require 'cider )
2
3
(require 'cider-client )
3
- (require 'ert )
4
4
5
5
; ;; cider-client tests
6
6
@@ -19,97 +19,146 @@ SYMBOL is locally let-bound to the current buffer."
19
19
(, symbol (current-buffer )))
20
20
,@body )))
21
21
22
- (ert-deftest cider-current-connection-nil-case ()
23
- (let ((cider-connections nil ))
24
- (should-not (cider-current-connection))
25
- (should-not (cider-current-connection " clj" ))
26
- (should-not (cider-current-connection " cljs" ))))
27
-
28
- (ert-deftest cider-current-connection-follow-type-argument ()
29
- (with-connection-buffer " clj" b1
30
- (should (equal (cider-current-connection) b1))
31
- (should (equal (cider-current-connection " clj" ) b1))
32
- (should-not (cider-current-connection " cljs" ))
33
- (with-connection-buffer " cljs" b2
34
- (should (equal (cider-current-connection) b2))
35
- (should (equal (cider-current-connection " cljs" ) b2))
36
- (should (equal (cider-current-connection " clj" ) b1))
37
- (with-connection-buffer " cljs" b3
38
- (should (equal (cider-current-connection) b3))
39
- (should (equal (cider-current-connection " cljs" ) b3))
40
- (should (equal (cider-current-connection " clj" ) b1)))
41
- (with-connection-buffer " clj" b4
42
- (should (equal (cider-current-connection) b4))
43
- (should (equal (cider-current-connection " cljs" ) b2))
44
- (should (equal (cider-current-connection " clj" ) b4))))))
45
-
46
- (ert-deftest cider-current-connection-follow-file-extension ()
47
- ; ; A single connection buffer.
48
- (with-connection-buffer " clj" b1
49
- (with-temp-buffer
50
- (setq major-mode 'clojure-mode )
51
- (should (equal (cider-current-connection) b1))
52
- (should (equal (cider-current-connection " clj" ) b1))
53
- (should-not (cider-current-connection " cljs" )))
54
- (with-temp-buffer
55
- ; ; No cljs repl exists, but the TYPE argument is nil, so the
56
- ; ; next-best-thing is returned.
57
- (setq major-mode 'clojurescript-mode )
58
- (should (equal (cider-current-connection) b1))
59
- (should (equal (cider-current-connection " clj" ) b1))
60
- (should-not (cider-current-connection " cljs" ))))
61
- (with-connection-buffer " cljs" b1
62
- (with-temp-buffer
63
- (setq major-mode 'clojure-mode )
64
- ; ; No clj repl exists, but the TYPE argument is nil, so the
65
- ; ; next-best-thing is returned.
66
- (should (equal (cider-current-connection) b1))
67
- (should (equal (cider-current-connection " cljs" ) b1))
68
- (should-not (cider-current-connection " clj" )))
69
- (with-temp-buffer
70
- (setq major-mode 'clojurescript-mode )
71
- (should (equal (cider-current-connection) b1))
72
- (should (equal (cider-current-connection " cljs" ) b1))
73
- (should-not (cider-current-connection " clj" ))))
74
- ; ; Multiple connection buffers.
75
- (with-connection-buffer " clj" bb1
76
- (with-connection-buffer " cljs" bb2
77
- ; ; The two buffers above are not used. We just want to ensure we are
78
- ; ; returning the most recent connection in case of ambiguity.
22
+
23
+ (describe " cider-current-connection"
24
+
25
+ (describe " when there are no active connections"
26
+ :var (cider-connections)
27
+ (it " returns nil"
28
+ (setq cider-connections nil )
29
+ (expect (cider-current-connection) :not :to-be-truthy )
30
+ (expect (cider-current-connection " clj" ) :not :to-be-truthy )
31
+ (expect (cider-current-connection " cljs" ) :not :to-be-truthy )))
32
+
33
+
34
+ (describe " when active connections are available"
35
+
36
+ (it " always returns the latest connection"
37
+ (with-connection-buffer " clj" bb1
38
+ (with-connection-buffer " cljs" bb2
39
+ (with-connection-buffer " clj" b1
40
+ (with-connection-buffer " cljs" b2
41
+ (expect (cider-current-connection) :to-equal b2)
42
+
43
+ ; ; follows type arguments
44
+ (expect (cider-current-connection " clj" ) :to-equal b1)
45
+ (expect (cider-current-connection " cljs" ) :to-equal b2)
46
+
47
+ ; ; follows file type
48
+ (with-temp-buffer
49
+ (setq major-mode 'clojure-mode )
50
+ (expect (cider-current-connection) :to-equal b1))
51
+
52
+ (with-temp-buffer
53
+ (setq major-mode 'clojurescript-mode )
54
+ (expect (cider-current-connection) :to-equal b2)))))))
55
+
56
+ (describe " when type argument is given"
57
+ (describe " when connection of that type exists"
58
+ (it " returns that connection buffer"
59
+ ; ; for clj
60
+ (with-connection-buffer " clj" b1
61
+ (with-connection-buffer " cljs" b2
62
+ (expect (cider-current-connection " clj" ) :to-equal b1)))
63
+ ; ; for cljs
64
+ (with-connection-buffer " cljs" b1
65
+ (with-connection-buffer " clj" b2
66
+ (expect (cider-current-connection " cljs" ) :to-equal b1)))))
67
+
68
+ (describe " when connection of that type doesn't exists"
69
+ (it " returns nil"
70
+ ; ; for clj
71
+ (with-connection-buffer " cljs" b1
72
+ (expect (cider-current-connection " clj" ) :to-equal nil ))
73
+
74
+ ; ; for cljs
75
+ (with-connection-buffer " clj" b2
76
+ (expect (cider-current-connection " cljs" ) :to-equal nil )))))
77
+
78
+ (describe " when type argument is not given"
79
+ (describe " when a connection matching current file extension exists"
80
+ (it " returns that connection buffer"
81
+ ; ; for clj
82
+ (with-connection-buffer " clj" b1
83
+ (with-connection-buffer " cljs" b2
84
+ (with-temp-buffer
85
+ (setq major-mode 'clojure-mode )
86
+ (expect (cider-current-connection) :to-equal b1))))
87
+
88
+ ; ; for cljs
89
+ (with-connection-buffer " cljs" b1
90
+ (with-connection-buffer " clj" b2
91
+ (with-temp-buffer
92
+ (setq major-mode 'clojurescript-mode )
93
+ (expect (cider-current-connection) :to-equal b1))))))
94
+
95
+ (describe " when a connection matching current file extension doesn't exist"
96
+ (it " returns the latest connection buffer"
97
+ ; ; for clj
98
+ (with-connection-buffer " clj" b1
99
+ (with-temp-buffer
100
+ (setq major-mode 'clojurescript-mode )
101
+ (expect (cider-current-connection) :to-equal b1)))
102
+
103
+ ; ; for cljs
104
+ (with-connection-buffer " cljs" b2
105
+ (with-temp-buffer
106
+ (setq major-mode 'clojure-mode )
107
+ (expect (cider-current-connection) :to-equal b2))))))))
108
+
109
+
110
+ (describe " cider-other-connection"
111
+ (describe " when there are no active connections"
112
+ :var (cider-connections)
113
+ (it " returns nil"
114
+ (setq cider-connections nil )
115
+ (expect (cider-other-connection) :to-equal nil )))
116
+
117
+ (describe " when there is only 1 active connection"
118
+ (it " returns nil"
119
+ ; ; for clj
79
120
(with-connection-buffer " clj" b1
80
- (with-connection-buffer " cljs" b2
81
- (with-temp-buffer
82
- (setq major-mode 'clojure-mode )
83
- ; ; TYPE argument is nil, a clj connection exists and we're in
84
- ; ; clojure-mode, so we return the clj connection even though the top
85
- ; ; connection is cljs.
86
- (should (equal (cider-current-connection) b1))
87
- (should (equal (cider-current-connection " clj" ) b1))
88
- (should (equal (cider-current-connection " cljs" ) b2)))
89
- (with-temp-buffer
90
- (setq major-mode 'clojurescript-mode )
91
- ; ; A cljs repl exists, and the TYPE argument is nil.
92
- (should (equal (cider-current-connection) b2))
93
- (should (equal (cider-current-connection " clj" ) b1))
94
- (should (equal (cider-current-connection " cljs" ) b2))))))))
95
-
96
- (ert-deftest cider-other-connection ()
97
- (let ((cider-connections nil ))
98
- (should-not (cider-other-connection))
99
- (with-connection-buffer " clj" b1
100
- (should-not (cider-other-connection))
101
- (should-not (cider-other-connection b1))
102
- (with-connection-buffer " cljs" b2
103
- (should (equal (cider-other-connection) b1))
104
- (should (equal (cider-other-connection b1) b2))
105
- (should (equal (cider-other-connection b2) b1))
106
- (with-connection-buffer " cljs" b3
107
- (should (equal (cider-other-connection) b1))
108
- (should (equal (cider-other-connection b1) b3))
109
- (should (equal (cider-other-connection b3) b1))
110
- (should (equal (cider-other-connection b2) b1)))
111
- (with-connection-buffer " clj" b4
112
- (should (equal (cider-other-connection) b2))
113
- (should (equal (cider-other-connection b4) b2))
114
- (should (equal (cider-other-connection b2) b4))
115
- (should (equal (cider-other-connection b1) b2)))))))
121
+ (expect (cider-other-connection) :to-equal nil )
122
+ (expect (cider-other-connection b1) :to-equal nil ))
123
+ ; ; for cljs
124
+ (with-connection-buffer " cljs" b1
125
+ (expect (cider-other-connection) :to-equal nil )
126
+ (expect (cider-other-connection b1) :to-equal nil ))))
127
+
128
+ (describe " when active connections are available"
129
+ (describe " when a connection of other type doesn't exist"
130
+ (it " returns nil"
131
+ ; ; for clj
132
+ (with-connection-buffer " clj" b1
133
+ (with-connection-buffer " clj" b2
134
+ (expect (cider-other-connection) :to-equal nil )
135
+ (expect (cider-other-connection b1) :to-equal nil )
136
+ (expect (cider-other-connection b2) :to-equal nil )))
137
+ ; ; for cljs
138
+ (with-connection-buffer " cljs" b1
139
+ (with-connection-buffer " cljs" b2
140
+ (expect (cider-other-connection) :to-equal nil )
141
+ (expect (cider-other-connection b1) :to-equal nil )
142
+ (expect (cider-other-connection b2) :to-equal nil )))))
143
+
144
+ (describe " when a connection of other type exists"
145
+ (it " returns that connection"
146
+ (with-connection-buffer " clj" b1
147
+ (with-connection-buffer " cljs" b2
148
+ (expect (cider-other-connection) :to-equal b1)
149
+ (expect (cider-other-connection b1) :to-equal b2)
150
+ (expect (cider-other-connection b2) :to-equal b1)))))
151
+
152
+ (describe " when there are multiple active connections"
153
+ (it " always returns the latest connection"
154
+
155
+ (with-connection-buffer " clj" bb1
156
+ (with-connection-buffer " cljs" bb2
157
+ (with-connection-buffer " clj" b1
158
+ (with-connection-buffer " cljs" b2
159
+ (expect (cider-other-connection) :to-equal b1)
160
+ (expect (cider-other-connection b1) :to-equal b2)
161
+ (expect (cider-other-connection b2) :to-equal b1)
162
+ ; ; older connections still work
163
+ (expect (cider-other-connection bb1) :to-equal b2)
164
+ (expect (cider-other-connection bb2) :to-equal b1)))))))))
0 commit comments