[rspec-users] AfterCurrentScenario block

Joseph Wilk joe at josephwilk.net
Fri Apr 17 12:45:57 EDT 2009


Matt Wynne wrote:
> Is there currently a way to register a block to run after the current 
> scenario completes?
>
You could achieve the same thing with After and tags:

http://wiki.github.com/aslakhellesoy/cucumber/hooks

@please-clean-me
Scenario: dirty
   ...


After "@please-clean-me" do
    #clean
end

--
Joseph Wilk
http://blog.josephwilk.net
> If not, we've implemented one. Would anyone be interested in us 
> submitting it as a patch to Cucumber?
>
> Something like
>
> Given "something that will not be rolled back after the scenario is 
> finished" do
>   original = SomeClass.a_value
>   SomeClass.a_value = 7
>
>   AfterCurrentScenario do
>     # undo stuff
>     SomeClass.a_value = original
>   end
> end
>
> If you're interested, our use case is for pagination, where we 
> explicitly set the length of a page to something much shorter than the 
> default in a step, so that we only have to create a small number of 
> objects to spill over onto another page. The page length value is set 
> on a class variable, and would pollute other tests, so we want to 
> reset it when the scenario is finished.
>
>   e.g.  Given the maximum number of Users to display is 2
>      And there are 3 Users
>     When I view the Users page
>     Then I should see the text "see all 3 users"
>
> Matt Wynne
> http://blog.mattwynne.net
> http://www.songkick.com
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



More information about the rspec-users mailing list