Matt Wynne
2008-Nov-12 13:12 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
My use case is that I want to be able to use a Logging::Logger[1] within my scenario code. I can create the logger explicitly within the step block, but this is a hackaround. I think I could monkey-patch Cucumber::Rails::World to include my logger, but that also feels dirty. Is there a nice clean way I can use on of the above (AFAIK undocumented) methods to help me? Better, is there some documentation / a blog post I can be pointed to so I can help myself? I have had a pretty thorough read of the code but I''m not quite there yet with my Ruby to make sufficient sense of it. cheers, Matt
aslak hellesoy
2008-Nov-12 13:30 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On Wed, Nov 12, 2008 at 2:12 PM, Matt Wynne <matt at mattwynne.net> wrote:> My use case is that I want to be able to use a Logging::Logger[1] within my > scenario code. > > I can create the logger explicitly within the step block, but this is a > hackaround. > > I think I could monkey-patch Cucumber::Rails::World to include my logger, > but that also feels dirty. > > Is there a nice clean way I can use on of the above (AFAIK undocumented) > methods to help me? >Try this: World do world = Object.new world.extend(Logging::Logger) world end Aslak> Better, is there some documentation / a blog post I can be pointed to so I > can help myself? I have had a pretty thorough read of the code but I''m not > quite there yet with my Ruby to make sufficient sense of it. > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky
2008-Nov-12 13:59 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> On Wed, Nov 12, 2008 at 2:12 PM, Matt Wynne <matt at mattwynne.net> wrote: >> My use case is that I want to be able to use a Logging::Logger[1] within my >> scenario code. >> >> I can create the logger explicitly within the step block, but this is a >> hackaround. >> >> I think I could monkey-patch Cucumber::Rails::World to include my logger, >> but that also feels dirty. >> >> Is there a nice clean way I can use on of the above (AFAIK undocumented) >> methods to help me? >> > > Try this: > > World do > world = Object.new > world.extend(Logging::Logger) > world > endOr, since you''re using Rails here: World do returning Cucumber::Rails::World do |world| world.extend(Logging::Logger) end end David> > Aslak > >> Better, is there some documentation / a blog post I can be pointed to so I >> can help myself? I have had a pretty thorough read of the code but I''m not >> quite there yet with my Ruby to make sufficient sense of it. >> >> cheers, >> Matt >> _______________________________________________ >> 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 >
Peter Jaros
2008-Nov-13 14:59 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy > <aslak.hellesoy at gmail.com> wrote: >> World do >> world = Object.new >> world.extend(Logging::Logger) >> world >> end > > World do > returning Cucumber::Rails::World do |world| > world.extend(Logging::Logger) > end > endIt would be really nice to be able to do: World do |world| returning world do |w| w.extend(Logging::Logger) end end This way steps files could extend the world by adding to a chain, agnostic of the nature of the original world object. Peter
David Chelimsky
2008-Nov-13 15:01 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On Thu, Nov 13, 2008 at 8:59 AM, Peter Jaros <peter.a.jaros at gmail.com> wrote:> On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky <dchelimsky at gmail.com> wrote: >> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy >> <aslak.hellesoy at gmail.com> wrote: >>> World do >>> world = Object.new >>> world.extend(Logging::Logger) >>> world >>> end >> >> World do >> returning Cucumber::Rails::World do |world| >> world.extend(Logging::Logger) >> end >> end > > It would be really nice to be able to do: > > World do |world| > returning world do |w| > w.extend(Logging::Logger) > end > end > > This way steps files could extend the world by adding to a chain, > agnostic of the nature of the original world object.That''s a cool idea - can you put a feature request in lighthouse? http://rspec.lighthouseapp.com/projects/16211-cucumber/overview Cheers, David> > Peter > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Matt Wynne
2008-Nov-13 15:15 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On 13 Nov 2008, at 15:01, David Chelimsky wrote:> On Thu, Nov 13, 2008 at 8:59 AM, Peter Jaros > <peter.a.jaros at gmail.com> wrote: >> On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky <dchelimsky at gmail.com >> > wrote: >>> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy >>> <aslak.hellesoy at gmail.com> wrote: >>>> World do >>>> world = Object.new >>>> world.extend(Logging::Logger) >>>> world >>>> end >>> >>> World do >>> returning Cucumber::Rails::World do |world| >>> world.extend(Logging::Logger) >>> end >>> end >> >> It would be really nice to be able to do: >> >> World do |world| >> returning world do |w| >> w.extend(Logging::Logger) >> end >> end >> >> This way steps files could extend the world by adding to a chain, >> agnostic of the nature of the original world object. > > That''s a cool idea - can you put a feature request in lighthouse? > > http://rspec.lighthouseapp.com/projects/16211-cucumber/overview > > Cheers, > DavidThat''s how I''d originally expected it to work, TBH. When I looked at the source and it didn''t, I got scared :) cheers, Matt
aslak hellesoy
2008-Nov-13 15:28 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On Thu, Nov 13, 2008 at 3:59 PM, Peter Jaros <peter.a.jaros at gmail.com> wrote:> On Wed, Nov 12, 2008 at 8:59 AM, David Chelimsky <dchelimsky at gmail.com> wrote: >> On Wed, Nov 12, 2008 at 7:30 AM, aslak hellesoy >> <aslak.hellesoy at gmail.com> wrote: >>> World do >>> world = Object.new >>> world.extend(Logging::Logger) >>> world >>> end >> >> World do >> returning Cucumber::Rails::World do |world| >> world.extend(Logging::Logger) >> end >> end > > It would be really nice to be able to do: > > World do |world| > returning world do |w| > w.extend(Logging::Logger) > end > end > > This way steps files could extend the world by adding to a chain, > agnostic of the nature of the original world object. >You *may* want to be in control over the world type (class). For example, in Rails the world instance is a ActionController::Integration::Session instance (off the top of my head) and in vanilla Cucumber it is Object. what if you want to change that? Maybe Cucumber could send in a world instance it *thinks* is the one you want (allowing what you suggest (and allow the user to instantiate a different class if they want to). # I''m happy with the suggested type World do |world| returning world do |w| w.extend(Logging::Logger) end end # I want my own type! World do world = MyType.new returning world do |w| w.extend(Logging::Logger) end end I didn''t see a ticket yet, so please add my comment or link to mail archive for this thread when you create the ticket. Cheers, Aslak> Peter > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Peter Jaros
2008-Nov-13 16:04 UTC
[rspec-users] Cucumber: The Mysteries of Before(), After(), World() etc
On Thu, Nov 13, 2008 at 10:01 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> That''s a cool idea - can you put a feature request in lighthouse?Done: http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/87-yield-existing-world-object-to-world-block Peter