After :each invoked before formatter?

Hello.

I’m using RSpec with Watir to do some automated tests on IE.

I’ve ran into problem, where I want to make a screenshot of a browser
window
when example fails. For that I made custom formatter where in
extra_failure_content i’m invoking screenshot taking methods. Now,
everything works like a charm, as long as I’m not using after :each. I
remember that I had this problem before with after :all with version
1.0.8
(at the moment I’m using 1.1.4).

In after :each block I’m invoking Watir to close IE (and maybe some
other
stuff). So if each example finishes, IE is closed. Now, my logic is
telling
me that after example has failed, formatter’s methods should be invoked
(as
example_failed or extra_failure_content methods), but it’s not like
that!
Those methods are called AFTER after :each block has finished. So, at
the
moment it’s like that:

  1. it block executes
  2. it block failed
  3. after :each block executes
  4. formatter’s example_failed and extra_failure_content methods are
    executed

shouldn’t be step 4 before step 3? With after :all, everything is
working as
expected (so steps are executed as 1,2,4,3 with one failing it method in
describe block). So the problem in my case is that when screenshot
taking
methods are invoked, IE has already been closed - thus unable to get any
screenshots.

As I mentioned before, everything was working alright with after :each
in
rspec 1.0.8, but the problem was with after :all… now the problem is
vice-versa.

Any ideas or suggestions or temporary patches?

Thank You for great framework!


View this message in context:
http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17796760.html
Sent from the rspec-users mailing list archive at Nabble.com.

Sorry for spamming. I just solved the problem. It was my close_browser
method, which handled thread differently after refactoring.

And I’ve confirmed that after :each was executed prior failure methods
in
formatter in RSpec 1.0.8 too. So, the question still remains - shouldn’t
these methods be invoked before “after” blocks?


View this message in context:
http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17797475.html
Sent from the rspec-users mailing list archive at Nabble.com.

On Jun 12, 2008, at 6:12 AM, kasutaja wrote:

Sorry for spamming. I just solved the problem. It was my close_browser
method, which handled thread differently after refactoring.

And I’ve confirmed that after :each was executed prior failure
methods in
formatter in RSpec 1.0.8 too. So, the question still remains -
shouldn’t
these methods be invoked before “after” blocks?

I don’t think so. If we did that and something was failing in the
‘after’ blocks, you’d not see that reported. Make sense?

I just reverted all my files from svn to revision prior upgrading rspec
and
it still doesn’t work :sunglasses: which might mean that I’ve ran out of ideas as
to
why was it working before and not anymore…

kasutaja wrote:

As I mentioned before, everything was working alright with after :each in
rspec 1.0.8, but the problem was with after :all… now the problem is
vice-versa.


View this message in context:
http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17797371.html
Sent from the rspec-users mailing list archive at Nabble.com.

Hmm. How come? As far as I’ve understood so far, then reports are
generated
it-method-by-it-method. So, why couldn’t RSpec handle after :each
methods
similar to it-methods? So it would go something like this:
-invoke it method
-it method fails
-invoke reporter’s methods to generate report for failing it-method
-invoke after :each method
-something fails in after :each block
-invoke reporter’s methods to generate report for failing after :each
method
-invoke next-it and so on

I don’t see any problems (maybe i’m just too narrow-minded, hehe) with
that
solution. Please be more specific if you still think that there is
problem.

David C.-2 wrote:

I don’t think so. If we did that and something was failing in the
‘after’ blocks, you’d not see that reported. Make sense?


View this message in context:
http://www.nabble.com/after-%3Aeach-invoked-before-formatter--tp17796760p17803189.html
Sent from the rspec-users mailing list archive at Nabble.com.