at_exit not getting called when using Spork

94 views
Skip to first unread message

Scott Johnson

unread,
Oct 7, 2009, 7:44:58 PM10/7/09
to Cukes
I've got fixtures that I want for all my scenarios. I've got the
following in my env.rb:

Spork.each_run do
require 'cucumber/rails/world'
Cucumber::Rails::World.use_transactional_fixtures = true
ActionController::Base.allow_rescue = false
fixtures = Fixtures.create_fixtures("spec/fixtures",
"config_spaces")

at_exit do
fixtures.delete_existing_fixtures
end

end

Yet the fixtures are not being deleted at the end of my cucumber run.
Nor are they deleted at the time I kill the spork server.

If I run cucumber when the spork server is not running, it properly
deletes them.

aslak hellesoy

unread,
Oct 7, 2009, 8:08:18 PM10/7/09
to cu...@googlegroups.com
On Thu, Oct 8, 2009 at 1:44 AM, Scott Johnson <sc...@scottjohnson.org> wrote:

I've got fixtures that I want for all my scenarios. I've got the
following in my env.rb:

Spork.each_run do
 require 'cucumber/rails/world'
 Cucumber::Rails::World.use_transactional_fixtures = true
 ActionController::Base.allow_rescue = false
 fixtures = Fixtures.create_fixtures("spec/fixtures",
"config_spaces")

 at_exit do
   fixtures.delete_existing_fixtures
 end

end

Yet the fixtures are not being deleted at the end of my cucumber run.
Nor are they deleted at the time I kill the spork server.


Are you sure at_exit isn't run? (Add a puts statement in there)
The spork team might know more about this...

In any case, I recommend you clean up on startup instead of shutdown.

Aslak
 

timcharper

unread,
Oct 7, 2009, 11:44:31 PM10/7/09
to Cukes
Hi Scott,

Unfortunately for you in this situation, this is on purpose. This
commit is behind the mischief:

http://is.gd/43TMv

There were some issues with at_exit hooks being ran in RSpec. It was
trying to run the specs twice, so I had to use exit!(0) instead of exit
(0) to skip the at_exit hooks.

In all fairness, this wouldn't have worked with the old rspec spec/
server either, because the process never ended.

Perhaps I could patch it to run any at_exit hooks defined after the
environment is loaded (by taking over at_ext and calling them
instead). That's if it's serious... I hate to be so aggressive with
ruby. It would be better to use a cucumber hook to run cleanup after
all scenarios were ran.

In other news, I've been planning on making a "between_run" section
for spork, that will execute the moment the tests have been run. This
way, you could have a full cleanup, and that cleanup would be running
right after you received the results of your tests.

Tim

Scott Johnson

unread,
Oct 8, 2009, 1:30:56 PM10/8/09
to Cukes
On Oct 7, 8:44 pm, timcharper <timchar...@gmail.com> wrote:
> ruby. It would be better to use a cucumber hook to run cleanup after
> all scenarios were ran.

I don't believe there is such a hook. The cucumber wiki ('Hooks' page)
says to use Kernel#at_exit for global teardown.

Doing cleanup on startup is no good, because rspec uses the same
database and it doesn't expect there to be garbage sitting around.

Ben Mabey

unread,
Oct 8, 2009, 6:14:22 PM10/8/09
to cu...@googlegroups.com
Scott Johnson wrote:
> On Oct 7, 8:44 pm, timcharper <timchar...@gmail.com> wrote:
>
>> ruby. It would be better to use a cucumber hook to run cleanup after
>> all scenarios were ran.
>>
>
> I don't believe there is such a hook. The cucumber wiki ('Hooks' page)
> says to use Kernel#at_exit for global teardown.
>

Thats correct. I think Tim's suggestion of adding a "between_run" hook
to spork is the best option. So you might have something like:

def cleanup
...
end

at_exit do
cleanup
end

Spork.between_run do
cleanup
end


WDYT? (If you like it you may want to open/vote up an issue on Spork's
github tracker.)


> Doing cleanup on startup is no good, because rspec uses the same
> database and it doesn't expect there to be garbage sitting around.
>
>

Until a between_run hook is added to Spork then I think you will need to
work around this issue. Meaning, you will need to do cleanup in both
rspec and cucumber on startup OR use a different database.

HTH,
Ben

Scott Johnson

unread,
Oct 8, 2009, 9:17:51 PM10/8/09
to Cukes


On Oct 8, 3:14 pm, Ben Mabey <b...@benmabey.com> wrote:
> Spork.between_run do
> cleanup
> end

That would work fine for me.

In the mean time I'll work around.

Thanks for the help...
Reply all
Reply to author
Forward
0 new messages