From 97d9392d5152b98b5f274652f5aa6d559f91fbb0 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 7 Dec 2022 07:27:55 -0800 Subject: [PATCH] Extract getting the latest commit message into a function If the way to get the commit message ever changes, or needs more post-processing, it's easy to be able to change it in just one place instead of everywhere. --- tests/git-auto-commit-mode-tests.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/git-auto-commit-mode-tests.el b/tests/git-auto-commit-mode-tests.el index 5ebb7b2..3dd8171 100644 --- a/tests/git-auto-commit-mode-tests.el +++ b/tests/git-auto-commit-mode-tests.el @@ -27,6 +27,10 @@ (require 'buttercup) (require 'git-auto-commit-mode) +(defun git-auto-commit-mode-tests--get-last-commit-message () + "Get the last commit message from git." + (shell-command-to-string "git log --format=format:%s")) + (describe "In a git repository" :var (temp-dir current-directory) @@ -55,7 +59,7 @@ (insert "test") (save-buffer)) - (expect (shell-command-to-string "git log --format=format:%s") + (expect (git-auto-commit-mode-tests--get-last-commit-message) :to-match (rx string-start "test" string-end))))) (describe "When ‘gac-automatically-add-new-files’ is nil" @@ -68,7 +72,7 @@ (insert "test") (save-buffer)) - (expect (shell-command-to-string "git log --format=format:%s") + (expect (git-auto-commit-mode-tests--get-last-commit-message) :not :to-match (rx string-start "test" string-end)))))) (describe "Getting a relative path" @@ -151,7 +155,7 @@ (insert "test") (save-buffer)) - (expect (shell-command-to-string "git log --format=format:%s") + (expect (git-auto-commit-mode-tests--get-last-commit-message) :to-equal "test.txt"))) (it "should use the message specified in ‘gac-default-message’" @@ -163,7 +167,7 @@ (insert "test") (save-buffer)) - (expect (shell-command-to-string "git log --format=format:%s") + (expect (git-auto-commit-mode-tests--get-last-commit-message) :to-equal "I made a commit!"))) (it "should use the function result if ‘gac-default-message’ is a function" @@ -177,7 +181,7 @@ (insert "test") (save-buffer)) - (expect (shell-command-to-string "git log --format=format:%s") + (expect (git-auto-commit-mode-tests--get-last-commit-message) :to-equal "wip test.txt"))))) (provide 'git-auto-commit-mode-tests)