branch: elpa/buttercup commit 9d172a74373916f571f6fe3292bdc66cd3f28779 Merge: debe7cc 159fe3c Author: Ola Nilsson <ola.nils...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #145 from snogge/test-fixes Fix the tests that were reported as problematic in #144 --- tests/test-buttercup.el | 65 ++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el index b78c104..06dcce4 100644 --- a/tests/test-buttercup.el +++ b/tests/test-buttercup.el @@ -956,7 +956,11 @@ (it "should print the elapsed time for all specs" (dolist (state '(pending failed passed)) - (setq spec (make-buttercup-spec :description "spec" :status state :parent child-suite)) + (spy-calls-reset 'buttercup--print) + (setq spec (make-buttercup-spec :description "spec" + :parent child-suite + :status state + :failure-description "")) (buttercup--set-start-time spec) (buttercup--set-end-time spec) (let ((buttercup-reporter-batch--failures nil)) @@ -965,7 +969,7 @@ (expect (mapconcat (apply-partially #'apply #'format) (spy-calls-all-args 'buttercup--print) "") - :to-match "([0-9]+\\.[0-9]+\\(h\\|m\\|m?s\\))")))) + :to-match " ([0-9]+\\(\\.[0-9]+\\)?\\(h\\|m\\|m?s\\))\n$")))) (describe "on the suite-done event" (it "should emit a newline at the end of the top-level suite" @@ -996,36 +1000,41 @@ :to-throw))))) (describe "The `buttercup-run' function" - :var (buttercup-suites parent-suite child-suite spec) - (cl-flet (((reporter (event arg) (ignore event arg)))) - (before-each - (setq parent-suite (make-buttercup-suite :description "parent-suite") - child-suite (make-buttercup-suite :description "child-suite") - spec (make-buttercup-spec :description "spec") - buttercup-suites (list parent-suite)) - (buttercup-suite-add-child parent-suite child-suite) - (buttercup-suite-add-child child-suite spec) - (spy-on 'reporter)) - (it "should raise an error if at least one spec failed" - (setf (buttercup-spec-status spec) 'failed) - (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) - (buttercup-reporter 'reporter)) - (expect (buttercup-run) :to-throw))) - (it "should call the reporter twice with events buttercup-started and -done" - (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) - (buttercup-reporter 'reporter)) + :var (parent-suite child-suite spec reporter) + (before-each + (ignore reporter) + (setf (symbol-function 'reporter) (lambda (event arg) (ignore event arg))) + (setq parent-suite (make-buttercup-suite :description "parent-suite") + child-suite (make-buttercup-suite :description "child-suite") + spec (make-buttercup-spec :description "spec")) + (buttercup-suite-add-child parent-suite child-suite) + (buttercup-suite-add-child child-suite spec) + (spy-on 'reporter)) + (it "should raise an error if at least one spec failed" + (setf (buttercup-spec-status spec) 'failed) + (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) + (buttercup-reporter 'reporter)) + (let ((buttercup-suites (list parent-suite))) + (expect (buttercup-run) :to-throw)))) + (it "should call the reporter twice with events buttercup-started and -done" + (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) + (buttercup-reporter 'reporter)) + (let ((buttercup-suites (list parent-suite))) (expect (buttercup-run) :not :to-throw) (expect 'reporter :to-have-been-called-times 2) (expect 'reporter :to-have-been-called-with 'buttercup-started buttercup-suites) (expect 'reporter :to-have-been-called-with 'buttercup-done buttercup-suites))) - (it "should call `buttercup--run-suite once per suite" - (cl-flet (((runner (suite) (ignore suite)))) - (spy-on 'runner) - (cl-letf (((symbol-function 'buttercup--run-suite) #'runner) - (buttercup-reporter 'reporter) - (buttercup-suites (make-list 5 parent-suite))) - (expect (buttercup-run) :not :to-throw) - (expect 'runner :to-have-been-called-times 5)))))) + ) + (it "should call `buttercup--run-suite once per suite" + (let ((buttercup-suites (list parent-suite)) runner) + (ignore runner) + (setf (symbol-function 'runner) (lambda (suite) (ignore suite))) + (spy-on 'runner) + (cl-letf (((symbol-function 'buttercup--run-suite) #'runner) + (buttercup-reporter 'reporter) + (buttercup-suites (make-list 5 parent-suite))) + (expect (buttercup-run) :not :to-throw) + (expect 'runner :to-have-been-called-times 5))))) (describe "The `buttercup--print' function" (before-each