Make use of the ‘:var’ and ‘before|after-each’ forms of buttercup
This removes a bit of boiler-plate code from the tests, hopefully making them easier to read and write.
This commit is contained in:
parent
e2c939cb8e
commit
d4fd943206
1 changed files with 104 additions and 130 deletions
|
@ -27,146 +27,120 @@
|
|||
(require 'buttercup)
|
||||
(require 'git-auto-commit-mode)
|
||||
|
||||
(defun git-auto-commit-tests-setup-git ()
|
||||
(describe "In a git repository"
|
||||
:var (temp-dir current-directory)
|
||||
|
||||
(before-each
|
||||
(setq temp-dir (make-temp-file "gac-" t)
|
||||
current-directory default-directory
|
||||
default-directory temp-dir)
|
||||
(shell-command "git init")
|
||||
(shell-command "git config user.email user@example.com")
|
||||
(shell-command "git config user.name \"User Example\""))
|
||||
|
||||
(after-each
|
||||
(delete-directory temp-dir t)
|
||||
(setq temp-dir nil
|
||||
default-directory current-directory
|
||||
current-directory nil))
|
||||
|
||||
(describe "New files"
|
||||
(describe "When ‘gac-automatically-add-new-files’ is t"
|
||||
(it "Should be added to git"
|
||||
(let* ((gac-automatically-add-new-files-p t)
|
||||
(temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "test" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (shell-command-to-string "git log --format=format:%s")
|
||||
:to-match (rx string-start "test" string-end)))
|
||||
(delete-directory temp-dir t)))))
|
||||
:to-match (rx string-start "test" string-end)))))
|
||||
|
||||
(describe "When ‘gac-automatically-add-new-files’ is nil"
|
||||
(it "Shouldn’t be added to git"
|
||||
(let* ((gac-automatically-add-new-files-p nil)
|
||||
(temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "test" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (shell-command-to-string "git log --format=format:%s")
|
||||
:not :to-match (rx string-start "test" string-end)))
|
||||
(delete-directory temp-dir t))))))
|
||||
:not :to-match (rx string-start "test" string-end))))))
|
||||
|
||||
(describe "Getting a relative path"
|
||||
(it "should return the file name for files in the project root"
|
||||
(let* ((temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "test" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(let* ((temp-file (expand-file-name "test" temp-dir))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (gac-relative-file-name temp-file)
|
||||
:to-equal "test"))
|
||||
(delete-directory temp-dir t))))
|
||||
:to-equal "test")))
|
||||
|
||||
(it "should return the file name and directory name for nested files"
|
||||
(let* ((temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "test/test.txt" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(mkdir (expand-file-name "test" temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
|
||||
(let* ((temp-file (expand-file-name "test/test.txt" temp-dir))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (gac-relative-file-name temp-file)
|
||||
:to-equal "test/test.txt"))
|
||||
(delete-directory temp-dir t))))
|
||||
:to-equal "test/test.txt")))
|
||||
|
||||
(it "should handle ‘[]’ in the filename"
|
||||
(let* ((temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "[test]-test.txt" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(let* ((temp-file (expand-file-name "[test]-test.txt" temp-dir))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (gac-relative-file-name temp-file)
|
||||
:to-equal "[test]-test.txt"))
|
||||
(delete-directory temp-dir t))))
|
||||
:to-equal "[test]-test.txt")))
|
||||
|
||||
(it "should handle ‘[]’ in the directory name"
|
||||
(let* ((temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "[test]-test/testing.txt" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(mkdir (expand-file-name "[test]-test" temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
|
||||
(let* ((temp-file (expand-file-name "[test]-test/testing.txt" temp-dir))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (gac-relative-file-name temp-file)
|
||||
:to-equal "[test]-test/testing.txt"))
|
||||
(delete-directory temp-dir t))))
|
||||
:to-equal "[test]-test/testing.txt")))
|
||||
|
||||
(it "should handle ‘[’ in the directory name"
|
||||
(let* ((temp-dir (make-temp-file "gac-[test-" t))
|
||||
(temp-file (expand-file-name "testing.txt" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(let* ((temp-file (expand-file-name "testing.txt" temp-dir))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (gac-relative-file-name temp-file)
|
||||
:to-equal "testing.txt"))
|
||||
(delete-directory temp-dir t))))
|
||||
:to-equal "testing.txt")))
|
||||
|
||||
(it "should handle ‘[’ in the file name"
|
||||
(let* ((temp-dir (make-temp-file "gac-" t))
|
||||
(temp-file (expand-file-name "[test-test.txt" temp-dir))
|
||||
(default-directory temp-dir))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(git-auto-commit-tests-setup-git)
|
||||
(let ((buffer (find-file-noselect temp-file)))
|
||||
(let* ((temp-file (expand-file-name "[test-test.txt" temp-dir))
|
||||
(buffer (find-file-noselect temp-file)))
|
||||
(with-current-buffer buffer
|
||||
(git-auto-commit-mode)
|
||||
(insert "test")
|
||||
(save-buffer)))
|
||||
(save-buffer))
|
||||
|
||||
(expect (gac-relative-file-name temp-file)
|
||||
:to-equal "[test-test.txt"))
|
||||
(delete-directory temp-dir t)))))
|
||||
:to-equal "[test-test.txt")))))
|
||||
|
||||
(provide 'git-auto-commit-mode-tests)
|
||||
;;; git-auto-commit-mode-tests.el ends here
|
||||
|
|
Loading…
Reference in a new issue