Browse Source

Fix mocking a server's connection

Previous code was not good enough because if the code called
`(libmpdel-ensure-connection)`, a connection would be created even if
the code is wrapped in `(libmpdel-test--with-connection ...)`.
tags/v1.1.2
Damien Cassou 4 months ago
parent
commit
15e7a18b13
Signed by: DamienCassou <damien@cassou.me> GPG Key ID: B68746238E59B548
1 changed files with 11 additions and 2 deletions
  1. +11
    -2
      test/libmpdel-test.el

+ 11
- 2
test/libmpdel-test.el View File

@@ -129,13 +129,14 @@
(defmacro libmpdel-test--with-connection (&rest body)
"Execute BODY within a new fake MPD connection."
`(let ((libmpdel--msghandlers (list))
(libmpdel--connection (list))
(commands (list))
(log (list)))
(cl-letf (((symbol-function 'libmpdel--log)
(lambda (string type-string) (setq log (append log (list (cons string type-string))))))
((symbol-function 'libmpdel--raw-send-command)
(lambda (command) (setq commands (append commands (list command))))))
(lambda (command) (setq commands (append commands (list command)))))
((symbol-function 'libmpdel-connected-p)
(lambda () t)))
,@body)))

(ert-deftest libmpdel-test--raw-send-command-with-handler-with-a-string ()
@@ -326,6 +327,14 @@
(should (not (libmpdel-equal song1 song2)))
(should (not (libmpdel-equal song2 song1)))))

(ert-deftest libmpdel-test-playlist-add-artist-to-stored-playlist ()
(libmpdel-test--with-connection
(let ((artist (libmpdel--artist-create :name "The Artist"))
(playlist (libmpdel--stored-playlist-create :name "the playlist")))
(libmpdel-playlist-add artist playlist)
(should (equal (car (last commands))
"searchaddpl \"the playlist\" artist \"The Artist\"")))))

(provide 'libmpdel-test)
;;; libmpdel-test.el ends here



Loading…
Cancel
Save