Joaquin Rivera Padron
2009-Feb-15 19:21 UTC
[rspec-users] cucumber hooks BeforeAll and AfterAll
hey there, the short version: right now Cucumber provides hooks Before and After to be run around every step, I have notice some use case where BeforeAll and AfterAll hooks would be useful. are ther plans that they be provided? what you think would be the best place to do it (mother_step.rb)? any ideas about this could be accomplished? the long version: playing with culerity, which according to the author: * when running cucumber culerity spawns a new jruby process (that''s the IO.popen call) - this way cucumber runs in plain old ruby (and you can work with your models for test setup etc.) and only celerity runs in jruby * from then on all communication has to go through pipes (in, out) so i am passing the browser config through those pipes to the newsly spawned jruby process * when a test fails the jruby process doesn''t get killed, that''s the java processes you see. don''t have a good idea how to solve this yet. for now you will have to kill those processes by hand. that has improved since now there''s a first attempt for built in support to kill orfan java processes at: http://github.com/joahking/culerity/tree/orfan_processes culerity trick happen at step_definitions/common_celerity.rb Before and After hooks, where you build and kill a spawned jruby around every step. There it is easy to see the gain if we could do those in an around All steps manner what do you think? cheers, joaquin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090215/ab2eba7a/attachment.html>
On Sun, Feb 15, 2009 at 2:21 PM, Joaquin Rivera Padron <joahking at gmail.com> wrote:> hey there, > the short version: > right now Cucumber provides hooks Before and After to be run around every > step, I have notice some use case where BeforeAll and AfterAll hooks would > be useful. > are ther plans that they be provided? what you think would be the best place > to do it (mother_step.rb)? any ideas about this could be accomplished? >BeforeAll is equivalent to just calling code up in env.rb. AfterAll is equivalent to registering a ruby at_exit hook in your env.rb. Of course they don''t have to go in your env.rb, you could put them in another file, and then require them from env.rb or just let cucumber auto-load them if they''re in your support/ directory.> the long version: > > playing with culerity, which according to the author: > * when running cucumber culerity spawns a new jruby process (that''s the > IO.popen call) - this way cucumber runs in plain old ruby (and you can work > with your models for test setup etc.) and only celerity runs in jruby > * from then on all communication has to go through pipes (in, out) so i am > passing the browser config through those pipes to the newsly spawned jruby > process > * when a test fails the jruby process doesn''t get killed, that''s the java > processes you see. don''t have a good idea how to solve this yet. for now you > will have to kill those processes by hand. > > that has improved since now there''s a first attempt for built in support to > kill orfan java processes at: > http://github.com/joahking/culerity/tree/orfan_processes > > culerity trick happen at step_definitions/common_celerity.rb Before and > After hooks, where you build and kill a spawned jruby around every step. > There it is easy to see the gain if we could do those in an around All steps > manner > > what do you think? > > cheers, > joaquin > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
Zach Dennis wrote:> On Sun, Feb 15, 2009 at 2:21 PM, Joaquin Rivera Padron > <joahking at gmail.com> wrote: > >> hey there, >> the short version: >> right now Cucumber provides hooks Before and After to be run around every >> step, I have notice some use case where BeforeAll and AfterAll hooks would >> be useful. >> are ther plans that they be provided? what you think would be the best place >> to do it (mother_step.rb)? any ideas about this could be accomplished? >> >> > > BeforeAll is equivalent to just calling code up in env.rb. > AfterAll is equivalent to registering a ruby at_exit hook in your env.rb. > > Of course they don''t have to go in your env.rb, you could put them in > another file, and then require them from env.rb or just let cucumber > auto-load them if they''re in your support/ directory. > >To illustrate what Zach is saying here is an example I used on the wiki[1] before: # Global setup ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true Before do # Scenario setup ActionMailer::Base.deliveries.clear end After do # Scenario teardown Database.truncate_all end at_exit do # Global teardown TempFileManager.clean_up end HTH, Ben 1. http://wiki.github.com/aslakhellesoy/cucumber/migration-from-rspec-stories> >> the long version: >> >> playing with culerity, which according to the author: >> * when running cucumber culerity spawns a new jruby process (that''s the >> IO.popen call) - this way cucumber runs in plain old ruby (and you can work >> with your models for test setup etc.) and only celerity runs in jruby >> * from then on all communication has to go through pipes (in, out) so i am >> passing the browser config through those pipes to the newsly spawned jruby >> process >> * when a test fails the jruby process doesn''t get killed, that''s the java >> processes you see. don''t have a good idea how to solve this yet. for now you >> will have to kill those processes by hand. >> >> that has improved since now there''s a first attempt for built in support to >> kill orfan java processes at: >> http://github.com/joahking/culerity/tree/orfan_processes >> >> culerity trick happen at step_definitions/common_celerity.rb Before and >> After hooks, where you build and kill a spawned jruby around every step. >> There it is easy to see the gain if we could do those in an around All steps >> manner >> >> what do you think? >> >> cheers, >> joaquin >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > > >
Joaquin Rivera Padron
2009-Feb-16 08:57 UTC
[rspec-users] cucumber hooks BeforeAll and AfterAll
cool thanks, joaquin 2009/2/15 Ben Mabey <ben at benmabey.com>> Zach Dennis wrote: > >> On Sun, Feb 15, 2009 at 2:21 PM, Joaquin Rivera Padron >> <joahking at gmail.com> wrote: >> >> >>> hey there, >>> the short version: >>> right now Cucumber provides hooks Before and After to be run around every >>> step, I have notice some use case where BeforeAll and AfterAll hooks >>> would >>> be useful. >>> are ther plans that they be provided? what you think would be the best >>> place >>> to do it (mother_step.rb)? any ideas about this could be accomplished? >>> >>> >>> >> >> BeforeAll is equivalent to just calling code up in env.rb. >> AfterAll is equivalent to registering a ruby at_exit hook in your env.rb. >> >> Of course they don''t have to go in your env.rb, you could put them in >> another file, and then require them from env.rb or just let cucumber >> auto-load them if they''re in your support/ directory. >> >> >> > > To illustrate what Zach is saying here is an example I used on the wiki[1] > before: > > # Global setup > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > > Before do > # Scenario setup > ActionMailer::Base.deliveries.clear > end > > After do > # Scenario teardown > Database.truncate_all > end > > at_exit do > # Global teardown > TempFileManager.clean_up > end > > HTH, > Ben > > 1. > http://wiki.github.com/aslakhellesoy/cucumber/migration-from-rspec-stories > > >> >>> the long version: >>> >>> playing with culerity, which according to the author: >>> * when running cucumber culerity spawns a new jruby process (that''s the >>> IO.popen call) - this way cucumber runs in plain old ruby (and you can >>> work >>> with your models for test setup etc.) and only celerity runs in jruby >>> * from then on all communication has to go through pipes (in, out) so i >>> am >>> passing the browser config through those pipes to the newsly spawned >>> jruby >>> process >>> * when a test fails the jruby process doesn''t get killed, that''s the java >>> processes you see. don''t have a good idea how to solve this yet. for now >>> you >>> will have to kill those processes by hand. >>> >>> that has improved since now there''s a first attempt for built in support >>> to >>> kill orfan java processes at: >>> http://github.com/joahking/culerity/tree/orfan_processes >>> >>> culerity trick happen at step_definitions/common_celerity.rb Before and >>> After hooks, where you build and kill a spawned jruby around every step. >>> There it is easy to see the gain if we could do those in an around All >>> steps >>> manner >>> >>> what do you think? >>> >>> cheers, >>> joaquin >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >>> >> >> >> >> >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090216/6a11895a/attachment-0001.html>
On Sun, Feb 15, 2009 at 8:47 PM, Ben Mabey <ben at benmabey.com> wrote:> Zach Dennis wrote: >> >> On Sun, Feb 15, 2009 at 2:21 PM, Joaquin Rivera Padron >> <joahking at gmail.com> wrote: >> >>> >>> hey there, >>> the short version: >>> right now Cucumber provides hooks Before and After to be run around every >>> step, I have notice some use case where BeforeAll and AfterAll hooks >>> would >>> be useful. >>> are ther plans that they be provided? what you think would be the best >>> place >>> to do it (mother_step.rb)? any ideas about this could be accomplished? >>> >>> >> >> BeforeAll is equivalent to just calling code up in env.rb. >> AfterAll is equivalent to registering a ruby at_exit hook in your env.rb. >>I updated the most relevant wiki page with this info: http://wiki.github.com/aslakhellesoy/cucumber/hooks Aslak>> Of course they don''t have to go in your env.rb, you could put them in >> another file, and then require them from env.rb or just let cucumber >> auto-load them if they''re in your support/ directory. >> >> > > To illustrate what Zach is saying here is an example I used on the wiki[1] > before: > > # Global setup > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > > Before do > # Scenario setup > ActionMailer::Base.deliveries.clear > end > > After do > # Scenario teardown > Database.truncate_all > end > > at_exit do > # Global teardown > TempFileManager.clean_up > end > > HTH, > Ben > > 1. > http://wiki.github.com/aslakhellesoy/cucumber/migration-from-rspec-stories >> >> >>> >>> the long version: >>> >>> playing with culerity, which according to the author: >>> * when running cucumber culerity spawns a new jruby process (that''s the >>> IO.popen call) - this way cucumber runs in plain old ruby (and you can >>> work >>> with your models for test setup etc.) and only celerity runs in jruby >>> * from then on all communication has to go through pipes (in, out) so i >>> am >>> passing the browser config through those pipes to the newsly spawned >>> jruby >>> process >>> * when a test fails the jruby process doesn''t get killed, that''s the java >>> processes you see. don''t have a good idea how to solve this yet. for now >>> you >>> will have to kill those processes by hand. >>> >>> that has improved since now there''s a first attempt for built in support >>> to >>> kill orfan java processes at: >>> http://github.com/joahking/culerity/tree/orfan_processes >>> >>> culerity trick happen at step_definitions/common_celerity.rb Before and >>> After hooks, where you build and kill a spawned jruby around every step. >>> There it is easy to see the gain if we could do those in an around All >>> steps >>> manner >>> >>> what do you think? >>> >>> cheers, >>> joaquin >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> >> >> >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Aslak (::)
On 15 Feb 2009, at 19:47, Ben Mabey wrote:> To illustrate what Zach is saying here is an example I used on the > wiki[1] before: > > # Global setup > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > > Before do > # Scenario setup > ActionMailer::Base.deliveries.clear > end > > After do > # Scenario teardown > Database.truncate_all > end > > at_exit do > # Global teardown > TempFileManager.clean_up > end > > HTH, > BenI still think it would be nice if you could write BeforeAll do ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true end AfterAll do # Global teardown TempFileManager.clean_up end *Yes* it''s equivalent (largely), but it does make the intent more clear. And expressing intent is a big part of Cucumber (and RSpec) IMHO. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ http://twitter.com/ashleymoran
On Tue, Feb 17, 2009 at 3:32 PM, Ashley Moran <ashley.moran at patchspace.co.uk> wrote:> > On 15 Feb 2009, at 19:47, Ben Mabey wrote: > >> To illustrate what Zach is saying here is an example I used on the wiki[1] >> before: >> >> # Global setup >> ActionMailer::Base.delivery_method = :test >> ActionMailer::Base.perform_deliveries = true >> >> Before do >> # Scenario setup >> ActionMailer::Base.deliveries.clear >> end >> >> After do >> # Scenario teardown >> Database.truncate_all >> end >> >> at_exit do >> # Global teardown >> TempFileManager.clean_up >> end >> >> HTH, >> Ben > > I still think it would be nice if you could write > > BeforeAll do > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > end > > AfterAll do > # Global teardown > TempFileManager.clean_up > end > > *Yes* it''s equivalent (largely), but it does make the intent more clear. > And expressing intent is a big part of Cucumber (and RSpec) IMHO.The main problem w/ this for me is that before(:all) in RSpec means something different here (before(:all) the examples in one group). There is also a rarely used before(:suite), which is more akin to what you''re proposing here. So *if* we add Before[... some scope ...], I''d prefer it be aligned (or at least not conflict) w/ RSpec''s meaning (so ppl don''t have to remember which to use where). May I propose: Before(:suite) or Before(:all_features) ??> > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > http://twitter.com/ashleymoran > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Tue, Feb 17, 2009 at 10:32 PM, Ashley Moran <ashley.moran at patchspace.co.uk> wrote:> > On 15 Feb 2009, at 19:47, Ben Mabey wrote: > >> To illustrate what Zach is saying here is an example I used on the wiki[1] >> before: >> >> # Global setup >> ActionMailer::Base.delivery_method = :test >> ActionMailer::Base.perform_deliveries = true >> >> Before do >> # Scenario setup >> ActionMailer::Base.deliveries.clear >> end >> >> After do >> # Scenario teardown >> Database.truncate_all >> end >> >> at_exit do >> # Global teardown >> TempFileManager.clean_up >> end >> >> HTH, >> Ben > > I still think it would be nice if you could write > > BeforeAll do > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > end > > AfterAll do > # Global teardown > TempFileManager.clean_up > end > > *Yes* it''s equivalent (largely), but it does make the intent more clear. > And expressing intent is a big part of Cucumber (and RSpec) IMHO. >You can express intent with a comment in this case. I don''t want to invent constructs that do nothing. Gold plating. Aslak> Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > http://twitter.com/ashleymoran > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Aslak (::)