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

[1] 
https://github.com/rspec/rspec-core/blob/v3.1.7/features/formatters/custom_formatter.feature
[2] http://www.rubydoc.info/github/rspec/rspec-core/RSpec/Core/Formatters
[3] 
http://www.rubydoc.info/github/rspec/rspec-core/RSpec/Core/Formatters/Protocol

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/af880f0d-ab54-4afa-9a41-69dad22e5c3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to