At_exit in spec file?

I need to perform some work (shutdown mysql servers & delete their
data directories) at the end of my tests. Naturally, I would like to
use at_exit. HOWEVER, when I do, the spec file gets loaded twice (and
the tests are run twice).

Help?

On Oct 28, 2009, at 10:41 AM, Student wrote:

I need to perform some work (shutdown mysql servers & delete their
data directories) at the end of my tests. Naturally, I would like to
use at_exit. HOWEVER, when I do, the spec file gets loaded twice (and
the tests are run twice).

Help?

For better or worse, RSpec uses at_exit, so you can’t for this purpose.

What you can do is add an after(:suite) block (typically in
spec_helper.rb):

Spec::Runner.configure do |config|
after(:suite) do
# shut stuff down here
end
end

HTH,
David

Hmmm… That yields “undefined method `after’ for main:Object
(NoMethodError)”

… BUT I’m pretty sure I’m barking up the wrong tree. I think that
I’m getting hung up with mysqld_safe. I’m

Looking over things, the problem is probably with fork/exec related.

I need to start mysql (two of them). They need to run in separate
processes. However, I don’t seem to be able to “really” exit when I
call exit!. It’s the final termination of these processes which
trigger the reruns.

I’ve tried several variations, nothing is working so far.

Some trouble with the list here…

Hmmm… That yields “undefined method `after’ for main:Object
(NoMethodError)” … BUT

I’m pretty sure I’m barking up the wrong tree. I think that I’m
getting hung up with mysqld_safe. I’m running two test servers, which
need to be in separate threads. So I have to background them some
way. I’ve tried playing games with fork & nohup, but no success so
far. (When these threads exit, even exit!, the test gets reread &
reexecuted.)

Well, I’ve got it half solved. In the shell call, I background &
nohup the mysqld_safe call. After the fork, I do a Process.kill(9,
pid) on each of them. That stops the “run twice” problem. So now I’m
back to the “undefined method `after’ for main:Object (NoMethodError)”
problem.

On 28 Oct 2009, at 20:42, Student wrote:

So now I’m
back to the “undefined method `after’ for main:Object (NoMethodError)”
problem.

I think it was just a typo on David’s part. Does the following work?

Spec::Runner.configure do |config|
config.after(:suite) do
# shut stuff down here
end
end

And I had no idea you could do before/after :suite…

Ashley


http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran

Sorry about that :frowning: And thanks, Ashley, for righting (and writing) my
wrong.

Cheers,
David

On Oct 28, 2009, at 4:06 PM, Student wrote:

Ashley
http://rubyforge.org/mailman/listinfo/rspec-users
Cheers,
David

Sweet! Thanks!

On Oct 28, 3:52 pm, Ashley M. [email protected]

On Oct 28, 2009, at 9:42 pm, David C. wrote:

Sorry about that :frowning: And thanks, Ashley, for righting (and writing)
my wrong.

No probs. I’m trying to answer the straightforward technical
questions, at least non-Rails ones. To people who have clearly tried
to help themselves first of course :slight_smile: Hopefully will free up other
people’s time.

But, is it me, or is rspec-users quieter than it used to be? I’m sure
when I was learning the volume of questions was much higher. Are
there fewer people using RSpec? Or is it just more stable and well-
documented now? (Maybe I’m just imagining it anyway.)

Ashley


http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran

On Thu, Oct 29, 2009 at 6:18 AM, Ashley M.
[email protected] wrote:

But, is it me, or is rspec-users quieter than it used to be? I’m sure when
I was learning the volume of questions was much higher. Are there fewer
people using RSpec? Or is it just more stable and well-documented now?
(Maybe I’m just imagining it anyway.)

Everyone’s busy programming. >8->

(More helpfully: this stuff tends to come in waves. A busier list
pushes up its visibility in people’s mailboxes, which makes them
participate more, which makes it busier. This one never seems to be
totally quiet, though.)


Have Fun,
Steve E. ([email protected])
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org

On 29 Oct 2009, at 13:46, Stephen E. wrote:

Everyone’s busy programming. >8->

I imagine the book helps a bit, too.

Cheers,
-Tom

On Wed, Oct 28, 2009 at 4:49 PM, David C. [email protected]
wrote:

Why not? Kernel#at_exit will just push procs onto a list of procs and
run them all when Ruby exits.

On 29 Oct 2009, at 13:58, Tom S. wrote:

On 29 Oct 2009, at 13:46, Stephen E. wrote:

Everyone’s busy programming. >8->

I imagine the book helps a bit, too.

The book pretty much replaces the slides I did for my mocking
presentation, and may do the same for the rest of my consulting work
=) Burn all the copies! And print the PDFs out and throw them on
the fire!!!

Ashley


http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran