[cuke4duke] at_exit hook?

261 views
Skip to first unread message

George Dinwiddie

unread,
Dec 9, 2010, 4:02:52 PM12/9/10
to Cukes
What would be the cuke4duke mechanism to simulate the at_exit in env.rb?

- George

--
Dec. 14 - Agile Richmond in Glen Allen, VA
http://georgedinwiddie.eventbrite.com/
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

aslak hellesoy

unread,
Dec 9, 2010, 6:24:59 PM12/9/10
to cu...@googlegroups.com
On Thu, Dec 9, 2010 at 9:02 PM, George Dinwiddie
<li...@idiacomputing.com> wrote:
> What would be the cuke4duke mechanism to simulate the at_exit in env.rb?
>

http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

Aslak

>  - George
>
> --
>  Dec. 14 - Agile Richmond in Glen Allen, VA
>  http://georgedinwiddie.eventbrite.com/
>  ----------------------------------------------------------------------
>  * George Dinwiddie *                      http://blog.gdinwiddie.com
>  Software Development                    http://www.idiacomputing.com
>  Consultant and Coach                    http://www.agilemaryland.org
>  ----------------------------------------------------------------------
>

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to
> cukes+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cukes?hl=en.
>
>

George Dinwiddie

unread,
Dec 9, 2010, 7:25:25 PM12/9/10
to cu...@googlegroups.com
On 12/9/10 5:24 PM, aslak hellesoy wrote:
> On Thu, Dec 9, 2010 at 9:02 PM, George Dinwiddie
> <li...@idiacomputing.com> wrote:
>> What would be the cuke4duke mechanism to simulate the at_exit in env.rb?
>>
>
> http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

Thanks. I looked for something in Java, figuring it should have it when
even lowly C does, but didn't find that.

Robert

unread,
Dec 10, 2010, 10:51:57 AM12/10/10
to Cukes
George,

Not knowing the context behind "at_exit in env.rb", I googled it and
found a copy on the web. The at_exit shown in my results is as
follows:

# "after all"
at_exit do
browser.close
end


We are also using Cuke4Duke. We have implemented a TestEnvironment
class that supports the loading (loading property files and starting
Selenium) and unloading (closing Selenium) of our test environment.
The 'load' method is invoked within a Before hook, contained in a
Hooks class.

After reading your post, I was wondering if we might have implemented
this improperly. Just wondering how you are handling this? Is it
through the env.rb or some other mechanism?

On Dec 9, 4:25 pm, George Dinwiddie <li...@iDIAcomputing.com> wrote:
> On 12/9/10 5:24 PM, aslak hellesoy wrote:
>
> > On Thu, Dec 9, 2010 at 9:02 PM, George Dinwiddie
> > <li...@idiacomputing.com>  wrote:
> >> What would be the cuke4duke mechanism to simulate the at_exit in env.rb?
>
> >http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#a...)

George Dinwiddie

unread,
Dec 10, 2010, 11:38:41 AM12/10/10
to cu...@googlegroups.com
Robert

On 12/10/10 9:51 AM, Robert wrote:
> George,
>
> Not knowing the context behind "at_exit in env.rb", I googled it and
> found a copy on the web. The at_exit shown in my results is as
> follows:
>
> # "after all"
> at_exit do
> browser.close
> end
>
>
> We are also using Cuke4Duke. We have implemented a TestEnvironment
> class that supports the loading (loading property files and starting
> Selenium) and unloading (closing Selenium) of our test environment.
> The 'load' method is invoked within a Before hook, contained in a
> Hooks class.
>
> After reading your post, I was wondering if we might have implemented
> this improperly. Just wondering how you are handling this? Is it
> through the env.rb or some other mechanism?

After reflection, we decided to put the final action into the continuous
integration server rather than at the end of the Cucumber run, so it
would be optional when running manually.

I'm not sure Runtime.addShutdownHook would be a good idea for this sort
of thing, anyway. The javadocs say "Shutdown hooks run at a delicate
time in the life cycle of a virtual machine and should therefore be
coded defensively.... Shutdown hooks should also finish their work
quickly." Probably not the best place to spawn an external process.

A better approach might be to use a snippet of ruby in env.rb to call a
Java method that does what you want. We were about to do that when we
decided to move the behavior to the build process rather than the
acceptance test process. You should be able to use that for shutting
down Selenium.

Aslak Hellesøy

unread,
Dec 10, 2010, 12:21:24 PM12/10/10
to cu...@googlegroups.com
On Dec 10, 2010, at 4:51 PM, Robert <rest...@gmail.com> wrote:

> George,
>
> Not knowing the context behind "at_exit in env.rb", I googled it and
> found a copy on the web. The at_exit shown in my results is as
> follows:
>
> # "after all"
> at_exit do
> browser.close
> end
>

Just to be clear - Kernel.at_exit is not a cucumber thing. It's in ruby core.

Reply all
Reply to author
Forward
0 new messages