Skip to content

Yanoh sample lspec#2

Open
yanoh wants to merge 3 commits into
yanoh-sample-quiz2from
yanoh-sample-lspec
Open

Yanoh sample lspec#2
yanoh wants to merge 3 commits into
yanoh-sample-quiz2from
yanoh-sample-lspec

Conversation

@yanoh

@yanoh yanoh commented Aug 25, 2013

Copy link
Copy Markdown
Member

Ruby の RSpec を真似て LSpec を作ってみたいと思い立ちました。
S 式での仕様の書き方をざっくり決めて、それらしく動くところまでプロトタイプとして書いてみました。

仕様の記述例

先日できあがった minmax 関数の仕様です。

(describe 'minmax
  ((context 'call-with-empty-list
     (it-should-be-nil (minmax ())))
   (context 'call-with-list-of-one-element
     (it-should-be-equal-to (minmax '(1)) (cons 1 1)))
   (context 'call-with-list-of-odd-number-of-elements
     (it-should-be-equal-to (minmax '(3 5 2 1 4)) (cons 1 5)))
   (context 'call-with-list-of-even-number-of-elements
     (let ((arg '(3 5 2 1 4 6)))
       ((it-should-be-equal-to (minmax arg) (cons 1 6)))))
   (context 'test-with-incorrect-spec
     (it-should-be-equal-to (minmax '(1 2 3)) (cons 1 5)))))

テスト結果

minmax
(call-with-empty-list OK)
(call-with-list-of-one-element OK)
(call-with-list-of-odd-number-of-elements OK)
(call-with-list-of-even-number-of-elements OK)
(test-with-incorrect-spec NG (expected (1 . 5) but got (1 . 3)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant