Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add example of catching assertions

  • Loading branch information...
commit 1d0ea726e3e1cbe9c680684a634f50b2e058fbd3 1 parent 51da62c
@Sutto authored
View
0  wip-coffeescripts/example_test.coffee
No changes.
View
37 wip-coffeescripts/test/assertions.coffee
@@ -1,6 +1,27 @@
# General assertions.
Shuriken.Test.Assertions: ((ns) ->
+ ns.currentAssertionCatcher: null
+
+ class ns.AssertionCatcher
+
+ constructor: ->
+ @passedCount: 0
+ @passedMessages: []
+ @failedOn: null
+
+ failAssertion: (e) ->
+ @failedOn: e
+
+ passAssertion: (e) ->
+ @passedMessages.push e.message
+ @passedCount++
+
+ passed: -> not @failed()
+
+ failed: -> @failedOn?
+
+
class ns.AssertionFailed
constructor: (message) ->
@@ -69,4 +90,18 @@ Shuriken.Test.Assertions: ((ns) ->
)({})
Shuriken.Test.withAssertions: (closure) ->
- `with(Shuriken.Test.Assertions) { closure() }`
+ `with(Shuriken.Test.Assertions) { closure() }`
+
+Shuriken.Test.catchingAssertions: (closure) ->
+ ac: Shuriken.Test.AssertionCatcher
+ catcher: new ac()
+ oldCatcher: ac.currentAssertionCatcher
+ ac.currentAssertionCatcher: catcher
+ try
+ closure()
+ catch e
+ catcher.failAssertion e
+ finally
+ ac.currentAssertionCatcher: oldCatcher
+ catcher
+
Please sign in to comment.
Something went wrong with that request. Please try again.