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 On Fri, Jul 28, 2017 at 9:14 PM, JQN <[email protected]> wrote: > 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 <[email protected]> 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 [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/ms >>> gid/rspec/0f2bb5d5-ab61-4559-a871-ce7b7b72577b%40googlegroups.com >>> <https://groups.google.com/d/msgid/rspec/0f2bb5d5-ab61-4559-a871-ce7b7b72577b%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > 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/f64810dd-25bc-4a23-bc82-583245524a0b%40googlegroups.com > <https://groups.google.com/d/msgid/rspec/f64810dd-25bc-4a23-bc82-583245524a0b%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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/CADUxQmtX5EbfWAdS2%3DhopkYxV7c_-eKi-PB0Gj7%2BoB1gXd_QHw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
