emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup debe7cc 204/340: Merge pull request #144 from ke


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup debe7cc 204/340: Merge pull request #144 from kevinjfoley/support-var-star
Date: Thu, 16 Dec 2021 14:59:35 -0500 (EST)

branch: elpa/buttercup
commit debe7ccac6b7ad4ad99060a7e685bd69fdde8e0a
Merge: 810fa6f 2bc55fe
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #144 from kevinjfoley/support-var-star
    
    Add support for :var*
---
 .travis.yml             |  1 +
 buttercup.el            | 13 +++++++++----
 docs/writing-tests.md   | 24 ++++++++++++++++++++++++
 tests/test-buttercup.el |  7 ++++++-
 4 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index da3de57..8d00c58 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,7 @@ env:
   - EVM_EMACS=emacs-25.1-travis
   - EVM_EMACS=emacs-25.2-travis
   - EVM_EMACS=emacs-26.1-travis
+  - EVM_EMACS=emacs-26.2-travis
 before_install:
   - curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > 
travis.sh && source ./travis.sh
   - evm install "$EVM_EMACS" --use --skip
diff --git a/buttercup.el b/buttercup.el
index 49f5669..dbeb966 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -805,10 +805,15 @@ form.")
 DESCRIPTION is a string. BODY is a sequence of instructions,
 mainly calls to `describe', `it' and `before-each'."
   (declare (indent 1) (debug (&define sexp def-body)))
-  (let ((new-body (if (eq (elt body 0) :var)
-                      `((let ,(elt body 1)
-                          ,@(cddr body)))
-                    body)))
+  (let ((new-body
+         (cond
+          ((eq (elt body 0) :var)
+           `((let ,(elt body 1)
+               ,@(cddr body))))
+          ((eq (elt body 0) :var*)
+           `((let* ,(elt body 1)
+               ,@(cddr body))))
+          (t body))))
     `(buttercup-describe ,description (lambda () ,@new-body))))
 
 (defun buttercup-describe (description body-function)
diff --git a/docs/writing-tests.md b/docs/writing-tests.md
index c478111..3383467 100644
--- a/docs/writing-tests.md
+++ b/docs/writing-tests.md
@@ -202,6 +202,30 @@ as full sentences in traditional
       (expect t :to-equal t))))
 ```
 
+### Declaring Variables
+
+The `describe` macro supports the optional `:var` and `:var*` args.
+These bind variables for the suite by passing them as a varlist to the
+`let` and `let*` form respectively.
+
+```Emacs-Lisp
+(describe "A spec using :VAR"
+  :var ((foo 1))
+  (it "has access to the variables bound in :VAR"
+    (expect foo :to-be 1)))
+
+(describe "A spec using :VAR*"
+  :var* ((foo 1)
+        (bar (1+ foo)))
+  (it "has access to the variables bound in :VAR* which can refer \
+to symbols already bound"
+    (expect bar :to-be 2)))
+```
+
+It's important to note that `lexical-binding` must be `non-nil` for
+`:var` and `:var*` to work properly. Within a test file this is
+usually set using a local file variable.
+
 ### Setup and Teardown
 
 To help a test suite DRY up any duplicated setup and teardown code,
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 5a660e6..b78c104 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -379,7 +379,12 @@
     (expect (macroexpand '(describe "description" :var (foo bar) (+ foo bar)))
             :to-equal
             '(buttercup-describe "description"
-                                 (lambda () (let (foo bar) (+ foo bar)))))))
+                                 (lambda () (let (foo bar) (+ foo bar))))))
+  (it "should support the :var* argument"
+    (expect (macroexpand '(describe "description" :var* (foo bar) (+ foo bar)))
+            :to-equal
+            '(buttercup-describe "description"
+                                 (lambda () (let* (foo bar) (+ foo bar)))))))
 
 (describe "The `buttercup-describe' function"
   (it "should run the enclosing body"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]