Browse files

Add have_failed to the readme

  • Loading branch information...
1 parent 2f63ab4 commit ae570b0707afcefbdb0f3c88ddd007676ecc5582 @jimweirich committed Aug 30, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0
@@ -193,6 +193,25 @@ The code block is executed once per test and the value of the code
block is bound to 'result'. Use this form when the code under test
returns a value that you wish to interrogate in the _Then_ code.
+If an exception occurs during the execution of the When block, the
+exception is caught and a failure object is bound to 'result'. The
+failure can be checked in a then block with the 'have_failed' matcher.
+The failure object will rethrow the captured exception if anything
+other than have_failed matcher is used on the failure object.
+For example, if the stack is empty when it is popped, then it is
+reasonable for pop to raise an UnderflowError. This is how you might
+specify that behavior:
+ When(:result) { stack.pop }
+ Then { result.should have_failed(UnderflowError, /empty/) }
+Note that the arguments to the 'have_failed' matcher are the same as
+those given to the standard RSpec matcher 'raise_error'.
### Then
The _Then_ sections are the postconditions of the specification. These

0 comments on commit ae570b0

Please sign in to comment.