branch: elpa/buttercup commit 3637e3d16bf3de29718beb25ba6a55a4cd337f1d Author: Jorgen Schaefer <cont...@jorgenschaefer.de> Commit: Jorgen Schaefer <cont...@jorgenschaefer.de>
Add more extensive matcher tests to the README. --- README.md | 21 ++++++++++++++++----- buttercup-test.el | 28 +++++++++++++++------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ac773d9..6d3d202 100644 --- a/README.md +++ b/README.md @@ -137,11 +137,22 @@ that are not included below. (expect pi :not :to-be-close-to e 2) (expect pi :to-be-close-to e 0))) - (it "The :to-throw matcher is for testing if a function throws an exception" - (let ((foo (lambda () (+ 1 2))) - (bar (lambda () (+ a 1)))) - (expect foo :not :to-throw) - (expect bar :to-throw)))) + (describe "The :to-throw matcher" + (it "is for testing if a function throws an exception" + (let ((foo (lambda () (+ 1 2))) + (bar (lambda () (+ a 1)))) + (expect foo :not :to-throw) + (expect bar :to-throw))) + (it "accepts a symbol to check for the signal thrown" + (let ((foo (lambda () (/ 1 0))) + (bar (lambda () (+ a 1)))) + (expect foo :not :to-throw 'void-variable) + (expect bar :to-throw 'void-variable))) + (it "optionally matches arguments to signals" + (let ((foo (lambda () (+ a 1))) + (bar (lambda () (+ a 1)))) + (expect foo :not :to-throw 'void-variable '(b)) + (expect bar :to-throw 'void-variable '(a)))))) ``` ## Spies diff --git a/buttercup-test.el b/buttercup-test.el index 7e4ae99..ba9b266 100644 --- a/buttercup-test.el +++ b/buttercup-test.el @@ -107,20 +107,22 @@ (it "should create a matcher usable by apply-matcher" (expect (buttercup--apply-matcher :test-matcher '(1 2)) :to-equal + 3))) + +(describe "The `buttercup--apply-matcher'" + (it "should work with functions" + (expect (buttercup--apply-matcher #'+ '(1 2)) + :to-equal 3)) - (describe "The `buttercup--apply-matcher'" - (it "should work with functions" - (expect (buttercup--apply-matcher #'+ '(1 2)) - :to-equal - 3)) + (it "should work with matchers" + (expect (buttercup--apply-matcher :test-matcher '(1 2)) + :to-equal + 3)) - (it "should work with matchers" - (expect (buttercup--apply-matcher :test-matcher '(1 2)) - :to-equal - 3)) + (it "should fail if the matcher is not defined" + (expect (lambda () + (buttercup--apply-matcher :not-defined '(1 2))) + :to-throw))) - (it "should fail if the matcher is not defined" - (expect (lambda () - (buttercup--apply-matcher :not-defined '(1 2))) - :to-throw)))) +;; Built-in matchers are tested in README.md