Commit 1c50a80f authored by Ola Nilsson's avatar Ola Nilsson Committed by Jorgen Schäfer

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.
parent 18502530
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment