[rspec-users] AfterCurrentScenario block

Matt Wynne matt at mattwynne.net
Fri Apr 17 18:00:02 EDT 2009

On 17 Apr 2009, at 18:20, Aslak Hellesøy wrote:

> Den 17. april. 2009 kl. 18.58 skrev Zach Dennis  
> <zach.dennis at gmail.com>:
>> On Fri, Apr 17, 2009 at 12:31 PM, Aslak Hellesøy
>> <aslak.hellesoy at gmail.com> wrote:
>>> Den 17. april. 2009 kl. 18.06 skrev Matt Wynne <matt at mattwynne.net>:
>>>> Is there currently a way to register a block to run after the  
>>>> current
>>>> scenario completes?
>>> After.
>> After is used after *any* scenario completes thought, right? If you
>> add an After block inside of a step definition, it's going to be
> Aha now I understand. Matt, would Joseph's suggestion work for you?
> Aslak

It would work, yes, but I have to say I like ours a bit better - you  
can put the undo code right next to the code it's undoing, as Zach  
pointed out. With the tags thing I'd have to put a tag in the feature  
file which is introducing a tiny bit more coupling and noise which I'd  
rather avoid.

I had pondered on the idea of changing the After method to use a  
syntax a bit like RSpec's #before(:each) where we could say:

After(:each) do
   # general post-scenario clean-up

After(:current) do
   # one-time clean-up

Anyway, just a thought.

Matt Wynne

More information about the rspec-users mailing list