Example#execution_result Grabbing the Status

99 views
Skip to first unread message

Kevin Solorio

unread,
Oct 16, 2014, 4:33:48 PM10/16/14
to rs...@googlegroups.com
It seems like the result of running the test is not available on the example object during the after callback hook. Is there another place to hook into RSpec where that information will be set?

To give some back story, I'm using RSpec to help teach coding, and I'd like to have the test run send stats to a server every time a student runs a test. Specifically, did the test pass or fail on this run. I figured the after(:example) hook would be the best place to do this, but it seems that the data is not part of the object just yet. Where else can I grab this data?


Myron Marston

unread,
Oct 16, 2014, 5:05:47 PM10/16/14
to rs...@googlegroups.com
On Thursday, October 16, 2014 1:33:48 PM UTC-7, Kevin Solorio wrote:
It seems like the result of running the test is not available on the example object during the after callback hook. Is there another place to hook into RSpec where that information will be set?

To give some back story, I'm using RSpec to help teach coding, and I'd like to have the test run send stats to a server every time a student runs a test. Specifically, did the test pass or fail on this run. I figured the after(:example) hook would be the best place to do this, but it seems that the data is not part of the object just yet. Where else can I grab this data?

It's not available in `after(:example)` hooks because the example isn't finished until the `after(:example)` hooks run.  If an error is raised while executing the `after(:example)` hook, it'll cause the example to fail, so the status isn't set until _after_ the after hooks run.

To monitor the status of examples, I recommend defining and using a custom formatter.  While the primary use case of formatters is to format the console output as the spec suite runs, they are a generalized mechanism to get notified of events (example started, example complete, etc) as the suite progresses, and you can use those event notifications for any purpose.

To build a custom formatter, see the cucumber feature[1] for a simple example and the API docs[2][3] for detailed documentation.

HTH,
Myron

Kevin Solorio

unread,
Oct 17, 2014, 11:58:52 AM10/17/14
to rs...@googlegroups.com
Thanks for the explanation and the links.

To the Formatters!
Reply all
Reply to author
Forward
0 new messages