Is there a way right now to run some setup code once after environment.rb has loaded but before all the scenarios are run? And how about a teardown after everything''s done? cheers, Matt ---- http://blog.mattwynne.net http://songkick.com In case you wondered: The opinions expressed in this email are my own and do not necessarily reflect the views of any former, current or future employers of mine. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080902/4d8e0afb/attachment.html>
On Tue, Sep 2, 2008 at 3:50 PM, Matt Wynne <matt at mattwynne.net> wrote:> Is there a way right now to run some setup code once after environment.rb > has loaded but before all the scenarios are run?Yes. Just use Ruby :-) Put it at the "main level" in one of your ruby files under steps/> And how about a teardown after everything''s done?at_exit do .. end For example: # steps/globals.rb User.create! :name => ''matt'' at_exit do User.destroy_all end Would this work for you? Aslak> cheers, > Matt > ---- > http://blog.mattwynne.net > http://songkick.com > In case you wondered: The opinions expressed in this email are my own and do > not necessarily reflect the views of any former, current or future employers > of mine. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 2 Sep 2008, at 15:24, aslak hellesoy wrote:> On Tue, Sep 2, 2008 at 3:50 PM, Matt Wynne <matt at mattwynne.net> wrote: >> Is there a way right now to run some setup code once after >> environment.rb >> has loaded but before all the scenarios are run? > > Yes. Just use Ruby :-) > > Put it at the "main level" in one of your ruby files under steps/ > >> And how about a teardown after everything''s done? > > at_exit do > .. > end > > For example: > > # steps/globals.rb > > User.create! :name => ''matt'' > > at_exit do > User.destroy_all > end > > Would this work for you? > > AslakIt looks good, but the before stuff doesn''t work for me - it looks as though the rails environment hasn''t been loaded yet - I get '' uninitialized constant User (NameError)''
On Tue, Sep 2, 2008 at 4:53 PM, Matt Wynne <matt at mattwynne.net> wrote:> On 2 Sep 2008, at 15:24, aslak hellesoy wrote: > >> On Tue, Sep 2, 2008 at 3:50 PM, Matt Wynne <matt at mattwynne.net> wrote: >>> >>> Is there a way right now to run some setup code once after environment.rb >>> has loaded but before all the scenarios are run? >> >> Yes. Just use Ruby :-) >> >> Put it at the "main level" in one of your ruby files under steps/ >> >>> And how about a teardown after everything''s done? >> >> at_exit do >> .. >> end >> >> For example: >> >> # steps/globals.rb >> >> User.create! :name => ''matt'' >> >> at_exit do >> User.destroy_all >> end >> >> Would this work for you? >> >> Aslak > > It looks good, but the before stuff doesn''t work for me - it looks as though > the rails environment hasn''t been loaded yet - I get '' uninitialized > constant User (NameError)''I assume you''ve followed the Wiki instructions about how to set up Cucumber with Rails: http://github.com/aslakhellesoy/cucumber/wikis (I should move this to a separate Rails page) Then you should have a steps/env.rb file that looks like this: http://github.com/aslakhellesoy/cucumber/tree/master/generators/cucumber/templates/env.rb You can put the code in this file, or you can put it in another one and do this at the top: require File.dirname(__FILE__) + ''/env'' HTH, Aslak> _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Hi,>, aslak hellesoy wrote (sometime today):> at_exit do > .. > endIf I had a number of steps, stories and runners where would I put the kernal at_exit method? At the last ''Then'' in a step file? At the bottom of that particular runner file? I assume there would be numerous at_exit methods i.e. different teardowns. Cheers Aidy
> Hi, > >> , aslak hellesoy wrote (sometime today): > >> at_exit do >> .. >> end > > If I had a number of steps, stories and runners where would I put the > kernal at_exit method? > > At the last ''Then'' in a step file?No, never inside a step. You should only register each at_exit hook once.> At the bottom of that particular > runner file? I assume there would beNot sure what you mean by runner file. Stick the global setup code and at_exit hook(s) at the top level in a ruby file inside your steps folder. This file shouldn''t contain any step defs. Aslak> numerous at_exit methods i.e. > different teardowns. > > Cheers > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
> > I assume you''ve followed the Wiki instructions about how to set up > Cucumber with Rails: > http://github.com/aslakhellesoy/cucumber/wikis (I should move this to > a separate Rails page) > > Then you should have a steps/env.rb file that looks like this: > http://github.com/aslakhellesoy/cucumber/tree/master/generators/ > cucumber/templates/env.rb >Done all that.> You can put the code in this file, or you can put it in another one > and do this at the top: > require File.dirname(__FILE__) + ''/env''Aha. So I assumed that the features/steps/env.rb file was what was loading all the other files in features/steps. Sounds a bit silly when I write it down. Thanks Aslak