Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 committed Jul 23, 2018
1 parent eda6453 commit 6b3f8ac
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 30 deletions.
4 changes: 3 additions & 1 deletion buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,9 @@ mainly calls to `describe', `it' and `before-each'."
`((let ,var
,@body))
body)))
`(buttercup-describe ,description (lambda () ,@new-body) ',env)))
(if env
`(buttercup-describe ,description (lambda () ,@new-body) ',env)
`(buttercup-describe ,description (lambda () ,@new-body)))))

(defun buttercup-describe (description body-function &optional env)
"Function to handle a `describe' form.
Expand Down
101 changes: 72 additions & 29 deletions tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,50 @@
(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 after :env"
(expect (macroexpand '(describe "description" :env nil :var (foo bar) (+ foo bar)))
:to-equal
'(buttercup-describe "description"
(lambda () (let (foo bar) (+ foo bar))))))

(it "should support the :env"
(expect (macroexpand '(describe "description" :env ((kill-ring kill-ring)) (+ foo bar)))
:to-equal
'(buttercup-describe "description"
(lambda () (+ foo bar))
'((kill-ring kill-ring)))))

(defvar buttercup-test--special-var "global")

(describe "Dynamic environment"

(describe "preserving global value"
:env ((kill-ring kill-ring))

(it "should update environment locally in a test"
(with-temp-buffer
(insert "killed line")
(goto-char (point-min))
(kill-line))
(expect kill-ring :to-equal (list "killed line")))

(it "should restore environment between tests"
(expect kill-ring :to-be nil)))

(describe "binding new value"
:env ((buttercup-test--special-var "local"))

(it "should setup new dynamic environment for special vars"
(expect (bound-and-true-p buttercup-test--special-var) :to-be-truthy)
(expect buttercup-test--special-var :to-equal "local")))

(describe "keeping global value"

(it "should use the global value for variable which is not locally updated"
(expect (bound-and-true-p buttercup-test--special-var) :to-be-truthy)
(expect buttercup-test--special-var :to-equal "global")))))

(describe "The `buttercup-describe' function"
(it "should run the enclosing body"
Expand Down Expand Up @@ -716,44 +759,44 @@
23))

(it "works with strings"
(spy-on 'test-function :and-return-value "return value")
(expect (test-function 2 3)
:to-equal
"return value"))
(spy-on 'test-function :and-return-value "return value")
(expect (test-function 2 3)
:to-equal
"return value"))

(it "works with vectors"
(spy-on 'test-function :and-return-value [1 2 3 4])
(expect (test-function 2 3)
:to-equal
[1 2 3 4]))
(spy-on 'test-function :and-return-value [1 2 3 4])
(expect (test-function 2 3)
:to-equal
[1 2 3 4]))

(it "works with symbols"
(spy-on 'test-function :and-return-value 'symbol)
(expect (test-function 2 3)
:to-equal
'symbol))
(spy-on 'test-function :and-return-value 'symbol)
(expect (test-function 2 3)
:to-equal
'symbol))

(it "works with conses"
(spy-on 'test-function :and-return-value '(1 . 2))
(expect (test-function 2 3)
:to-equal
(cons 1 2)))
(spy-on 'test-function :and-return-value '(1 . 2))
(expect (test-function 2 3)
:to-equal
(cons 1 2)))

(it "works with lists"
(spy-on 'test-function :and-return-value '(1 2 3))
(expect (test-function 2 3)
:to-equal
'(1 2 3)))
(spy-on 'test-function :and-return-value '(1 2 3))
(expect (test-function 2 3)
:to-equal
'(1 2 3)))

(it "works with alists"
(spy-on 'test-function :and-return-value '((first . 1)
(second . 2)
(third . 3)))
(expect (test-function 2 3)
:to-equal
'((first . 1)
(second . 2)
(third . 3)))))
(spy-on 'test-function :and-return-value '((first . 1)
(second . 2)
(third . 3)))
(expect (test-function 2 3)
:to-equal
'((first . 1)
(second . 2)
(third . 3)))))

(describe ":and-call-fake keyword functionality"
(before-each
Expand Down

0 comments on commit 6b3f8ac

Please sign in to comment.