How to programmatically find example/example group run status

95 views
Skip to first unread message

JQN

unread,
Jul 27, 2017, 10:02:05 PM7/27/17
to rspec
I am using rspec 3.5.0 and rspec-core 3.5.4.In earlier version I see that there are Formatter classes like JSONFormatter in rspec core are methods like failed_count and  these methods are not present in the newer versions.I couldn't figure out a way to obtain an example run status

For examples that run ok, i can look at the example metadata / execution_result in after(:each) but some of my examples fail due to load errors and the after(:each) block is not reached. There is execution results populated in a file/standard output correctly but I would like to dynamically inspect as well.

Please advise!

Myron Marston

unread,
Jul 28, 2017, 9:12:24 AM7/28/17
to rs...@googlegroups.com
Hi JQN,

It's not clear to me what you are trying to accomplish.  Can you explain a bit more about what you're trying to do?

Thanks,
Myron

--
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 rspec+unsubscribe@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/0f2bb5d5-ab61-4559-a871-ce7b7b72577b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JQN

unread,
Jul 28, 2017, 10:14:32 AM7/28/17
to rspec
Hi Myron

I am trying to capture each example execution result  in a  rspec.config.after(:each)  block so I could output it to a third party test result object.
but if an example fails during rspec.load() , the config.after(:each) block is not executed, neither is config.around(), but the example is correctly marked as a failure in the rspec output. How can I successfully capture the execution result for each example no matter how/where it fails/errors as soon as the failure happens.When an example fails can I inject the execution status as a value in the examplegroup metadata so I could refer it in a config.after(:all) block as this does seem to always execute.

I have had time to learn about this more and I think a custom formatter is a way to go and when an example fails i could inject a key value pair into the related examplegroup metadata. Am I on the right path ?



On Friday, July 28, 2017 at 2:12:24 PM UTC+1, Myron Marston wrote:
Hi JQN,

It's not clear to me what you are trying to accomplish.  Can you explain a bit more about what you're trying to do?

Thanks,
Myron
On Fri, Jul 28, 2017 at 1:23 AM, JQN <qns....@gmail.com> wrote:
I am using rspec 3.5.0 and rspec-core 3.5.4.In earlier version I see that there are Formatter classes like JSONFormatter in rspec core are methods like failed_count and  these methods are not present in the newer versions.I couldn't figure out a way to obtain an example run status

For examples that run ok, i can look at the example metadata / execution_result in after(:each) but some of my examples fail due to load errors and the after(:each) block is not reached. There is execution results populated in a file/standard output correctly but I would like to dynamically inspect as well.

Please advise!

--
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 rspec+un...@googlegroups.com.

Myron Marston

unread,
Jul 28, 2017, 10:33:05 AM7/28/17
to rs...@googlegroups.com
You can't use a hook to accurately capture the result of each spec because hooks are essentially part of each spec.  An example isn't done (and it's status isn't set) until all of its hooks have run, because a failure in an `after` hook must fail the example.

If you want to observe the result of each spec, a custom formatter is the way to go.  What you do with the status of each example in your custom formatter is entirely up to you, based on your needs.

Myron

To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.

To post to this group, send email to rs...@googlegroups.com.

JQN

unread,
Jul 28, 2017, 10:43:13 AM7/28/17
to rspec
thankyou !
Reply all
Reply to author
Forward
0 new messages