- capture a screenshot and save the page as soon as the example fails
- output extra information to the test log so it is obvious which log output is generated by which example
Capturing a screenshot and saving the current page on spec failure can be implemented like this: This adds an after-hook to all request-specs which invokes the
render_screenshot_and_save_page only if the example failed. The implementation for that method looks like this:So the screenshot is only rendered if the javascript-driver is used (the rack driver supports no screenshot method afaik). [NOTE: I had to copy the implementation for `save_page` because the capybara implementation did not work correctly, no idea why. It seemed like the method got overwritten from somewhere else, because when i added a `raise` inside it no exception got thrown when invoking the method (for other methods this worked fine)] The
filename_from_failed_example looks like this:
A failing example in say
spec/requests/comments_request_spec.rb would then generate the filename comments_request_spec_23-20120901 where 23 is the number of the line where the error occurred.
Logging an examples name and file as well as its result
To figure out what happened in a failed request spec one can inspec the
test.log. The problem with this is that its not so obvious which parts of the contents of the log belong to a failing spec and which parts don't. The following will print markers to the log so that its obvious what output is generated by which spec:





