branch: elpa/buttercup commit 1c50a80f2799dacc8331c76277f11b4875bf4fea Author: Ola Nilsson <ola.nils...@gmail.com> Commit: Jorgen Schäfer <jorgen.schae...@gmail.com>
Fix the buttercup-run tests Let-binding the buttercup-reporter in the suite did not work, the suites and specs used as test data were reported by the main buttercup-reporter. Move the let-binding into the specs instead. Use cl-flet to define local reporter and runner functions. Make the runner function local to the final spec for buttercup-run. --- tests/test-buttercup.el | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el index 20324c4..5a660e6 100644 --- a/tests/test-buttercup.el +++ b/tests/test-buttercup.el @@ -991,12 +991,8 @@ :to-throw))))) (describe "The `buttercup-run' function" - (let* ((reporter (lambda (event arg) (ignore event arg))) - (runner (lambda (suite) (ignore suite))) - (buttercup-reporter 'reporter) - buttercup-suites - parent-suite child-suite spec) - (ignore reporter runner) + :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") @@ -1004,23 +1000,27 @@ buttercup-suites (list parent-suite)) (buttercup-suite-add-child parent-suite child-suite) (buttercup-suite-add-child child-suite spec) - (spy-on 'reporter) - (spy-on 'runner)) + (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)) + (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)) + (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) + (buttercup-reporter 'reporter)) (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-letf (((symbol-function 'buttercup--run-suite) #'runner) - (buttercup-suites (make-list 5 parent-suite))) - (expect (buttercup-run) :not :to-throw) - (expect 'runner :to-have-been-called-times 5))))) + (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)))))) (describe "The `buttercup--print' function" (before-each