diff --git a/src/spec b/src/spec index 2747e5c..50a63f8 100644 --- a/src/spec +++ b/src/spec @@ -174,6 +174,22 @@ to() } +## +# Declares additional expectations for the preceding premise +and() +{ + __spec_caller="$(caller)" + + # the most recently popped value should be an expect premise, implying + # that an expectation declaration implicitly popped it + _sstack-unpop + _sstack-assert-within :expect and $(caller) \ + "follow an expectation as part of" + + "$@" +} + + ## # Outputs failure details and exits # diff --git a/test/test-spec b/test/test-spec index 96c0a48..b576e55 100644 --- a/test/test-spec +++ b/test/test-spec @@ -208,5 +208,46 @@ describe expect '; to succeed end end + + + describe and + # technically, we want this to be permitted after any declaration, but + # we do not yet support any others + it must appear after a "'to'" declaration + expect test-run <<< ' + describe foo + it should fail + expect true + # missing "to" + and to succeed + end + end + '; to fail + end + + it adds additional expectations to preceding declaration + # impossible condition + expect test-run <<< ' + describe foo + it should fail + expect true + to succeed + and to fail + end + end + '; to fail + + # redundant to demonstrate that it does not always fail + expect test-run <<< ' + describe foo + it should fail + expect true + to succeed + and to succeed + end + end + '; to succeed + end + end end